Skip to content

[Dart2] Fix compile errors for required enums without default value.#7877

Merged
wing328 merged 1 commit intoOpenAPITools:masterfrom
gilbsgilbs:fix-dart-enum-default-value
Nov 24, 2020
Merged

[Dart2] Fix compile errors for required enums without default value.#7877
wing328 merged 1 commit intoOpenAPITools:masterfrom
gilbsgilbs:fix-dart-enum-default-value

Conversation

@gilbsgilbs
Copy link
Copy Markdown
Contributor

@gilbsgilbs gilbsgilbs commented Nov 4, 2020

Before:

  schemas:
    Order:
      type: object
      required: ["status"]
      properties:
        status:
          type: string
          enum:
            - placed
            - approved
            - delivered

Would produce the following Dart code which would fail to compile (because of a missing required parameter):

OrderEnum order = OrderEnum._();

This PR skips the enum initialization when no default value is provided.

Also, when a minimum value was specified for a property, I think there was a comment expected to display but wasn't (because it was in a wrong section). If fixed the comment value and put it in the proper section so that it shows.

PR checklist

  • Read the contribution guidelines.
  • 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.
  • If contributing template-only or documentation-only changes which will change sample output, build the project beforehand.
  • Run the shell script ./bin/generate-samples.shto update all Petstore samples related to your fix. 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 ./bin/generate-samples.sh bin/configs/java*. For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master
  • Copy the technical committee to review the pull request if your PR is targeting a particular programming language. @ircecho @swipesight @jaumard @athornz @amondnet

@agilob
Copy link
Copy Markdown
Contributor

agilob commented Nov 12, 2020

You need to run mvn clean package -DskipTests=true && ./bin/generate-samples.sh to update existing sample projects. Commit only changes in .dart files.

@gilbsgilbs
Copy link
Copy Markdown
Contributor Author

gilbsgilbs commented Nov 12, 2020

@agilob The petstore sample is not affected by this change actually, that's why this PR only modifies the template files. Do you want me to add specific test cases for this?

@agilob
Copy link
Copy Markdown
Contributor

agilob commented Nov 14, 2020

@wing328 can we get this in pls?

@wing328
Copy link
Copy Markdown
Member

wing328 commented Nov 23, 2020

@agilob Sorry for late reply as we were busy with the v5.0.0-beta3 release.

@gilbsgilbs can you please resolve the merge conflicts when you've time?

Also fix display of minimum/maximum comment.
@gilbsgilbs gilbsgilbs force-pushed the fix-dart-enum-default-value branch from 0efa375 to 5a18352 Compare November 23, 2020 09:32
@gilbsgilbs
Copy link
Copy Markdown
Contributor Author

@wing328 ✅ Thanks.

@wing328 wing328 merged commit 9c0850f into OpenAPITools:master Nov 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants