-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
[Dart-Dio-Next]#9082 Add json_serializable serialization option #9980
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
Merged
wing328
merged 40 commits into
OpenAPITools:master
from
MichaelMarner:dart-dio-next-json-serializable
Apr 27, 2022
Merged
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
330526f
PoC json_serializable in dart-dio-next
MichaelMarner eef247d
Move build.yaml template into json_serializable dir
MichaelMarner acddd80
Undo implicit-dynamic change
MichaelMarner cabdbda
Fix automatic formatting
MichaelMarner 2c5ef70
Treat non-required fields as nullable
MichaelMarner 693227c
Make class properties final
MichaelMarner e1c9571
Fix error introduced by merging in master
MichaelMarner b35785c
Fix map creation when deserializing
MichaelMarner 36f47e7
Exclude built files from analysis
MichaelMarner 0feda9b
Add new dio import props
MichaelMarner dc34a8a
Fix broken merge
MichaelMarner 237bdc4
Fix configuration of nullable properties
MichaelMarner 5d4fa0f
Only add api_util import if using built value
MichaelMarner f336c78
Add config param to set properties as final
MichaelMarner a3ab5d2
Fix syntax error due to merge
MichaelMarner 4f3f64f
Update to simplified dio configuration
MichaelMarner 3a2cb03
Merge branch 'master' into dart-dio-next-json-serializable
MichaelMarner 019084a
Add missing api constructor template
MichaelMarner d6af303
Merge branch 'dart-dio-next-json-serializable' of github.com:MichaelM…
MichaelMarner f9c7e21
Fix import for multipart files
MichaelMarner 826b465
Fix inclusion of library deserialize template
MichaelMarner 6d185a1
Update docs
MichaelMarner a78f410
Remove trailing newline from class
MichaelMarner 8e8cb4f
Fix whitespace in generated templates
MichaelMarner a820c44
FIx built value generation problem caused by merge conflicts
MichaelMarner 6e2a3ae
Escape dollar signs in strings
MichaelMarner de62845
Handle enums
MichaelMarner 3c56734
Config for json_serializable sample
MichaelMarner 4203144
Generate sample for json_serializable
MichaelMarner 87608f7
Revert "Escape dollar signs in strings"
MichaelMarner 4c41ddb
Use raw strings when dealing with enum values
MichaelMarner 78f075a
Add json_serializable Maven module ind fix number based enums
kuhnroyal 25eb6bc
Merge pull request #3 from kuhnroyal/dart-dio-next-json-serializable
MichaelMarner 5006f9e
Update docs and fix wrong maven module
kuhnroyal 76f2d2c
Merge remote-tracking branch 'OpenAPITools/master' into dart-dio-next…
kuhnroyal 4080525
Merge pull request #4 from kuhnroyal/dart-dio-next-json-serializable
MichaelMarner 67ec4ed
Merge remote-tracking branch 'upstream/master' into dart-dio-next-jso…
MichaelMarner a016b88
Update minimum dart sdk with json serializable
MichaelMarner b894e14
Use dart 2.14 when testing Dart samples
MichaelMarner cf5ceef
Update codegen to remove analysis errors in output
MichaelMarner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
bin/configs/dart-dio-next-petstore-client-lib-fake-json_serializable.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| generatorName: dart-dio-next | ||
| outputDir: samples/openapi3/client/petstore/dart-dio-next/petstore_client_lib_fake-json_serializable | ||
| inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml | ||
| templateDir: modules/openapi-generator/src/main/resources/dart/libraries/dio | ||
| typeMappings: | ||
| Client: "ModelClient" | ||
| File: "ModelFile" | ||
| EnumClass: "ModelEnumClass" | ||
| additionalProperties: | ||
| hideGenerationTimestamp: "true" | ||
| enumUnknownDefaultCase: "true" | ||
| serializationLibrary: "json_serializable" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
...or/src/main/resources/dart/libraries/dio/serialization/built_value/test_instance.mustache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| final instance = {{{classname}}}Builder(); | ||
| // TODO add properties to the builder and call build() |
1 change: 1 addition & 0 deletions
1
...ain/resources/dart/libraries/dio/serialization/json_serializable/api/constructor.mustache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| const {{classname}}(this._dio); |
1 change: 1 addition & 0 deletions
1
...ain/resources/dart/libraries/dio/serialization/json_serializable/api/deserialize.mustache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| _responseData = deserialize<{{{returnType}}}, {{{returnBaseType}}}>(_response.data!, '{{{returnType}}}', growable: true); |
3 changes: 3 additions & 0 deletions
3
...rc/main/resources/dart/libraries/dio/serialization/json_serializable/api/imports.mustache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| // ignore: unused_import | ||
| import 'dart:convert'; | ||
| import 'package:{{pubName}}/src/deserialize.dart'; |
1 change: 1 addition & 0 deletions
1
...ain/resources/dart/libraries/dio/serialization/json_serializable/api/query_param.mustache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {{{paramName}}} |
1 change: 1 addition & 0 deletions
1
.../main/resources/dart/libraries/dio/serialization/json_serializable/api/serialize.mustache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {{#bodyParam}}_bodyData=jsonEncode({{{paramName}}});{{/bodyParam}} |
18 changes: 18 additions & 0 deletions
18
...src/main/resources/dart/libraries/dio/serialization/json_serializable/build.yaml.mustache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| targets: | ||
| $default: | ||
| builders: | ||
| json_serializable: | ||
| options: | ||
| # Options configure how source code is generated for every | ||
| # `@JsonSerializable`-annotated class in the package. | ||
| # | ||
| # The default value for each is listed. | ||
| any_map: false | ||
| checked: true | ||
| create_factory: true | ||
| create_to_json: true | ||
| disallow_unrecognized_keys: true | ||
| explicit_to_json: true | ||
| field_rename: none | ||
| ignore_unannotated: false | ||
| include_if_null: false | ||
MichaelMarner marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
93 changes: 93 additions & 0 deletions
93
...ator/src/main/resources/dart/libraries/dio/serialization/json_serializable/class.mustache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| import 'package:json_annotation/json_annotation.dart'; | ||
|
|
||
| part '{{classFilename}}.g.dart'; | ||
|
|
||
| {{! | ||
| Classes with polymorphism or composition may generate unused imports, | ||
| these need to be ignored for said classes so that there are no lint errors. | ||
| }} | ||
| {{#parentModel}} | ||
| // ignore_for_file: unused_import | ||
|
|
||
| {{/parentModel}} | ||
|
|
||
| @JsonSerializable( | ||
| checked: true, | ||
| createToJson: true, | ||
| disallowUnrecognizedKeys: false, | ||
| explicitToJson: true, | ||
| ) | ||
| class {{{classname}}} { | ||
| {{>serialization/json_serializable/dart_constructor}} | ||
|
|
||
| {{#vars}} | ||
| {{#description}} | ||
| /// {{{description}}} | ||
| {{/description}} | ||
| {{^isEnum}} | ||
| {{#minimum}} | ||
| // minimum: {{{minimum}}} | ||
| {{/minimum}} | ||
| {{#maximum}} | ||
| // maximum: {{{maximum}}} | ||
| {{/maximum}} | ||
| {{/isEnum}} | ||
| {{^isBinary}} | ||
| @JsonKey( | ||
| {{#defaultValue}}defaultValue: {{{defaultValue}}},{{/defaultValue}} | ||
| name: r'{{{baseName}}}', | ||
| required: {{#required}}true{{/required}}{{^required}}false{{/required}}, | ||
|
||
| includeIfNull: {{#required}}{{#isNullable}}true{{/isNullable}}false{{/required}}{{^required}}false{{/required}} | ||
| ) | ||
| {{/isBinary}} | ||
| {{#isBinary}} | ||
| @JsonKey(ignore: true) | ||
| {{/isBinary}} | ||
|
|
||
|
|
||
| {{#required}} | ||
| {{#finalProperties}}final {{/finalProperties}}{{{datatypeWithEnum}}}{{#isNullable}}?{{/isNullable}} {{{name}}}; | ||
| {{/required}} | ||
| {{^required}} | ||
| {{#finalProperties}}final {{/finalProperties}}{{{datatypeWithEnum}}}? {{{name}}}; | ||
| {{/required}} | ||
|
|
||
|
|
||
|
|
||
| {{/vars}} | ||
| @override | ||
| bool operator ==(Object other) => identical(this, other) || other is {{{classname}}} && | ||
| {{#vars}} | ||
| other.{{{name}}} == {{{name}}}{{^-last}} &&{{/-last}}{{#-last}};{{/-last}} | ||
| {{/vars}} | ||
|
|
||
| @override | ||
| int get hashCode => | ||
| {{#vars}} | ||
| {{#isNullable}}({{{name}}} == null ? 0 : {{{name}}}.hashCode){{/isNullable}}{{^isNullable}}{{{name}}}.hashCode{{/isNullable}}{{^-last}} +{{/-last}}{{#-last}};{{/-last}} | ||
| {{/vars}} | ||
|
|
||
| factory {{{classname}}}.fromJson(Map<String, dynamic> json) => _${{{classname}}}FromJson(json); | ||
|
|
||
| Map<String, dynamic> toJson() => _${{{classname}}}ToJson(this); | ||
|
|
||
| @override | ||
| String toString() { | ||
| return toJson().toString(); | ||
| } | ||
|
|
||
| } | ||
| {{#vars}} | ||
| {{#isEnum}} | ||
| {{^isContainer}} | ||
|
|
||
| {{>serialization/json_serializable/enum_inline}} | ||
| {{/isContainer}} | ||
| {{#isContainer}} | ||
| {{#mostInnerItems}} | ||
|
|
||
| {{>serialization/json_serializable/enum_inline}} | ||
| {{/mostInnerItems}} | ||
| {{/isContainer}} | ||
| {{/isEnum}} | ||
| {{/vars}} | ||
11 changes: 11 additions & 0 deletions
11
...in/resources/dart/libraries/dio/serialization/json_serializable/dart_constructor.mustache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| /// Returns a new [{{{classname}}}] instance. | ||
| {{{classname}}}({ | ||
| {{#vars}} | ||
|
|
||
| {{! | ||
| A field is required in Dart when it is | ||
| required && !defaultValue in OAS | ||
| }} | ||
| {{#required}}{{^defaultValue}}required {{/defaultValue}}{{/required}} this.{{{name}}}{{#defaultValue}} = {{#isEnum}}{{^isContainer}}const {{{enumName}}}._({{/isContainer}}{{/isEnum}}{{{defaultValue}}}{{#isEnum}}{{^isContainer}}){{/isContainer}}{{/isEnum}}{{/defaultValue}}, | ||
| {{/vars}} | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.