Skip to content

[dart][dart-dio] Enum improvements#8149

Merged
wing328 merged 2 commits intoOpenAPITools:masterfrom
kuhnroyal:dart/enums
Dec 13, 2020
Merged

[dart][dart-dio] Enum improvements#8149
wing328 merged 2 commits intoOpenAPITools:masterfrom
kuhnroyal:dart/enums

Conversation

@kuhnroyal
Copy link
Copy Markdown
Contributor

  • use raw strings for enum value where possible
  • special handling for dart-dio as raw string don't work as expected with the built_value generator
  • use the correct datatype in dart enum templates

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.

CC @ircecho (2017/07) @swipesight (2018/09) @jaumard (2018/09) @josh-burton (2019/12) @amondnet (2019/12)
FYI @agilob

@noordawod I reverted some of your changes to the enum templates. As far as I can tell isEnum is always true in enum templates.

@auto-labeler
Copy link
Copy Markdown

auto-labeler Bot commented Dec 9, 2020

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

@wing328
Copy link
Copy Markdown
Member

wing328 commented Dec 10, 2020

As far as I can tell isEnum is always true in enum templates.

Can you please elaborate on that? Sounds like a bug if it's always true independent of whether it's an enum or not.

@noordawod
Copy link
Copy Markdown
Contributor

Could you also elaborate more on use the correct datatype in dart enum templates?

@kuhnroyal
Copy link
Copy Markdown
Contributor Author

I have not found a model that get's passed into any of the enum(_inline) templates in which isEnum is false.
Which seems logical when you look at the model and class templates. They only render the enum templates when isEnum is true.

{{#models}}
{{#model}}
{{#isEnum}}
{{>enum}}
{{/isEnum}}
{{^isEnum}}
{{>class}}
{{/isEnum}}
{{/model}}
{{/models}}

Inside the enum template the value will always be a String which prevents int/double based enums from being correctly generated:

   /// The underlying value of this enum member.
  {{#isEnum}}	
  final String value;	
  {{/isEnum}}	
  {{^isEnum}}	
  final {{{dataType}}} value;
  {{/isEnum}}

After removing this check, the correct enum value type is generated: https://github.com/OpenAPITools/openapi-generator/pull/8149/files#diff-4671c37577153f83b40b0ad23a216cc1c6e1bbd2bbe7c074733af003c266f8b3L18

* use raw strings for enum string values
`@BuiltValueEnumConst` does some wierd string handling in the generated code `r'\$'` becomes `'$'`. This is different compared to the wireName in `@BuiltValueField`
static const InlineObject2EnumFormStringArray greaterThan = _$inlineObject2EnumFormStringArray_greaterThan;
/// Form parameter enum test (string array)
@BuiltValueEnumConst(wireName: '$')
@BuiltValueEnumConst(wireName: r'\$')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found a mismatch between dart-dio and dart. a few files below you will find:

static const dollar = EnumArraysJustSymbolEnum._(r'$');

You can see the $ isn't escaped with \ but it is here, both are raw strings. I suspect this is breaking compatibility between them?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah thanks for that, missed comment. Well, it's fine then I expressed my opinion on use of built_value in another PR.

bool operator ==(Object other) => identical(this, other) ||
other is InlineObject2EnumFormStringArrayEnum && other.value == value ||
other is String && other == value;
other is InlineObject2EnumFormStringArrayEnum && other.value == value;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

other.value == value

this is comparing references not contents of lists, so it's not what I would expect from == on enum. What are your expectations?

Copy link
Copy Markdown
Contributor

@agilob agilob Dec 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a request for change , just asking.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this is a list but is actually completely wrong. This needs to be fixed in some other PR. An enum with a list as value is not valid. And the inline objects are gonna be removed soon.
I know what causes this but it will get too big.

@agilob
Copy link
Copy Markdown
Contributor

agilob commented Dec 10, 2020

Please change title to include dart-dio

@kuhnroyal kuhnroyal changed the title [dart] Enum improvements [dart][dart-dio] Enum improvements Dec 10, 2020
@wing328 wing328 merged commit cd0257b into OpenAPITools:master Dec 13, 2020
@kuhnroyal kuhnroyal deleted the dart/enums branch December 13, 2020 16:13
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.

4 participants