swagger-api / swagger-api/swagger-codegen
NullpointerException and missing model object while using external schemas
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
I am trying to generate api and model object for my Open API specification using swagger code gen plugin ( v 3.0.24 )
I have the external schema reference for one of the response object ( refer yaml below )
I have the following plugin in my pom.xml
<plugin>
<groupId>io.swagger.codegen.v3</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>3.0.24</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<environmentVariables>
<io.swagger.v3.parser.util.RemoteUrl.trustAll>true</io.swagger.v3.parser.util.RemoteUrl.trustAll>
</environmentVariables>
<inputSpec>src/main/openapi/openapi.yaml</inputSpec>
<language>spring</language>
<templateDirectory>${basedir}/src/main/resources/templates</templateDirectory>
<output>${project.build.directory}/generated-sources</output>
<apiPackage>com.mydomain.api</apiPackage>
<modelPackage>com.mydomain.model</modelPackage>
<generateApiDocumentation>false</generateApiDocumentation>
<generateModelDocumentation>false</generateModelDocumentation>
<generateSupportingFiles>false</generateSupportingFiles>
<generateApiTests>false</generateApiTests>
<generateModelTests>false</generateModelTests>
<configOptions>
<dateLibrary>java8</dateLibrary>
<interfaceOnly>true</interfaceOnly>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
I am getting the following exception. Also ErrorResponse model is not getting generated. Please advise
[WARNING] Exception while resolving:
java.lang.NullPointerException
at io.swagger.v3.parser.util.OpenAPIDeserializer.getSchema(OpenAPIDeserializer.java:2450)
at io.swagger.v3.parser.ResolverCache.loadRef(ResolverCache.java:152)
at io.swagger.v3.parser.processors.ExternalRefProcessor.processRefToExternalSchema(ExternalRefProcessor.java:56)
at io.swagger.v3.parser.processors.SchemaProcessor.processReferenceSchema(SchemaProcessor.java:214)
at io.swagger.v3.parser.processors.SchemaProcessor.processSchema(SchemaProcessor.java:37)
at io.swagger.v3.parser.processors.ResponseProcessor.processResponse(ResponseProcessor.java:52)
at io.swagger.v3.parser.processors.OperationProcessor.processOperation(OperationProcessor.java:67)
at io.swagger.v3.parser.processors.PathsProcessor.processPaths(PathsProcessor.java:84)
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 io.swagger.codegen.v3.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:517)
at io.swagger.codegen.v3.maven.plugin.CodeGenMojo.execute_(CodeGenMojo.java:532)
Swagger-codegen version
3.0.24
Swagger declaration file content or url
responses:
"500":
description: Error response
content:
application/json:
schema:
$ref: 'https://swaggerhub.mydomain.com/v1/domains/Global_Domains/V0/#/responses/ErrorResponse'
Command line used for generation
Steps to reproduce
Related issues/PRs
Suggest a fix/enhancement
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with OpenAPIDeserializer.java:2450 and trace the external reference through ResolverCache.java, ExternalRefProcessor.java, and SchemaProcessor.java. Reproduce the Maven generation using the shown external $ref and confirm that resolution no longer raises a NullPointerException and that the ErrorResponse model is generated.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100