swagger-api / swagger-api/swagger-codegen

dart generator crashes when encountering enums containing only null

Open
#10,829 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

dart generator throws NPE when encountering enums containing only null while other client generators (java) process them just fine.

Swagger-codegen version

3.0.24-SNAPSHOT
(built from 2d0f7a9e1b61a470039ea580a4d3024b1da92188 (HEAD -> 3.0.0, origin/3.0.0))

Swagger declaration file content or url
components:
  schemas:
    NullEnum:
        enum:
        - null

this seems to be what caused the bug, I can't include the entire spec.
output:

Exception in thread "Thread-0" java.lang.RuntimeException: Could not process model 'NullEnum'.Please make sure that your schema is correct!
        at io.swagger.codegen.v3.DefaultGenerator.generateModels(DefaultGenerator.java:386)
        at io.swagger.codegen.v3.DefaultGenerator.generate(DefaultGenerator.java:779)
        at io.swagger.codegen.v3.cli.cmd.Generate.run(Generate.java:378)
        at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: java.lang.NullPointerException
        at io.swagger.codegen.v3.generators.dart.DartClientCodegen.buildEnumFromValues(DartClientCodegen.java:390)
        at io.swagger.codegen.v3.generators.dart.DartClientCodegen.postProcessModelsEnum(DartClientCodegen.java:364)
        at io.swagger.codegen.v3.generators.dart.DartClientCodegen.postProcessModels(DartClientCodegen.java:355)
        at io.swagger.codegen.v3.DefaultGenerator.processModels(DefaultGenerator.java:1053)
        at io.swagger.codegen.v3.DefaultGenerator.generateModels(DefaultGenerator.java:375)
        ... 3 more
Command line used for generation

java -jar ~/Documents/projects/swagger-codegen/modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -l dart -i $MYSPEC -o ~/Documents/projects/dart-apiclientswagger/

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in modules/swagger-codegen/src/main/java/io/swagger/codegen/v3/generators/dart/DartClientCodegen.java, especially buildEnumFromValues and postProcessModelsEnum. Run the provided generation command with the minimal NullEnum YAML; done means the Dart generator processes an enum containing only null without the reported NullPointerException.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart, java
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.