How do I access a private swagger API with a maven-build-plugin? - maven

I have generated an API in swagger (API 3.0.0):
Offer-Api:
openapi: 3.0.0
[…]
paths:
/offers:
get:
summary: get all offers
operationId: allOffers
description: return ALL offers
responses:
'200':
description: search results matching criteria
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/ApiOffer'
links:
GetOffererById:
$ref: 'https://api.swaggerhub.com/apis/comp/offers/1.0.0#/components/links/GetSingleOffererById'
GetOfferById:
$ref: '#/components/links/GetSingleOfferById'
'400':
description: something went terribly wrong
[…]
I copied that content into my project as an „Offers.yaml“ and try to compile it via „openapi-generator-maven-plugin“
[…]
<plugins>
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>3.3.0</version>
<executions>
[…]
<execution>
<id>Offers</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/Offers.yaml</inputSpec>
<modelPackage>${project.modelpackage}</modelPackage>
<apiPackage>${project.apipackage}</apiPackage>
<generateApis>false</generateApis>
<generateApiTests>false</generateApiTests>
<generateApiDocumentation>false</generateApiDocumentation>
<generateModels>true</generateModels>
<generateModelTests>true</generateModelTests>
<withXml>true</withXml>
<generateModelDocumentation>false</generateModelDocumentation>
<generateSupportingFiles>false</generateSupportingFiles>
<generatorName>java</generatorName>
<library>jersey2</library>
<validateSpec>false</validateSpec>
<configOptions>
<sourceFolder>src/gen/java/</sourceFolder>
<java8>true</java8>
<dateLibrary>java8</dateLibrary>
<useBeanValidation>true</useBeanValidation>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
[…]
During maven-compile following error occurs:
[INFO]
[INFO] --- openapi-generator-maven-plugin:3.3.0:generate (Offers) # server ---
[ERROR] unable to read
java.io.FileNotFoundException: https://api.swaggerhub.com/apis/comp/offerers/1.0.0
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0 (HttpURLConnection.java:1890)
Sure, https://api.swaggerhub.com/apis/comp/offerers/1.0.0 is a PRIVATE API. But is there a way to tell the maven plugin the correct credentials, so that it can access that API anyway?

Related

Swagger-codegen-maven-plugin with feign library build invalid paths

I have API.yaml file from supplier.
When codegen generates an API all my links are invalid because they have a question mark at the end
When i used openapi-generator-maven-plugin for this same API.yaml file, all links were correct.
I can't change swagger to openapi and feign library (project rules).
In project i'm using Feign 11.8 version and feign client has problem with question mark at the end (of course for requests without reqquest params)
How to fix it?
My plugin:
<plugin>
<groupId>io.swagger.codegen.v3</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>3.0.35</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/BookAPI.yaml</inputSpec>
<language>java</language>
<configOptions>
<dateLibrary>java8-localdatetime</dateLibrary>
<java8>true</java8>
</configOptions>
<library>feign</library>
<modelPackage>${project.groupId}.client.model</modelPackage>
<apiPackage>${project.groupId}.client.api</apiPackage>
<invokerPackage>${project.groupId}.client.invoker</invokerPackage>
<generateModelTests>false</generateModelTests>
<generateApiTests>false</generateApiTests>
<typeMappings>
<typeMapping>Double=java.math.BigDecimal</typeMapping>
</typeMappings>
</configuration>
</execution>
</executions>
</plugin>
Generated api example:
#RequestLine("POST /api/something/FindSomething?")
#Headers({
"Content-Type: application/json",
"Accept: application/json",
"Authorization: {authorization}"
})
SomethingsResponse findSomething(#Param("authorization") String authorization, SomethingRequest body);
Part of API.yaml
/api/Flight/Something:
post:
tags:
- Something
summary: Something
description: 'Description'
operationId: findSomething
parameters:
- name: Authorization
in: header
description: OAuth 2.0 access token obtained from OAuth2 Token endpoint. Supported grant types: Resource owner password.
required: true
schema:
type: string
requestBody:
description: The request
content:
application/json:
schema:
$ref: '#/components/schemas/SomethingRequest'
example:
Field1: XYZ
Field2: XYZ
Field3:
Field3_1: XYZ
Field3_2: [ ]
responses:
'200':
description: Description.
content:
application/json:
schema:
$ref: '#/components/schemas/SomethingResponse'
'400':
description: Bad Request
content:
application/json: { }
'401':
description: Unauthorized Request
content:
application/json: { }
'403':
description: Forbidden - HTTPS Required.
content:
application/json: { }
'500':
description: Internal Server Error
content:
application/json: { }

How To ignore Endpoints from openapi.yaml in generation with openapi-generator-maven-plugin/

yaml and openapi-generator-maven-plugin is corretly generating Spring Boot Controller Interfaces from it. All is working fine. But now we want to overwrite one of the generated Interfaces with our own interface. How can we exclude a certain endpoint from this generation?
Example:
paths:
/currencies:
get:
tags:
- DomainData
summary: Lists all valid currencies available.
operationId: "getCurrencies"
parameters:
- $ref: '#/components/parameters/AcceptLanguage'
responses:
"200":
description: "OK"
content:
application/json:
schema:
type: string
additionalProperties:
type: string
'401':
$ref: '#/components/responses/Unauthorized'
'5XX':
$ref: '#/components/responses/Unexpected'
/languages:
get:
tags:
- DomainData
summary: Lists all valid languages available.
operationId: "getLanguages"
parameters:
- $ref: '#/components/parameters/AcceptLanguage'
responses:
"200":
description: "OK"
content:
application/json:
schema:
type: string
additionalProperties:
type: string
'401':
$ref: '#/components/responses/Unauthorized'
'5XX':
$ref: '#/components/responses/Unexpected'
This is a part of the openapi.yaml and we would not like to generate for /languages but everything else.
I found a solution we used a .openapi-generator-ignore
and linked it in the pom options of the openapi generator.
In the .openapi-generator-ignore we used the full relative path from position of the ignore file to the file that is not existing and we dont want to get generated.
target/generated-sources/v1/src/main/java/ch/company/dsp/bff/project/generated/api/languageApi.java

Configuring Spring Boot REST API project with yaml file

It is my first time working with Spring Boot REST API. I would like to build a Spring Boot Project with 2 microservices: UserManagement and Messaging.
I have the following yaml file for my UserManagement API endpoint:
swagger: '2.0'
info:
description: UMS Service
version: 1.0.0
title: UMS API
host: ums
basePath: /api/v1
tags:
- name: role
description: Operations about roles
- name: user
description: Operations about users
- name: login/logout
description: Operations about sessions
schemes:
- https
- http
paths:
/role:
post:
tags:
- role
summary: Create role
description: This can only be done by the logged in user.
operationId: createRole
produces:
- application/json
parameters:
- in: body
name: body
description: Created role object
required: true
schema:
$ref: '#/definitions/Role'
responses:
default:
description: successful operation
get:
tags:
- role
summary: Get role by name
description: ''
operationId: getRoleByName
produces:
- application/json
parameters:
- name: rolename
in: query
description: The name that needs to be fetched.
required: true
type: string
responses:
'200':
description: successful operation
schema:
$ref: '#/definitions/Role'
'400':
description: Invalid rolename supplied
'401':
description: Not authenticated
'404':
description: Role not found
put:
tags:
- role
summary: Updated role name
operationId: updateRole
produces:
- application/json
parameters:
- name: rolename
in: query
description: name that need to be updated
required: true
type: string
- in: body
name: body
description: Updated role object
required: true
schema:
$ref: '#/definitions/Role'
responses:
'400':
description: Invalid role supplied
'401':
description: Not authenticated
'404':
description: Role not found
delete:
tags:
- role
summary: Delete role
description: This can only be done by the logged in user.
operationId: deleteRole
produces:
- application/json
parameters:
- name: rolename
in: query
description: The role that needs to be deleted
required: true
type: string
responses:
'400':
description: Invalid role supplied
'401':
description: Not authenticated
'404':
description: Role not found
/user:
post:
tags:
- user
summary: Create user
description: This can only be done by the logged in user.
operationId: createUser
produces:
- application/json
parameters:
- in: body
name: body
description: Created user object
required: true
schema:
$ref: '#/definitions/User'
responses:
default:
description: successful operation
get:
tags:
- user
summary: Get user by user name
description: ''
operationId: getUserByName
produces:
- application/json
parameters:
- name: username
in: query
description: The name that needs to be fetched
required: true
type: string
responses:
'200':
description: successful operation
schema:
$ref: '#/definitions/User'
'400':
description: Invalid username supplied
'401':
description: Not authenticated
'404':
description: User not found
put:
tags:
- user
summary: Updated user
description: This can only be done by the logged in user.
operationId: updateUser
produces:
- application/xml
- application/json
parameters:
- in: body
name: body
description: Updated user object
required: true
schema:
$ref: '#/definitions/User'
responses:
'400':
description: Invalid user supplied
'401':
description: Not authenticated
'404':
description: User not found
delete:
tags:
- user
summary: Delete user
description: This can only be done by the logged in user.
operationId: deleteUser
produces:
- application/json
parameters:
- name: username
in: query
description: The name that needs to be deleted
required: true
type: string
responses:
'400':
description: Invalid username supplied
'401':
description: Not authenticated
'404':
description: User not found
/user/role:
post:
tags:
- user
summary: Assign role to user
description: This can only be done by the logged in user.
operationId: createUserRole
produces:
- application/json
parameters:
- in: body
name: body
description: Created user object
required: true
schema:
$ref: '#/definitions/UserRole'
responses:
default:
description: successful operation
get:
tags:
- user
summary: Get role by user name
description: ''
operationId: getRoleByUserName
produces:
- application/json
parameters:
- name: username
in: query
description: The name that needs to be fetched
required: true
type: string
responses:
'200':
description: successful operation
schema:
$ref: '#/definitions/UserRole'
'400':
description: Invalid username supplied
'401':
description: Not authenticated
'404':
description: User not found
put:
tags:
- user
summary: Updated user's role
description: This can only be done by the logged in user.
operationId: updateUserRole
produces:
- application/json
parameters:
- in: body
name: body
description: Updated user object with new role
required: true
schema:
$ref: '#/definitions/UserRole'
responses:
'400':
description: Invalid username supplied
'401':
description: Not authenticated
'404':
description: User not found
/session/login:
get:
tags:
- login/logout
summary: Get last login for user
description: This can only be done by the logged in user.
operationId: getLastSessionStart
produces:
- application/json
parameters:
- name: username
in: query
required: true
type: string
responses:
'200':
description: successful operation
schema:
$ref: '#/definitions/Session'
'401':
description: Not authenticated
/session/logout:
get:
tags:
- login/logout
summary: Get last logout for user
description: This can only be done by the logged in user.
operationId: getLastSessionEnd
produces:
- application/json
parameters:
- name: username
in: query
required: true
type: string
responses:
'200':
description: successful operation
schema:
$ref: '#/definitions/Session'
'401':
description: Not authenticated
post:
tags:
- login/logout
summary: Set logout for user
description: This can only be done by the logged in user.
operationId: setLastSessionEnd
produces:
- application/json
parameters:
- in: body
name: body
description: Set Log out data for user
required: true
schema:
$ref: '#/definitions/Session'
responses:
default:
description: successful operation
securityDefinitions:
ums_auth:
type: oauth2
authorizationUrl: 'http://ums/oauth/user'
flow: implicit
scopes:
'write:users': modify users in your account
'read:users': read user data
api_key:
type: apiKey
name: api_key
in: header
definitions:
UserRole:
type: object
properties:
username:
type: string
rolename:
type: string
Role:
type: object
properties:
rolename:
type: string
User:
type: object
properties:
username:
type: string
email:
type: string
password:
type: string
role:
type: string
Session:
type: object
properties:
username:
type: string
login:
type: number
logout:
type: number
My question is: how do I configure my UserManagement Service to communicate with this yaml file and generate its contents in a web browser? I am using Eclipse with STS3 plugin.
Thank you for any suggestions. Also, I'd be grateful to sample links to Spring Boot REST API projects with application.yml files which could help me build a simple Spring Boot REST API with 2 services.
You may need a openapi-generator-maven-plugin to read your YML file and generate an OAS (Open API specification) out of it.
Not completely tried from scratch, but check if below helps
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>4.3.1</version>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/oas/openapi.yaml</inputSpec>
<generatorName>spring</generatorName>
<modelPackage>com.xyz....</modelPackage>
<apiPackage>com.xyz...</apiPackage>
<output>./../api</output>
<generateSupportingFiles>false</generateSupportingFiles>
<configOptions>
<sourceFolder>src/main/java</sourceFolder>
<interfaceOnly>true</interfaceOnly>
<skipDefaultInterface>true</skipDefaultInterface>
<hideGenerationTimestamp>true</hideGenerationTimestamp>
</configOptions>
</configuration>
</plugin>
You may reach out to the one who asked a similar question on this article, he might have tried from scratch Openapi operationid is repeated

Why does multi openAPI yaml not work? Spring Boot, Maven, OpenApi

I have the following problem. I want to create several smaller interfaces from an OpenAPI.yaml.
The OpenAPI.yaml serves as the top-level yaml file and this should contain all the necessary references to point to the other interfaces.
But now I get the error shown below. Does anyone have a solution for this problem?
openapi: 3.0.1
info:
description: "REST resources for Test"
version: "1.0.0"
title: "Test"
servers:
- url: 'http://localhost:8080'
description: local dev environment
tags:
- name: openApi Top-Level
description: Top-Level OpenApi.yaml
paths:
/:
get:
tags:
- home
summary: loads the homepage
description: loads the homepage
operationId: loadIndex
responses:
'200':
description: successful operation
content:
application/json:
schema:
type: string
'400':
description: Invalid status value
content: {}
/user:
$ref: 'user.yaml#/user'
/user/createWithArray:
$ref: 'user.yaml#/user-createWithArray'
/user/createWithList:
$ref: 'user.yaml#/user-createWithList'
/user/login:
$ref: 'user.yaml#/user-login'
/user/logout:
$ref: 'user.yaml#/user-logout'
/version:
$ref: 'pet.api.yaml#/version'
/version/findAllByOrderByReleasedateAsc:
$ref: 'version.yaml#/version-findAllByOrderByReleasedateAsc'
/version/findAllByOrderByReleasedateDesc:
$ref: 'version.yaml#/version-findAllByOrderByReleasedateDesc'
/version/currentVersion:
$ref: 'version.yaml#/version-currentVersion'
/version/{versionId}:
$ref: 'version.yaml#/version-versionId'
components:
schemas:
StructureProperty:
$ref: 'structureGroup.yaml#/StructureProperty'
Structure:
$ref: 'structureGroup.yaml#/Structure'
StructureGroup:
$ref: 'structureGroup.yaml#/StructureGroup'
StructureGroupLocation:
$ref: 'structureGroupLocation.yaml#/StructureGroupLocation'
User:
$ref: 'user.yaml#/User'
Version:
$ref: 'version.yaml#/Version'
securitySchemes:
basicAuth:
type: http
scheme: basic
openapi: 3.0.1
info:
description: "REST resources for Test2"
version: "1.0.0"
title: "Test2"
servers:
- url: 'http://localhost:8080'
description: local dev environment
tags:
- name: user
description: Everything about the users
paths:
/user:
get:
tags:
- "user"
operationId: "getUsers"
responses:
'200':
description: successful operation
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/User'
security:
- basicAuth: []
post:
tags:
- user
summary: Create user
description: This can only be done by the logged in user.
operationId: createUser
requestBody:
description: Created user object
content:
application/json:
schema:
$ref: '#/components/schemas/User'
required: true
responses:
'405':
description: Invalid input
content: {}
security:
- basicAuth: []
x-codegen-request-body-name: body
/user/createWithArray:
post:
tags:
- user
summary: Creates list of users with given input array
operationId: createUsersWithArrayInput
requestBody:
description: List of user object
content:
'*/*':
schema:
type: array
items:
$ref: '#/components/schemas/User'
required: true
responses:
default:
description: successful operation
content: {}
x-codegen-request-body-name: body
/user/createWithList:
post:
tags:
- user
summary: Creates list of users with given input array
operationId: createUsersWithListInput
requestBody:
description: List of user object
content:
'*/*':
schema:
type: array
items:
$ref: '#/components/schemas/User'
required: true
responses:
default:
description: successful operation
content: {}
x-codegen-request-body-name: body
/user/login:
get:
tags:
- user
summary: Logs user into the system
operationId: loginUser
parameters:
- name: username
in: query
description: The user name for login
required: true
schema:
type: string
- name: password
in: query
description: The password for login in clear text
required: true
schema:
type: string
responses:
'200':
description: successful operation
headers:
X-Rate-Limit:
description: calls per hour allowed by the user
schema:
type: integer
format: int32
X-Expires-After:
description: date in UTC when token expires
schema:
type: string
format: date-time
content:
application/json:
schema:
type: string
'400':
description: Invalid username/password supplied
content: {}
/user/logout:
get:
tags:
- user
summary: Logs out current logged in user session
operationId: logoutUser
responses:
default:
description: successful operation
content: {}
'/user/{id}':
get:
tags:
- user
summary: Get user by user id
operationId: getUserById
parameters:
- name: id
in: path
description: 'The id that needs to be fetched. '
required: true
schema:
type: integer
format: int64
responses:
'200':
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/User'
'400':
description: Invalid user id supplied
content: {}
'404':
description: User not found
content: {}
put:
tags:
- user
summary: Updated user
description: This can only be done by the logged in user.
operationId: updateUserById
parameters:
- name: id
in: path
description: id that need to be updated
required: true
schema:
type: integer
format: int64
requestBody:
description: Updated user object
content:
'*/*':
schema:
$ref: '#/components/schemas/User'
required: true
responses:
'400':
description: Invalid user id supplied
content: {}
'404':
description: User not found
content: {}
x-codegen-request-body-name: body
delete:
tags:
- user
summary: Delete user
description: This can only be done by the logged in user.
operationId: deleteUserById
parameters:
- name: id
in: path
description: The id of the user that needs to be deleted
required: true
schema:
type: integer
format: int64
responses:
'400':
description: Invalid user id supplied
content: {}
'404':
description: User not found
content: {}
security:
- basicAuth: []
components:
schemas:
User:
required:
- id
- username
- email
- password
- role
type: object
properties:
id:
type: integer
format: int64
username:
type: string
example: "toencript"
firstName:
type: string
example: "to"
lastName:
type: string
example: "encript"
email:
type: string
example: "toencript#toencript.com"
password:
type: string
example: "toencript"
role:
type: string
example: "ADMIN"
securitySchemes:
basicAuth:
type: http
scheme: basic
<plugin>
<!-- Generate the classes from open api -->
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>5.1.1</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/openapi.yaml</inputSpec>
<generatorName>spring</generatorName>
<supportingFilesToGenerate>
ApiUtil.java
</supportingFilesToGenerate>
<configOptions>
<delegatePattern>true</delegatePattern>
<interfaceOnly>true</interfaceOnly>
</configOptions>
<modelPackage>${project.groupId}.openapi.DTO</modelPackage>
<apiPackage>${project.groupId}.openapi.api</apiPackage>
</configuration>
</execution>
</executions>
</plugin>
[ERROR] Failed to execute goal org.openapitools:openapi-generator-maven-plugin:5.1.1:generate (default) on project service: Code generation failed. See
above for the full exception. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[WARNING] Exception while resolving:
java.lang.RuntimeException: Unable to load RELATIVE ref: user path: D:\Repositories\service\src\main\resources
at io.swagger.v3.parser.util.RefUtils.readExternalRef (RefUtils.java:239)
at io.swagger.v3.parser.ResolverCache.loadRef (ResolverCache.java:119)
at io.swagger.v3.parser.processors.ExternalRefProcessor.processRefToExternalPathItem (ExternalRefProcessor.java:237)
at io.swagger.v3.parser.processors.PathsProcessor.processReferencePath (PathsProcessor.java:299)
at io.swagger.v3.parser.processors.PathsProcessor.processPaths (PathsProcessor.java:63)
at io.swagger.v3.parser.OpenAPIResolver.resolve (OpenAPIResolver.java:49)
at io.swagger.v3.parser.OpenAPIV3Parser.resolve (OpenAPIV3Parser.java:175)
at io.swagger.v3.parser.OpenAPIV3Parser.readContents (OpenAPIV3Parser.java:154)
at io.swagger.v3.parser.OpenAPIV3Parser.readLocation (OpenAPIV3Parser.java:89)
at io.swagger.parser.OpenAPIParser.readLocation (OpenAPIParser.java:16)
at org.openapitools.codegen.config.CodegenConfigurator.toContext (CodegenConfigurator.java:523)
at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput (CodegenConfigurator.java:573)
at org.openapitools.codegen.plugin.CodeGenMojo.execute (CodeGenMojo.java:731)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:972)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:566)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: java.lang.RuntimeException: Could not find structureGroupLocation on the classpath
at io.swagger.v3.parser.util.ClasspathHelper.loadFileFromClasspath (ClasspathHelper.java:31)
at io.swagger.v3.parser.util.RefUtils.readExternalRef (RefUtils.java:233)
at io.swagger.v3.parser.ResolverCache.loadRef (ResolverCache.java:119)
at io.swagger.v3.parser.processors.ExternalRefProcessor.processRefToExternalPathItem (ExternalRefProcessor.java:237)
at io.swagger.v3.parser.processors.PathsProcessor.processReferencePath (PathsProcessor.java:299)
at io.swagger.v3.parser.processors.PathsProcessor.processPaths (PathsProcessor.java:63)
at io.swagger.v3.parser.OpenAPIResolver.resolve (OpenAPIResolver.java:49)
at io.swagger.v3.parser.OpenAPIV3Parser.resolve (OpenAPIV3Parser.java:175)
at io.swagger.v3.parser.OpenAPIV3Parser.readContents (OpenAPIV3Parser.java:154)
at io.swagger.v3.parser.OpenAPIV3Parser.readLocation (OpenAPIV3Parser.java:89)
at io.swagger.parser.OpenAPIParser.readLocation (OpenAPIParser.java:16)
at org.openapitools.codegen.config.CodegenConfigurator.toContext (CodegenConfigurator.java:523)
at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput (CodegenConfigurator.java:573)
at org.openapitools.codegen.plugin.CodeGenMojo.execute (CodeGenMojo.java:731)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:972)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:566)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
[WARNING] D:\Repositories\service\src\main\resources\openapi.yaml [0:0]: unexpected error in Open-API generation
org.openapitools.codegen.SpecValidationException: There were issues with the specification. The option can be disabled via validateSpec (Maven/Gradle) or --skip-valid
ate-spec (CLI).
| Error count: 1, Warning count: 6
Errors:
-Unable to load RELATIVE ref: user path: D:\Repositories\service\src\main\resources
Warnings:
-Unable to load RELATIVE ref: user path: D:\Repositories\service\src\main\resources
Your $refs are not correct. It should look like this:
paths:
/user:
$ref: 'user.yaml#/paths/~1user'
components:
schemas:
User:
$ref: 'user.yaml#/components/schemas/User'
the funny ~1 is escaping the '/' of the /user path.

Open API -> How to reference the external property names/types of Java objects of class path/jar in Request or Response Body YAML Specification

my requirement is to use the properties names and types of the classes which are included in class path java objects.
Basically, $ref will allow us to use the classes which are included in class path like below
1) **YML File**
paths:
/users/{id}:
parameters:
- name: id
in: path
required: true
description: the user identifier, as userId
schema:
type: string
get:
responses:
'200':
description: the user being returned
content:
application/json:
schema:
$ref: "**TESTCALSSOFCLASSPATHORJAR**"
properties:
uuid: # the unique user id
type: string
format: uuid
2) <plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>${openapi-generator-maven-plugin.version}</version>
<configuration>
... excluded for simplicity
<importMappings>
<importMapping>TESTCALSSOFCLASSPATHORJAR=path.to.your.TESTCALSSOFCLASSPATHORJAR</importMapping>
</importMappings>
</configuration>
</plugin>
Is there any way that, I can refer id attribute name from my class path/jar java object??
paths:
/users/{id}:
parameters:
- name: **id** -> I want to get this prop from TESTCALSSOFCLASSPATHORJAR class
i.e.TESTCALSSOFCLASSPATHORJAR.id
in: path
required: true
description: the user identifier, as userId
schema:
type: string
get:
responses:
'200':
description: the user being returned
content:
application/json:
schema:
$ref: "**TESTCALSSOFCLASSPATHORJAR**"
properties:
uuid: # the unique user id
type: string
format: uuid
Referred below documents and searching a lot but didn't find any solution.
https://github.com/OAI/OpenAPI-Specification
https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator-maven-plugin
Any suggestions would be really appreciated.

Resources