OpenAPITools / OpenAPITools/openapi-generator
[BUG] Using --input-spec-root-directory fails
Nobody has claimed this yet.
- 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
Using --input-spec-root-directory fails with exception.
PS F:\src\app> java -jar .\openapi-generator-cli.jar generate --input-spec-root-directory .\app\specs -g csharp -o generated
[main] INFO o.o.codegen.config.MergedSpecBuilder - In spec root directory .\app\specs found specs [swagger.yaml]
[main] INFO o.o.codegen.config.MergedSpecBuilder - Reading spec: .\app\specs\swagger.yaml
Merge input spec would be used - .\app\specs\_merged_spec.yaml
[main] WARN io.swagger.v3.parser.OpenAPIV3Parser - Exception while resolving:
java.lang.NullPointerException: Cannot invoke "io.swagger.v3.oas.models.parameters.Parameter.getSchema()" because "parameter" is null
at io.swagger.v3.parser.processors.ExternalRefProcessor.lambda$processRefToExternalPathItem$0(ExternalRefProcessor.java:358)
at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:196)
at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1709)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:570)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:560)
at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265)
at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:636)
at io.swagger.v3.parser.processors.ExternalRefProcessor.processRefToExternalPathItem(ExternalRefProcessor.java:359)
at io.swagger.v3.parser.processors.PathsProcessor.processReferencePath(PathsProcessor.java:325)
at io.swagger.v3.parser.processors.PathsProcessor.processPaths(PathsProcessor.java:65)
at io.swagger.v3.parser.OpenAPIResolver.resolve(OpenAPIResolver.java:72)
at io.swagger.v3.parser.OpenAPIResolver.resolve(OpenAPIResolver.java:59)
at io.swagger.v3.parser.OpenAPIV3Parser.resolve(OpenAPIV3Parser.java:240)
at io.swagger.v3.parser.OpenAPIV3Parser.readContents(OpenAPIV3Parser.java:183)
at io.swagger.v3.parser.OpenAPIV3Parser.readLocation(OpenAPIV3Parser.java:97)
at io.swagger.parser.OpenAPIParser.readLocation(OpenAPIParser.java:16)
at org.openapitools.codegen.config.CodegenConfigurator.toContext(CodegenConfigurator.java:686)
at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:744)
at org.openapitools.codegen.cmd.Generate.execute(Generate.java:527)
at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)
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: 0
Errors:
-Cannot invoke "io.swagger.v3.oas.models.parameters.Parameter.getSchema()" because "parameter" is null
at org.openapitools.codegen.config.CodegenConfigurator.toContext(CodegenConfigurator.java:717)
at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:744)
at org.openapitools.codegen.cmd.Generate.execute(Generate.java:527)
at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)
openapi-generator version
and 7.10.0
OpenAPI declaration file content or url
https://github.com/networknt/model-config/blob/master/rest/swagger/petstore/2.0.0/swagger.yaml
Generation Details
Windows 11
PS F:\src\> java --version
openjdk 23.0.1 2024-10-15
OpenJDK Runtime Environment Temurin-23.0.1+11 (build 23.0.1+11)
OpenJDK 64-Bit Server VM Temurin-23.0.1+11 (build 23.0.1+11, mixed mode, sharing)
PS F:\src\app> java -jar .\openapi-generator-cli.jar generate --input-spec-root-directory .\app\specs -g csharp -o generated
Steps to reproduce
- Download linked yaml
- Place in folder
- Use
--input-spec-root-directorywith any generator - Get exception
Same issue with json spec.
Related issues/PRs
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
Start with MergedSpecBuilder and the generation path through CodegenConfigurator.toContext, then inspect the ExternalRefProcessor stack trace while reproducing with the linked swagger.yaml and --input-spec-root-directory. Done means generation no longer fails validation with the reported null-parameter exception for the supplied YAML and JSON cases; the payload does not name a test file.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api, cli
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100