Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 7.7k
[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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
330526feef247dacddd80cabdbda2c5ef70693227ce1c9571b35785c36f47e70feda9bdc34a8a237bdc45d4fa0ff336c78a3ab5d24f3f64f3a2cb03019084ad6af303f9c7e21826b4656d185a1a78f4108e8cb4fa820c446e2a3aede628453c56734420314487608f74c41ddb78f075a25eb6bc5006f9e76f2d2c408052567ec4eda016b88b894e14cf5ceefFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| 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" |
| 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() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| const {{classname}}(this._dio); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| _responseData = deserialize<{{{returnType}}}, {{{returnBaseType}}}>(_response.data!, '{{{returnType}}}', growable: true); |
| 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'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {{{paramName}}} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {{#bodyParam}}_bodyData=jsonEncode({{{paramName}}});{{/bodyParam}} |
| 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
Uh oh!There was an error while loading. Please reload this page. | ||
| 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}}, | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. needs ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe I have addressed this now | ||
| 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}} | ||
| 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}} | ||
| }); |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.