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][dart-dio] Nullable support/improvements #8235

Closed

Conversation

kuhnroyal
Copy link
Contributor

@kuhnroyal kuhnroyal commented Dec 18, 2020

dart-dio/built_value

  • Disable all fields nullable by default:
    This is not in line with OAS and will prevent future Dart nullabilty features (NNBD) from being useful as all types would be optional.

  • Properties are @nullable when not required AND not nullable

  • Support nullable/required fields in JSON

    • properties in built_value need to be @nullable when they are nullable in OAS or when they are not required in OAS
    • built_value does not support serializing null values by default as it is based on a serialization format based on iterables/lists and not maps
    • dart-dio uses the built_value json plugin to convert the built_value format to regular json
    • by generating a custom serializer for each class we can add support for serializing null values if the property is required AND nullable in OAS
    • this is a breaking change as not all properties in the models are nullable by default anymore

Dart

  • basically just serialize null when the field is required and nullable

This is based on #8220 which needs to be merged first.

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.

@auto-labeler
Copy link

auto-labeler bot commented Dec 18, 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.

@kuhnroyal
Copy link
Contributor Author

@josh-burton Would really like your input on this.

@kuhnroyal kuhnroyal force-pushed the dart-dio/nullable-improvements branch from 31126fb to 96cd974 Compare January 7, 2021 16:35
* prevent further name conflicts by correctly naming the enum, until now there could potentially occur conflicts e.g. 2x `MapTestInnerEnum` by renaming the `items` child property
* correctly set `enumName` to match `datatypeWithEnum`
This is not in line with the OAS and will prevent future Dart nullabilty features (NNBD) from being useful as all types would be optional.
Users can still opt-in for this.
* properties in built_value need to be nullable when they are nullable in OAS or when they are not required in OAS
* built_value does not support serializing `null` values by default as it is based on a serialization format based on iterables/lists and not maps
* dart-dio uses the built_value json plugin to convert the built_value format to regular json
* by generating a custom serializer for each class we can add support for serializing `null` values if the property is required AND nullable in OAS
* this is a breaking change as not all properties in the models are nullable by default anymore
@kuhnroyal
Copy link
Contributor Author

@agilob Please check it out, serialization for the normal Dart generator is a mess so I am not so sure

@@ -1,5 +1,6 @@
# RELEASE_VERSION
openApiGeneratorVersion=5.0.1-SNAPSHOT
openApiGeneratorVersion=5.1.0-SNAPSHOT
>>>>>>> origin/master
Copy link
Contributor

Choose a reason for hiding this comment

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

merge conflict message here

@@ -4,7 +4,7 @@
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-project</artifactId>
<!-- RELEASE_VERSION -->
<version>5.0.1-SNAPSHOT</version>
<version>5.1.0-SNAPSHOT</version>
Copy link
Contributor

Choose a reason for hiding this comment

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

I think version bump should go in a separate PR, but leaving this to @wing328

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wrong target branch

@@ -1,14 +1,14 @@
{{#description}}/// {{{description}}}{{/description}}
class {{{classname}}}{{{enumName}}} {
class {{{enumName}}} {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that's a big breaking change for no big benefit, enum serialisation still won't be as good as in other languages. I think it's time to give up on doing this in openapi and use a more popular 3rd party library do it for us. I'm only familiar with json_serializable but it doesn't handle standalone enums so can't use it here. I'll look around soon.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is actually part of #8220 but required for this to work.

@kuhnroyal kuhnroyal changed the base branch from master to 5.1.x January 8, 2021 20:42
@kuhnroyal
Copy link
Contributor Author

Yea, wrong target and the enum branch this is based up on has already been discussed.

@wing328 wing328 closed this Feb 8, 2021
@wing328 wing328 deleted the branch OpenAPITools:5.1.x February 8, 2021 13:21
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