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][CLI] crash when evaluating definitions without parameters #7453

Closed
5 of 6 tasks
codymikol opened this issue Sep 19, 2020 · 3 comments · Fixed by #7472
Closed
5 of 6 tasks

[BUG][CLI] crash when evaluating definitions without parameters #7453

codymikol opened this issue Sep 19, 2020 · 3 comments · Fixed by #7472

Comments

@codymikol
Copy link
Contributor

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

When you provide openapi-generator an openapi definition that includes a url with path variables, but no defined parameters, it will throw a null pointer exception.

Exception in thread "main" java.lang.NullPointerException
        at java.base/java.util.HashSet.<init>(HashSet.java:120)
        at org.openapitools.codegen.config.CodegenConfigurator.toContext(CodegenConfigurator.java:464)
        at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:507)
        at org.openapitools.codegen.cmd.Generate.execute(Generate.java:423)
        at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
        at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:61)
openapi-generator version

5.0.0-SNAPSHOT

OpenAPI declaration file content or url

https://github.com/codymikol/openapi-generator-kotlin-bug-demo/blob/master/generated-openapi-spec.json

Generation Details

This seems to happen regardless of generator-name, and the only other CLI options I am providing are the input-spec and output.

Steps to reproduce

I have created a minimal repro repository over here
this includes a shell script with all of the exact steps that I took. The generated openapi spec is hardcoded in the repo, but I have also included a minimal Spring project that generates the spec via springfox 3 if you'd like to generate that yourself.

Note that the script uses the latest published openapi-generator and will need some tweaking to point at your own build. I have tested with both and they have the same result

Related issues/PRs

I did a search, but found nothing similar.

Suggest a fix

I plan on looking into this myself, this is mostly to help document the issue in case I end up not having enough time. Any suggestions would be great.

@codymikol
Copy link
Contributor Author

I'll leave this for my findings while digging into this

It looks like when this is evaluated, the result.messages property is null and this is what causes the NPE.

SwaggerParseResult result = new OpenAPIParser().readLocation(inputSpec, authorizationValues, options);

@codymikol
Copy link
Contributor Author

The root cause of this issue seems to come from swagger-parser. It will return null for messages and throw a NPE. I think what we can do is add some decent error handling for when this kind of error does occur.

codymikol pushed a commit to codymikol/openapi-generator that referenced this issue Sep 21, 2020
swagger-parser has the potential to return null
for messages which will throw NPE on
initialization of the  validationMessages hashset.
rather that allow this to happen we will assume
that a null message collection represents an empty
collection and continue.

Fixes OpenAPITools#7453
@codymikol
Copy link
Contributor Author

I have added a PR that will not fix this, but will make it much more obvious what has gone wrong.

wing328 pushed a commit that referenced this issue Sep 29, 2020
swagger-parser has the potential to return null
for messages which will throw NPE on
initialization of the  validationMessages hashset.
rather that allow this to happen we will assume
that a null message collection represents an empty
collection and continue.

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

Successfully merging a pull request may close this issue.

2 participants