OpenAPITools / OpenAPITools/openapi-generator
[BUG] Can't parse schema with external $ref
Open
Nobody has claimed this yet.
Client: PowerShell
Issue: Bug
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
openapi-generator-cli can't parse schema with external $ref.
[main] WARN io.swagger.v3.parser.OpenAPIV3Parser - Exception while resolving:
java.lang.NullPointerException: null
at io.swagger.v3.parser.util.OpenAPIDeserializer.getSchema(OpenAPIDeserializer.java:2467)
at io.swagger.v3.parser.util.OpenAPIDeserializer.getSchema(OpenAPIDeserializer.java:2349)
at io.swagger.v3.parser.ResolverCache.loadRef(ResolverCache.java:152)
at io.swagger.v3.parser.processors.ExternalRefProcessor.processRefToExternalSchema(ExternalRefProcessor.java:75)
at io.swagger.v3.parser.processors.ExternalRefProcessor.processRefSchema(ExternalRefProcessor.java:921)
at io.swagger.v3.parser.processors.ExternalRefProcessor.processSchema(ExternalRefProcessor.java:200)
at io.swagger.v3.parser.processors.ExternalRefProcessor.processProperties(ExternalRefProcessor.java:223)
at io.swagger.v3.parser.processors.ExternalRefProcessor.processProperties(ExternalRefProcessor.java:230)
at io.swagger.v3.parser.processors.ExternalRefProcessor.processRefToExternalSchema(ExternalRefProcessor.java:157)
at io.swagger.v3.parser.processors.ExternalRefProcessor.processRefToExternalSchema(ExternalRefProcessor.java:119)
at io.swagger.v3.parser.processors.SchemaProcessor.processReferenceSchema(SchemaProcessor.java:214)
at io.swagger.v3.parser.processors.SchemaProcessor.processArraySchema(SchemaProcessor.java:198)
at io.swagger.v3.parser.processors.SchemaProcessor.processSchemaType(SchemaProcessor.java:47)
at io.swagger.v3.parser.processors.SchemaProcessor.processSchema(SchemaProcessor.java:39)
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 org.openapitools.codegen.config.CodegenConfigurator.toContext(CodegenConfigurator.java:523)
at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:573)
at org.openapitools.codegen.cmd.Generate.execute(Generate.java:432)
at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: https://raw.githubusercontent.com/beatcracker/toptout/master/schema/toptout.schema.json
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: https://raw.githubusercontent.com/beatcracker/toptout/master/schema/toptout.schema.json
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: https://raw.githubusercontent.com/beatcracker/toptout/master/schema/toptout.schema.json
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: https://raw.githubusercontent.com/beatcracker/toptout/master/schema/toptout.schema.json
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: https://raw.githubusercontent.com/beatcracker/toptout/master/schema/toptout.schema.json
[main] WARN o.o.codegen.utils.ModelUtils - Failed to get the schema name: https://raw.githubusercontent.com/beatcracker/toptout/master/schema/toptout.schema.json
Exception in thread "main" org.openapitools.codegen.SpecValidationException: There were issues with the specification. The option can be disabled via validateSpec (Maven/Gradle) or --skip-validate-spec (CLI).
| Error count: 1, Warning count: 2
Errors:
-null
Warnings:
-null
at org.openapitools.codegen.config.CodegenConfigurator.toContext(CodegenConfigurator.java:546)
at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:573)
at org.openapitools.codegen.cmd.Generate.execute(Generate.java:432)
at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)
openapi-generator version
5.1.0-SNAPSHOT
OpenAPI declaration file content or url
- OpenAPI spec: openapi.yaml
$ref: toptout.schema.json
Generation Details
docker run --rm openapitools/openapi-generator-cli generate -i https://raw.githubusercontent.com/beatcracker/toptout/master/docs/swagger/openapi.yaml -g powershell
Steps to reproduce
Just run the command above.
Related issues/PRs
#1976
Suggest a fix
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
Reproduce the failure with the listed Docker command and the linked openapi.yaml and toptout.schema.json. Start by reading the OpenAPIV3Parser, ResolverCache, and ExternalRefProcessor stack entries. Done means the external $ref is parsed without the NullPointerException and specification validation succeeds.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 32/100