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] nullable schema is not allowed to contain null #5615

Open
5 tasks done
domenkozar opened this issue Mar 17, 2020 · 7 comments
Open
5 tasks done

[BUG] nullable schema is not allowed to contain null #5615

domenkozar opened this issue Mar 17, 2020 · 7 comments

Comments

@domenkozar
Copy link

domenkozar commented Mar 17, 2020

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used? 5.0.0
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
Description

Generator crashes if nullable enum schema contains null value.

This is allowed by jsonschema and thus openapi spec.

openapi-generator version

5.0.0 branch, 4th Feb 2020

OpenAPI declaration file content or url
rating:
      type: string
      nullable: true
      enum:
        - null 
        - Gibberish
Command line used for generation
openapi-generator-cli  generate --input-spec openapi.yaml --enable-post-process-file --generator-name elm --config openapi-generator.yml  --output openapi-client
Steps to reproduce

There's an error:

Exception in thread "main" java.lang.RuntimeException: Could not process model 'rating'.Please make sure that your schema is correct!
        at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:473)
        at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:938)
        at org.openapitools.codegen.cmd.Generate.run(Generate.java:423)
        at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:61)
Caused by: java.lang.NullPointerException
        at org.openapitools.codegen.DefaultCodegen.postProcessModelsEnum(DefaultCodegen.java:490)
        at org.openapitools.codegen.languages.ElmClientCodegen.postProcessModels(ElmClientCodegen.java:321)
        at org.openapitools.codegen.DefaultGenerator.processModels(DefaultGenerator.java:1214)
        at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:468)
        ... 3 more
@domenkozar
Copy link
Author

cc @eriktim

@domenkozar domenkozar changed the title [BUG][Elm] nullable Elm schema is not allowed to contain null [BUG][Elm] nullable Elm schema is not allowed contains null Mar 17, 2020
@domenkozar domenkozar changed the title [BUG][Elm] nullable Elm schema is not allowed contains null [BUG][Elm] nullable Elm schema is not allowed to contain null Mar 17, 2020
@eriktim
Copy link
Contributor

eriktim commented Mar 19, 2020

Thanks for opening this issue @domenkozar.
The error seems to be misleading. I think the issue is you're using null as an enum value here which seems to be unsupported. I'm not sure what you're trying to achieve here, but I think there are two options for now:

  1. You want null to be one of the values of the enum. In that case you should write "null" in the yaml instead, or

  2. You want the enum to be nullable. In that case I would recommend providing the non-nullable enum as a type and whereever you use it you can use nullable/[not-]required. For example:

optionA:
  required:
    - rating
  properties:
    rating:
      $ref: '#/components/schemas/rating'
      nullable: true
optionB:
  properties:
    rating:
      $ref: '#/components/schemas/rating'
rating:
      type: string
      enum:
        - Gibberish

@wing328 can you clarify what the desired behavior is here?

@domenkozar
Copy link
Author

domenkozar commented Mar 19, 2020

OpenAPI specification says schemas respect jsonschema, which does allow for my example.

See OAI/OpenAPI-Specification#1900 (comment)

@eriktim
Copy link
Contributor

eriktim commented Mar 19, 2020

Yes I've seen that one but it seems the OpenAPI generator does not support this (yet?). It's not the Elm generator breaking here.

@domenkozar domenkozar changed the title [BUG][Elm] nullable Elm schema is not allowed to contain null [BUG] nullable schema is not allowed to contain null Mar 19, 2020
@domenkozar
Copy link
Author

Thanks - I've updated issue title to reflect that.

@zupo
Copy link

zupo commented Aug 4, 2020

Hey @eriktim, where should I report this so that it gets fixed in the "OpenAPI generator", so that I can then help getting it fixed for Elm?

@eriktim
Copy link
Contributor

eriktim commented Aug 11, 2020

@zupo this should be the right location. I was actually hoping for @wing328 to give some clarity on this issue.

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

3 participants