fix: null exception error with addImport(composed, refSchema, m, modelName).
Closes https://github.com/OpenAPITools/openapi-generator/issues/13588
Hi team.
The following error occurred while generating a k6 scenario from oas using openapi-generator-cli version 6.2.0.
Exception in thread "main" java.lang.RuntimeException: Could not process model 'CommonSiteLink'.Please make sure that your schema is correct!
at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:518)
at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:912)
at org.openapitools.codegen.cmd.Generate.execute(Generate.java:465)
at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)
Caused by: java.lang.NullPointerException: Cannot invoke "io.swagger.v3.oas.models.media.Schema.getDiscriminator()" because "childSchema" is null
at org.openapitools.codegen.DefaultCodegen.addImport(DefaultCodegen.java:5497)
at org.openapitools.codegen.DefaultCodegen.updateModelForComposedSchema(DefaultCodegen.java:2633)
at org.openapitools.codegen.DefaultCodegen.fromModel(DefaultCodegen.java:2963)
at org.openapitools.codegen.DefaultGenerator.processModels(DefaultGenerator.java:1291)
at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:513)
... 4 more
This error is occurred if allDefinitions is null or allDefinitions.get(ref) returned null.
Therefore i added null check of the childSchema to the if statement.
This error was generated by https://github.com/OpenAPITools/openapi-generator/pull/12798.
The release that incorporates this PR appears to be 6.1.0, so versions above 6.1.0 may have the above error.
Signed-off-by: mugioka [email protected]
PR checklist
- [x] Read the contribution guidelines.
- [x] Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
- [x] Run the following to build the project and update samples:
Commit all changed files. This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master. These must match the expectations made by your contribution. You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example./mvnw clean package ./bin/generate-samples.sh ./bin/utils/export_docs_generators.sh./bin/generate-samples.sh bin/configs/java*. For Windows users, please run the script in Git BASH. - [x] File the PR against the correct branch:
master(6.1.0) (minor release - breaking changes with fallbacks),7.0.x(breaking changes without fallbacks) - [x] If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.
thanks for the fix. let me review later today.
@mugioka can you please share a spec to reproduce the issue?
@wing328 sorry for delay. I will share the specs to reproduce this issue later today.
Although still being verified, this PR may not be necessary since the root cause is incorrect parsing of paths referenced by $ref.
npx @redocly/cli bundle openapi.yaml successfully parse the correct $ref, but openapi-generator-cli generate -i openapi.yaml -g k6 --skip-validate-spec -o ./test failed to parse the correct $ref.
but openapi-generator-cli generate -i openapi.yaml -g k6 --skip-validate-spec -o ./test-v failed to parse the correct $ref.
can you please open an issue with details for tracking? I will try to take a look later.
closing it as there's no update. please open a new one if needed. thanks.