Skip to content

[Dart] Add configuration to add new generators and add json_serializable#8789

Merged
wing328 merged 23 commits intoOpenAPITools:masterfrom
agilob:dart-json_serializable
Feb 25, 2021
Merged

[Dart] Add configuration to add new generators and add json_serializable#8789
wing328 merged 23 commits intoOpenAPITools:masterfrom
agilob:dart-json_serializable

Conversation

@agilob
Copy link
Copy Markdown
Contributor

@agilob agilob commented Feb 22, 2021

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.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    
    Commit all changed files.
    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, 5.1.x, 6.0.x
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@agilob agilob marked this pull request as ready for review February 22, 2021 16:50
@agilob
Copy link
Copy Markdown
Contributor Author

agilob commented Feb 22, 2021

@swipesight (2018/09) @jaumard (2018/09) @josh-burton (2019/12) @amondnet (2019/12) @sbu-WBT (2020/12) @kuhnroyal (2020/12) @agilob (2020/12)

specify default serializer
@agilob agilob force-pushed the dart-json_serializable branch from bfb97ae to bf370a9 Compare February 22, 2021 17:04
Copy link
Copy Markdown
Contributor

@kuhnroyal kuhnroyal left a comment

Choose a reason for hiding this comment

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

I like it a lot.
You should test if the minimum supported Dart version needs to be raised.
And maybe get rid of the new empty lines to reduce noise.

Also add a pom.xml for the json_serializable sample?

@agilob
Copy link
Copy Markdown
Contributor Author

agilob commented Feb 22, 2021

You should test if the minimum supported Dart version needs to be raised.

json_serializer now has version 4.0.0 which will require updating dart version, but so far this is ok. I don't want to make too many changes at once here. eg. default value isn't support yet here, nor standalone enums, but it's a major move forward I think. It will open way for @k-paxian to add dart-json-mapper serializer in client library.

@kuhnroyal
Copy link
Copy Markdown
Contributor

kuhnroyal commented Feb 22, 2021

I am sure not the current approach with the part files will work. Have you run the build runner? I think you are missing the model part files and since only one part (of) is allowed, this might fail.

Maybe we first need to get rid of the current part files and use correct exports.

@agilob
Copy link
Copy Markdown
Contributor Author

agilob commented Feb 22, 2021

I am sure not the current approach with the part files will work. Have you run the build runner? I think you are missing the model part files and since only one part (of) is allowed, this might fail.

Neither I am, but this actually works quite nice. Instead producing really verbose files, one .g.dart for each model it generates one big api.g.dart which has serialization code for all models. It's much nicer to see in IDE. The project builds:

❯ pwd
/home/agilob/Projects/openapi-generator/samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake
 pub get && pub run build_runner build
Resolving dependencies... 
Got dependencies!
Precompiling executable... (8.6s)
Precompiled build_runner:build_runner.
[INFO] Generating build script completed, took 242ms
[INFO] Reading cached asset graph completed, took 44ms
[INFO] Checking for updates since last build completed, took 324ms
[INFO] Running build completed, took 19ms
[INFO] Caching finalized dependency graph completed, took 25ms
[INFO] Succeeded after 51ms with 0 outputs (0 actions)


@agilob
Copy link
Copy Markdown
Contributor Author

agilob commented Feb 22, 2021

And maybe get rid of the new empty lines to reduce noise.

Check commit history... and I give up, the new empty lines are result of

{{/json_serializable}}
{{#json_serializable}}

I'd rather have nicer mustache template than autogenerated code that shouldn't me modified manually anyway... (and we recommend running dartfmt after generation). You can remove whitespaces from GH review in options.

@agilob
Copy link
Copy Markdown
Contributor Author

agilob commented Feb 22, 2021

Travis failing

anyrequests: You have reached your pull rate limit.
You may increase the limit by authenticating and upgrading: https://www.docker.com/increase-rate-limit

@wing328

@kuhnroyal
Copy link
Copy Markdown
Contributor

That is good but I know a lot of generators where this will not work. So we should do that anyway, but then it can be independent of this change.

There seems to be some transformer stuff left in the api client and helper that doesnt compile.

@agilob
Copy link
Copy Markdown
Contributor Author

agilob commented Feb 22, 2021

That is good but I know a lot of generators where this will not work. So we should do that anyway, but then it can be independent of this change.

I propose to do it after this change, I find this PR to be too much in one go already.

@agilob
Copy link
Copy Markdown
Contributor Author

agilob commented Feb 22, 2021

There seems to be some transformer stuff left in the api client and helper that doesnt compile.

Unfortunately this is where we're hitting temporary limitation of json_serializable and for now I can't add this module to pom.xml

image

it doesn't generate mapping for enums that are not used in classes. This is purely temporary as this api-helper and api-client are redundant for this functionality. Each class has its own toJson and fromJson method now, but I'm going to keep it in this PR for backwards consistency. Both native and j_s serializes now can be used interchangeably.

@kuhnroyal
Copy link
Copy Markdown
Contributor

I see, so you want this merged to have the basic infrastructure in place although the json_serializable option does not completely work yet. I agree in that regard, maybe we should log some warning when this option is set until it is completely working.

That is good but I know a lot of generators where this will not work. So we should do that anyway, but then it can be independent of this change.

I propose to do it after this change, I find this PR to be too much in one go already.

I agree, this is out of scope.

@agilob
Copy link
Copy Markdown
Contributor Author

agilob commented Feb 23, 2021

I agree in that regard, maybe we should log some warning when this option is set until it is completely working.

I'll add default value support after this gets in. It doesn't have to be perfect on the first merge. defaultValue flag is also incompatible with nullable flag in json_serializable so this need to be conditional support in mustache template, which I simply avoided doing now. This is big already. I'll add this later, but also very soon.

If you think this looks good, can we get this merged please @kuhnroyal and @wing328 ?

@kuhnroyal
Copy link
Copy Markdown
Contributor

I think changing the enum templates to }{{/json_serializable}}{{#json_serializable}} removes the new lines if you want. Otherwise I am good with this.

@agilob
Copy link
Copy Markdown
Contributor Author

agilob commented Feb 23, 2021

Done!

@agilob agilob force-pushed the dart-json_serializable branch from 31da697 to 926515e Compare February 23, 2021 16:38
@wing328 wing328 added Client: Dart Enhancement: Feature Enhancement: Code Cleanup General refactoring, removal of deprecated things, commenting, etc. labels Feb 24, 2021
@wing328 wing328 added this to the 5.1.0 milestone Feb 24, 2021
@wing328
Copy link
Copy Markdown
Member

wing328 commented Feb 24, 2021

@agilob thanks for the PR. Please resolve the merge conflicts when you've time.

@agilob
Copy link
Copy Markdown
Contributor Author

agilob commented Feb 24, 2021

@wing328 done

@agilob
Copy link
Copy Markdown
Contributor Author

agilob commented Feb 25, 2021

@wing328 can we get this in please? I want to add a few more features to this generator while I still have time for it

@wing328 wing328 merged commit 9fc33f6 into OpenAPITools:master Feb 25, 2021
@wing328
Copy link
Copy Markdown
Member

wing328 commented Feb 25, 2021

Just merged. Thanks again for the PR.

@agilob agilob deleted the dart-json_serializable branch September 25, 2021 20:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Client: Dart Enhancement: Code Cleanup General refactoring, removal of deprecated things, commenting, etc. Enhancement: Feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants