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

[Dart][Client] Fix default value of enum variables #7496

Merged
merged 5 commits into from
Sep 28, 2020

Conversation

lchwe
Copy link
Contributor

@lchwe lchwe commented Sep 23, 2020

Classes that have enums properties with a default required value are initialized with a String value, rather than using the enum values, so the dart client fails to compile unless this is manually fixed.

For example, I get the following generated:
AppointmentStatusEnum status = "open";

while I should be getting instead:
AppointmentStatusEnum status = AppointmentStatusEnum._internal("open");

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 (2017/07) @swipesight (2018/09) @jaumard (2018/09) @athornz (2019/12) @amondnet (2019/12)

@lchwe lchwe changed the title Dart - Fix default value of enum variables [Dart][Client] -\ Fix default value of enum variables Sep 23, 2020
@lchwe lchwe changed the title [Dart][Client] -\ Fix default value of enum variables [Dart][Client] Fix default value of enum variables Sep 23, 2020
@szotp
Copy link

szotp commented Sep 25, 2020

Hi, this is slightly offtopic, but do you have any array of enums in your scheme? It seems to be completely broken currently, instead of List<ExampleDefinitionExampleEnum> it generates ExampleDefinitionExampleEnumArrayEnum.

@lchwe
Copy link
Contributor Author

lchwe commented Sep 25, 2020

@szotp I don't think I have that issue

@wing328
Copy link
Member

wing328 commented Sep 26, 2020

@lchwe can you try to merge the latest master of the official repo into this branch to see if that fixes the CI failures?

I wanted to do it for you but don't have the right to modify your branch.

@lchwe
Copy link
Contributor Author

lchwe commented Sep 26, 2020

@wing328 nice, all green now!

@wing328
Copy link
Member

wing328 commented Sep 28, 2020

@lchwe I did a test manually with a top-level enum definition in the spec and here is what I got (partial code):

part of openapi.api;

class ModelStatus {
  /// The underlying value of this enum member.
  final String value;

  const ModelStatus._internal(this.value);

  /// pet status in the store
  static const ModelStatus available_ = ModelStatus._internal(&quot;available&quot;);
  /// pet status in the store
  static const ModelStatus pending_ = ModelStatus._internal(&quot;pending&quot;);
  /// pet status in the store
  static const ModelStatus sold_ = ModelStatus._internal(&quot;sold&quot;);

  static List<ModelStatus> get values => const [
        available_,
        pending_,
        sold_,
      ];

Are those &quot; expected?

@lchwe
Copy link
Contributor Author

lchwe commented Sep 28, 2020

@wing328 , weird. It should not be &quot;, it should just be normal quotes (ie. ""). Must be because the defaultValue has the triple curly braces. It's weird because, it was already like that before i made the change and i never got &quot; before. So I'm pretty sure using double curly braces on defaultValue would fix the issue

@lchwe
Copy link
Contributor Author

lchwe commented Sep 28, 2020

@wing328 thanks for the help btw!

@wing328
Copy link
Member

wing328 commented Sep 28, 2020

Agreed triple curly braces should not result in those HTML-escaped output. Likely a mistake in my end when testing the change.

@wing328 wing328 merged commit 3f18d0f into OpenAPITools:master Sep 28, 2020
@lchwe lchwe deleted the dart-enum-default-fix branch September 28, 2020 16:44
@wing328 wing328 added this to the 5.0.0 milestone Oct 26, 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.

None yet

4 participants