Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Using --input-spec-root-directory fails #20352

Open
5 of 6 tasks
eclazi opened this issue Dec 18, 2024 · 1 comment
Open
5 of 6 tasks

[BUG] Using --input-spec-root-directory fails #20352

eclazi opened this issue Dec 18, 2024 · 1 comment

Comments

@eclazi
Copy link

eclazi commented Dec 18, 2024

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?

Tested with https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/7.11.0-SNAPSHOT/openapi-generator-cli-7.11.0-20241218.082146-58.jar

  • 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

Tested with https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/7.11.0-SNAPSHOT/openapi-generator-cli-7.11.0-20241218.082146-58.jar

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
  1. Download linked yaml
  2. Place in folder
  3. Use --input-spec-root-directory with any generator
  4. Get exception

Same issue with json spec.

Related issues/PRs
Suggest a fix
@eclazi
Copy link
Author

eclazi commented Dec 19, 2024

I think the issue relates to using an OpenAPI v2 spec. It seems to work file when the spec is v3 (e.g v3 petstore example)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant