diff --git a/modules/openapi-generator/src/main/resources/dart2/api.mustache b/modules/openapi-generator/src/main/resources/dart2/api.mustache index bbdc28b4462..6b01841dacd 100644 --- a/modules/openapi-generator/src/main/resources/dart2/api.mustache +++ b/modules/openapi-generator/src/main/resources/dart2/api.mustache @@ -69,19 +69,31 @@ class {{{classname}}} { final queryParams = []; final headerParams = {}; final formParams = {}; + {{#hasQueryParams}} - {{#queryParams}} - {{^required}} + {{#queryParams}} + {{^required}} if ({{{paramName}}} != null) { - {{/required}} + {{/required}} queryParams.addAll(_convertParametersForCollectionFormat('{{{collectionFormat}}}', '{{{baseName}}}', {{{paramName}}})); - {{^required}} + {{^required}} } - {{/required}} - {{/queryParams}} - {{#headerParams}} - headerParams['{{{baseName}}}'] = {{{paramName}}}; - {{/headerParams}} + {{/required}} + {{/queryParams}} + {{/hasQueryParams}} + {{#hasHeaderParams}} + + {{#headerParams}} + {{#required}} + headerParams['{{{baseName}}}'] = parameterToString({{{paramName}}}); + {{/required}} + {{^required}} + if ({{{paramName}}} != null) { + headerParams['{{{baseName}}}'] = parameterToString({{{paramName}}}); + } + {{/required}} + {{/headerParams}} + {{/hasHeaderParams}} final contentTypes = [{{#consumes}}'{{{mediaType}}}'{{^-last}}, {{/-last}}{{/consumes}}]; final nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null; diff --git a/modules/openapi-generator/src/main/resources/dart2/class.mustache b/modules/openapi-generator/src/main/resources/dart2/class.mustache index cfd45cf3a2e..ce7d8a4a9c9 100644 --- a/modules/openapi-generator/src/main/resources/dart2/class.mustache +++ b/modules/openapi-generator/src/main/resources/dart2/class.mustache @@ -6,118 +6,6 @@ class {{{classname}}} { {{/vars}} }); - /// Returns a new [{{{classname}}}] instance and optionally import its values from - /// [json] if it's non-null. - {{{classname}}}.fromJson(Map json) { - if (json != null) { - {{#vars}} - {{#isDateTime}} - {{{name}}} = json['{{{baseName}}}'] == null - ? null - {{#pattern}} - : _dateEpochMarker == '{{{pattern}}}' - ? DateTime.fromMillisecondsSinceEpoch(json['{{{baseName}}}'] as int, isUtc: true) - : DateTime.parse(json['{{{baseName}}}']); - {{/pattern}} - {{^pattern}} - : DateTime.parse(json['{{{baseName}}}']); - {{/pattern}} - {{/isDateTime}} - {{#isDate}} - {{{name}}} = json['{{{baseName}}}'] == null - ? null - {{#pattern}} - : _dateEpochMarker == '{{{pattern}}}' - ? DateTime.fromMillisecondsSinceEpoch(json['{{{baseName}}}'] as int, isUtc: true) - : DateTime.parse(json['{{{baseName}}}']); - {{/pattern}} - {{^pattern}} - : DateTime.parse(json['{{{baseName}}}']); - {{/pattern}} - {{/isDate}} - {{^isDateTime}} - {{^isDate}} - {{#complexType}} - {{#isArray}} - {{#items.isArray}} - {{{name}}} = json['{{{baseName}}}'] == null - ? null - : (json['{{{baseName}}}'] as List).map( - {{#items.complexType}} - {{items.complexType}}.listFromJson(json['{{{baseName}}}']) - {{/items.complexType}} - {{^items.complexType}} - (e) => e == null ? null : (e as List).cast<{{items.items.dataType}}>() - {{/items.complexType}} - ).toList(growable: false); - {{/items.isArray}} - {{^items.isArray}} - {{{name}}} = {{{complexType}}}.listFromJson(json['{{{baseName}}}']); - {{/items.isArray}} - {{/isArray}} - {{^isArray}} - {{#isMap}} - {{#items.isArray}} - {{{name}}} = json['{{{baseName}}}'] == null - ? null - {{#items.complexType}} - : {{items.complexType}}.mapListFromJson(json['{{{baseName}}}']); - {{/items.complexType}} - {{^items.complexType}} - : (json['{{{baseName}}}'] as Map).cast(); - {{/items.complexType}} - {{/items.isArray}} - {{^items.isArray}} - {{{name}}} = json['{{{baseName}}}'] == null - ? null - : {{{complexType}}}.mapFromJson(json['{{{baseName}}}']); - {{/items.isArray}} - {{/isMap}} - {{^isMap}} - {{{name}}} = {{{complexType}}}.fromJson(json['{{{baseName}}}']); - {{/isMap}} - {{/isArray}} - {{/complexType}} - {{^complexType}} - {{#isArray}} - {{#isEnum}} - {{{name}}} = {{{classname}}}{{{items.datatypeWithEnum}}}.listFromJson(json['{{{baseName}}}']); - {{/isEnum}} - {{^isEnum}} - {{{name}}} = json['{{{baseName}}}'] == null - ? null - : (json['{{{baseName}}}'] as List).cast<{{{items.datatype}}}>(); - {{/isEnum}} - {{/isArray}} - {{^isArray}} - {{#isMap}} - {{{name}}} = json['{{{baseName}}}'] == null ? - null : - (json['{{{baseName}}}'] as Map).cast(); - {{/isMap}} - {{^isMap}} - {{#isNumber}} - {{{name}}} = json['{{{baseName}}}'] == null ? - null : - json['{{{baseName}}}'].toDouble(); - {{/isNumber}} - {{^isNumber}} - {{^isEnum}} - {{{name}}} = json['{{{baseName}}}']; - {{/isEnum}} - {{#isEnum}} - {{{name}}} = {{{classname}}}{{{enumName}}}.fromJson(json['{{{baseName}}}']); - {{/isEnum}} - {{/isNumber}} - {{/isMap}} - {{/isArray}} - {{/complexType}} - {{/isDate}} - {{/isDateTime}} - {{/vars}} - } - } - {{#vars}} {{#description}}/// {{{description}}}{{/description}} {{^isEnum}} @@ -149,7 +37,7 @@ class {{{classname}}} { @override int get hashCode => {{#vars}} - {{#isNullable}}({{{name}}}?.hashCode ?? 0){{/isNullable}}{{^isNullable}}{{{name}}}.hashCode{{/isNullable}}{{^-last}} +{{/-last}}{{#-last}};{{/-last}} + ({{{name}}} == null ? 0 : {{{name}}}.hashCode){{^-last}} +{{/-last}}{{#-last}};{{/-last}} {{/vars}} @override @@ -157,38 +45,150 @@ class {{{classname}}} { Map toJson() { final json = {}; -{{#vars}} + {{#vars}} if ({{{name}}} != null) { - {{#isDateTime}} - {{#pattern}} + {{#isDateTime}} + {{#pattern}} json['{{{baseName}}}'] = _dateEpochMarker == '{{{pattern}}}' ? {{{name}}}.millisecondsSinceEpoch : {{{name}}}.toUtc().toIso8601String(); - {{/pattern}} - {{^pattern}} + {{/pattern}} + {{^pattern}} json['{{{baseName}}}'] = {{{name}}}.toUtc().toIso8601String(); - {{/pattern}} - {{/isDateTime}} - {{#isDate}} - {{#pattern}} + {{/pattern}} + {{/isDateTime}} + {{#isDate}} + {{#pattern}} json['{{{baseName}}}'] = _dateEpochMarker == '{{{pattern}}}' ? {{{name}}}.millisecondsSinceEpoch : _dateFormatter.format({{{name}}}.toUtc()); - {{/pattern}} - {{^pattern}} + {{/pattern}} + {{^pattern}} json['{{{baseName}}}'] = _dateFormatter.format({{{name}}}.toUtc()); - {{/pattern}} - {{/isDate}} - {{^isDateTime}} - {{^isDate}} - json['{{{baseName}}}'] = {{{name}}}; + {{/pattern}} {{/isDate}} - {{/isDateTime}} + {{^isDateTime}} + {{^isDate}} + json['{{{baseName}}}'] = {{{name}}}; + {{/isDate}} + {{/isDateTime}} } -{{/vars}} + {{/vars}} return json; } + /// Returns a new [{{{classname}}}] instance and imports its values from + /// [json] if it's non-null, null if [json] is null. + static {{{classname}}} fromJson(Map json) => json == null + ? null + : {{{classname}}}( + {{#vars}} + {{#isDateTime}} + {{{name}}}: json['{{{baseName}}}'] == null + ? null + {{#pattern}} + : _dateEpochMarker == '{{{pattern}}}' + ? DateTime.fromMillisecondsSinceEpoch(json['{{{baseName}}}'] as int, isUtc: true) + : DateTime.parse(json['{{{baseName}}}']), + {{/pattern}} + {{^pattern}} + : DateTime.parse(json['{{{baseName}}}']), + {{/pattern}} + {{/isDateTime}} + {{#isDate}} + {{{name}}}: json['{{{baseName}}}'] == null + ? null + {{#pattern}} + : _dateEpochMarker == '{{{pattern}}}' + ? DateTime.fromMillisecondsSinceEpoch(json['{{{baseName}}}'] as int, isUtc: true) + : DateTime.parse(json['{{{baseName}}}']), + {{/pattern}} + {{^pattern}} + : DateTime.parse(json['{{{baseName}}}']), + {{/pattern}} + {{/isDate}} + {{^isDateTime}} + {{^isDate}} + {{#complexType}} + {{#isArray}} + {{#items.isArray}} + {{{name}}}: json['{{{baseName}}}'] == null + ? null + : (json['{{{baseName}}}'] as List).map( + {{#items.complexType}} + {{items.complexType}}.listFromJson(json['{{{baseName}}}']) + {{/items.complexType}} + {{^items.complexType}} + (e) => e == null ? null : (e as List).cast<{{items.items.dataType}}>() + {{/items.complexType}} + ).toList(growable: false), + {{/items.isArray}} + {{^items.isArray}} + {{{name}}}: {{{complexType}}}.listFromJson(json['{{{baseName}}}']), + {{/items.isArray}} + {{/isArray}} + {{^isArray}} + {{#isMap}} + {{#items.isArray}} + {{{name}}}: json['{{{baseName}}}'] == null + ? null + {{#items.complexType}} + : {{items.complexType}}.mapListFromJson(json['{{{baseName}}}']), + {{/items.complexType}} + {{^items.complexType}} + : (json['{{{baseName}}}'] as Map).cast(), + {{/items.complexType}} + {{/items.isArray}} + {{^items.isArray}} + {{{name}}}: json['{{{baseName}}}'] == null + ? null + : {{{complexType}}}.mapFromJson(json['{{{baseName}}}']), + {{/items.isArray}} + {{/isMap}} + {{^isMap}} + {{{name}}}: {{{complexType}}}.fromJson(json['{{{baseName}}}']), + {{/isMap}} + {{/isArray}} + {{/complexType}} + {{^complexType}} + {{#isArray}} + {{#isEnum}} + {{{name}}}: {{{classname}}}{{{items.datatypeWithEnum}}}.listFromJson(json['{{{baseName}}}']), + {{/isEnum}} + {{^isEnum}} + {{{name}}}: json['{{{baseName}}}'] == null + ? null + : (json['{{{baseName}}}'] as List).cast<{{{items.datatype}}}>(), + {{/isEnum}} + {{/isArray}} + {{^isArray}} + {{#isMap}} + {{{name}}}: json['{{{baseName}}}'] == null ? + null : + (json['{{{baseName}}}'] as Map).cast(), + {{/isMap}} + {{^isMap}} + {{#isNumber}} + {{{name}}}: json['{{{baseName}}}'] == null ? + null : + json['{{{baseName}}}'].toDouble(), + {{/isNumber}} + {{^isNumber}} + {{^isEnum}} + {{{name}}}: json['{{{baseName}}}'], + {{/isEnum}} + {{#isEnum}} + {{{name}}}: {{{classname}}}{{{enumName}}}.fromJson(json['{{{baseName}}}']), + {{/isEnum}} + {{/isNumber}} + {{/isMap}} + {{/isArray}} + {{/complexType}} + {{/isDate}} + {{/isDateTime}} + {{/vars}} + ); + static List<{{{classname}}}> listFromJson(List json, {bool emptyIsNull, bool growable,}) => json == null || json.isEmpty ? true == emptyIsNull ? null : <{{{classname}}}>[] diff --git a/modules/openapi-generator/src/main/resources/dart2/enum.mustache b/modules/openapi-generator/src/main/resources/dart2/enum.mustache index 683e0d8528c..9d6dd3022fa 100644 --- a/modules/openapi-generator/src/main/resources/dart2/enum.mustache +++ b/modules/openapi-generator/src/main/resources/dart2/enum.mustache @@ -39,7 +39,7 @@ class {{{classname}}} { {{/allowableValues}} ]; - static {{{classname}}} fromJson({{{dataType}}} value) => + static {{{classname}}} fromJson(dynamic value) => {{{classname}}}TypeTransformer().decode(value); static List<{{{classname}}}> listFromJson(List json, {bool emptyIsNull, bool growable,}) => diff --git a/modules/openapi-generator/src/main/resources/dart2/enum_inline.mustache b/modules/openapi-generator/src/main/resources/dart2/enum_inline.mustache index 44ab77cceb5..f77a0a37103 100644 --- a/modules/openapi-generator/src/main/resources/dart2/enum_inline.mustache +++ b/modules/openapi-generator/src/main/resources/dart2/enum_inline.mustache @@ -39,7 +39,7 @@ class {{{classname}}}{{{enumName}}} { {{/allowableValues}} ]; - static {{{classname}}}{{{enumName}}} fromJson({{{dataType}}} value) => + static {{{classname}}}{{{enumName}}} fromJson(dynamic value) => {{{classname}}}{{{enumName}}}TypeTransformer().decode(value); static List<{{{classname}}}{{{enumName}}}> listFromJson(List json, {bool emptyIsNull, bool growable,}) => diff --git a/samples/client/petstore/dart2/petstore_client_lib/lib/api/pet_api.dart b/samples/client/petstore/dart2/petstore_client_lib/lib/api/pet_api.dart index c5ae7ae2bed..3d685f86bb6 100644 --- a/samples/client/petstore/dart2/petstore_client_lib/lib/api/pet_api.dart +++ b/samples/client/petstore/dart2/petstore_client_lib/lib/api/pet_api.dart @@ -37,7 +37,6 @@ class PetApi { final headerParams = {}; final formParams = {}; - final contentTypes = ['application/json', 'application/xml']; final nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null; final authNames = ['petstore_auth']; @@ -104,7 +103,9 @@ class PetApi { final headerParams = {}; final formParams = {}; - headerParams['api_key'] = apiKey; + if (apiKey != null) { + headerParams['api_key'] = parameterToString(apiKey); + } final contentTypes = []; final nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null; @@ -330,7 +331,6 @@ class PetApi { final headerParams = {}; final formParams = {}; - final contentTypes = []; final nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null; final authNames = ['api_key']; @@ -403,7 +403,6 @@ class PetApi { final headerParams = {}; final formParams = {}; - final contentTypes = ['application/json', 'application/xml']; final nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null; final authNames = ['petstore_auth']; @@ -474,7 +473,6 @@ class PetApi { final headerParams = {}; final formParams = {}; - final contentTypes = ['application/x-www-form-urlencoded']; final nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null; final authNames = ['petstore_auth']; @@ -565,7 +563,6 @@ class PetApi { final headerParams = {}; final formParams = {}; - final contentTypes = ['multipart/form-data']; final nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null; final authNames = ['petstore_auth']; diff --git a/samples/client/petstore/dart2/petstore_client_lib/lib/api/store_api.dart b/samples/client/petstore/dart2/petstore_client_lib/lib/api/store_api.dart index dca969b77ed..6b6004a16ce 100644 --- a/samples/client/petstore/dart2/petstore_client_lib/lib/api/store_api.dart +++ b/samples/client/petstore/dart2/petstore_client_lib/lib/api/store_api.dart @@ -40,7 +40,6 @@ class StoreApi { final headerParams = {}; final formParams = {}; - final contentTypes = []; final nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null; final authNames = []; @@ -98,7 +97,6 @@ class StoreApi { final headerParams = {}; final formParams = {}; - final contentTypes = []; final nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null; final authNames = ['api_key']; @@ -169,7 +167,6 @@ class StoreApi { final headerParams = {}; final formParams = {}; - final contentTypes = []; final nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null; final authNames = []; @@ -242,7 +239,6 @@ class StoreApi { final headerParams = {}; final formParams = {}; - final contentTypes = []; final nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null; final authNames = []; diff --git a/samples/client/petstore/dart2/petstore_client_lib/lib/api/user_api.dart b/samples/client/petstore/dart2/petstore_client_lib/lib/api/user_api.dart index 575660e3444..cfa14ee2e8b 100644 --- a/samples/client/petstore/dart2/petstore_client_lib/lib/api/user_api.dart +++ b/samples/client/petstore/dart2/petstore_client_lib/lib/api/user_api.dart @@ -39,7 +39,6 @@ class UserApi { final headerParams = {}; final formParams = {}; - final contentTypes = []; final nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null; final authNames = []; @@ -105,7 +104,6 @@ class UserApi { final headerParams = {}; final formParams = {}; - final contentTypes = []; final nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null; final authNames = []; @@ -169,7 +167,6 @@ class UserApi { final headerParams = {}; final formParams = {}; - final contentTypes = []; final nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null; final authNames = []; @@ -236,7 +233,6 @@ class UserApi { final headerParams = {}; final formParams = {}; - final contentTypes = []; final nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null; final authNames = []; @@ -303,7 +299,6 @@ class UserApi { final headerParams = {}; final formParams = {}; - final contentTypes = []; final nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null; final authNames = []; @@ -446,7 +441,6 @@ class UserApi { final headerParams = {}; final formParams = {}; - final contentTypes = []; final nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null; final authNames = []; @@ -514,7 +508,6 @@ class UserApi { final headerParams = {}; final formParams = {}; - final contentTypes = []; final nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null; final authNames = []; diff --git a/samples/client/petstore/dart2/petstore_client_lib/lib/model/api_response.dart b/samples/client/petstore/dart2/petstore_client_lib/lib/model/api_response.dart index 04e7edc1077..4724017e846 100644 --- a/samples/client/petstore/dart2/petstore_client_lib/lib/model/api_response.dart +++ b/samples/client/petstore/dart2/petstore_client_lib/lib/model/api_response.dart @@ -17,16 +17,6 @@ class ApiResponse { this.message, }); - /// Returns a new [ApiResponse] instance and optionally import its values from - /// [json] if it's non-null. - ApiResponse.fromJson(Map json) { - if (json != null) { - code = json['code']; - type = json['type']; - message = json['message']; - } - } - int code; @@ -44,9 +34,9 @@ class ApiResponse { @override int get hashCode => - code.hashCode + - type.hashCode + - message.hashCode; + (code == null ? 0 : code.hashCode) + + (type == null ? 0 : type.hashCode) + + (message == null ? 0 : message.hashCode); @override String toString() => 'ApiResponse[code=$code, type=$type, message=$message]'; @@ -65,6 +55,16 @@ class ApiResponse { return json; } + /// Returns a new [ApiResponse] instance and imports its values from + /// [json] if it's non-null, null if [json] is null. + static ApiResponse fromJson(Map json) => json == null + ? null + : ApiResponse( + code: json['code'], + type: json['type'], + message: json['message'], + ); + static List listFromJson(List json, {bool emptyIsNull, bool growable,}) => json == null || json.isEmpty ? true == emptyIsNull ? null : [] diff --git a/samples/client/petstore/dart2/petstore_client_lib/lib/model/category.dart b/samples/client/petstore/dart2/petstore_client_lib/lib/model/category.dart index 50043602747..0500aa5c93f 100644 --- a/samples/client/petstore/dart2/petstore_client_lib/lib/model/category.dart +++ b/samples/client/petstore/dart2/petstore_client_lib/lib/model/category.dart @@ -16,15 +16,6 @@ class Category { this.name, }); - /// Returns a new [Category] instance and optionally import its values from - /// [json] if it's non-null. - Category.fromJson(Map json) { - if (json != null) { - id = json['id']; - name = json['name']; - } - } - int id; @@ -38,8 +29,8 @@ class Category { @override int get hashCode => - id.hashCode + - name.hashCode; + (id == null ? 0 : id.hashCode) + + (name == null ? 0 : name.hashCode); @override String toString() => 'Category[id=$id, name=$name]'; @@ -55,6 +46,15 @@ class Category { return json; } + /// Returns a new [Category] instance and imports its values from + /// [json] if it's non-null, null if [json] is null. + static Category fromJson(Map json) => json == null + ? null + : Category( + id: json['id'], + name: json['name'], + ); + static List listFromJson(List json, {bool emptyIsNull, bool growable,}) => json == null || json.isEmpty ? true == emptyIsNull ? null : [] diff --git a/samples/client/petstore/dart2/petstore_client_lib/lib/model/order.dart b/samples/client/petstore/dart2/petstore_client_lib/lib/model/order.dart index 9de203f1fec..67b1b43c7d5 100644 --- a/samples/client/petstore/dart2/petstore_client_lib/lib/model/order.dart +++ b/samples/client/petstore/dart2/petstore_client_lib/lib/model/order.dart @@ -20,21 +20,6 @@ class Order { this.complete = false, }); - /// Returns a new [Order] instance and optionally import its values from - /// [json] if it's non-null. - Order.fromJson(Map json) { - if (json != null) { - id = json['id']; - petId = json['petId']; - quantity = json['quantity']; - shipDate = json['shipDate'] == null - ? null - : DateTime.parse(json['shipDate']); - status = OrderStatusEnum.fromJson(json['status']); - complete = json['complete']; - } - } - int id; @@ -64,12 +49,12 @@ class Order { @override int get hashCode => - id.hashCode + - petId.hashCode + - quantity.hashCode + - shipDate.hashCode + - status.hashCode + - complete.hashCode; + (id == null ? 0 : id.hashCode) + + (petId == null ? 0 : petId.hashCode) + + (quantity == null ? 0 : quantity.hashCode) + + (shipDate == null ? 0 : shipDate.hashCode) + + (status == null ? 0 : status.hashCode) + + (complete == null ? 0 : complete.hashCode); @override String toString() => 'Order[id=$id, petId=$petId, quantity=$quantity, shipDate=$shipDate, status=$status, complete=$complete]'; @@ -97,6 +82,21 @@ class Order { return json; } + /// Returns a new [Order] instance and imports its values from + /// [json] if it's non-null, null if [json] is null. + static Order fromJson(Map json) => json == null + ? null + : Order( + id: json['id'], + petId: json['petId'], + quantity: json['quantity'], + shipDate: json['shipDate'] == null + ? null + : DateTime.parse(json['shipDate']), + status: OrderStatusEnum.fromJson(json['status']), + complete: json['complete'], + ); + static List listFromJson(List json, {bool emptyIsNull, bool growable,}) => json == null || json.isEmpty ? true == emptyIsNull ? null : [] @@ -154,7 +154,7 @@ class OrderStatusEnum { delivered_, ]; - static OrderStatusEnum fromJson(String value) => + static OrderStatusEnum fromJson(dynamic value) => OrderStatusEnumTypeTransformer().decode(value); static List listFromJson(List json, {bool emptyIsNull, bool growable,}) => diff --git a/samples/client/petstore/dart2/petstore_client_lib/lib/model/pet.dart b/samples/client/petstore/dart2/petstore_client_lib/lib/model/pet.dart index cd77997466e..668b567ec4e 100644 --- a/samples/client/petstore/dart2/petstore_client_lib/lib/model/pet.dart +++ b/samples/client/petstore/dart2/petstore_client_lib/lib/model/pet.dart @@ -20,21 +20,6 @@ class Pet { this.status, }); - /// Returns a new [Pet] instance and optionally import its values from - /// [json] if it's non-null. - Pet.fromJson(Map json) { - if (json != null) { - id = json['id']; - category = Category.fromJson(json['category']); - name = json['name']; - photoUrls = json['photoUrls'] == null - ? null - : (json['photoUrls'] as List).cast(); - tags = Tag.listFromJson(json['tags']); - status = PetStatusEnum.fromJson(json['status']); - } - } - int id; @@ -64,12 +49,12 @@ class Pet { @override int get hashCode => - id.hashCode + - category.hashCode + - name.hashCode + - photoUrls.hashCode + - tags.hashCode + - status.hashCode; + (id == null ? 0 : id.hashCode) + + (category == null ? 0 : category.hashCode) + + (name == null ? 0 : name.hashCode) + + (photoUrls == null ? 0 : photoUrls.hashCode) + + (tags == null ? 0 : tags.hashCode) + + (status == null ? 0 : status.hashCode); @override String toString() => 'Pet[id=$id, category=$category, name=$name, photoUrls=$photoUrls, tags=$tags, status=$status]'; @@ -97,6 +82,21 @@ class Pet { return json; } + /// Returns a new [Pet] instance and imports its values from + /// [json] if it's non-null, null if [json] is null. + static Pet fromJson(Map json) => json == null + ? null + : Pet( + id: json['id'], + category: Category.fromJson(json['category']), + name: json['name'], + photoUrls: json['photoUrls'] == null + ? null + : (json['photoUrls'] as List).cast(), + tags: Tag.listFromJson(json['tags']), + status: PetStatusEnum.fromJson(json['status']), + ); + static List listFromJson(List json, {bool emptyIsNull, bool growable,}) => json == null || json.isEmpty ? true == emptyIsNull ? null : [] @@ -154,7 +154,7 @@ class PetStatusEnum { sold_, ]; - static PetStatusEnum fromJson(String value) => + static PetStatusEnum fromJson(dynamic value) => PetStatusEnumTypeTransformer().decode(value); static List listFromJson(List json, {bool emptyIsNull, bool growable,}) => diff --git a/samples/client/petstore/dart2/petstore_client_lib/lib/model/tag.dart b/samples/client/petstore/dart2/petstore_client_lib/lib/model/tag.dart index 9533f955d44..dd24d1e0cd6 100644 --- a/samples/client/petstore/dart2/petstore_client_lib/lib/model/tag.dart +++ b/samples/client/petstore/dart2/petstore_client_lib/lib/model/tag.dart @@ -16,15 +16,6 @@ class Tag { this.name, }); - /// Returns a new [Tag] instance and optionally import its values from - /// [json] if it's non-null. - Tag.fromJson(Map json) { - if (json != null) { - id = json['id']; - name = json['name']; - } - } - int id; @@ -38,8 +29,8 @@ class Tag { @override int get hashCode => - id.hashCode + - name.hashCode; + (id == null ? 0 : id.hashCode) + + (name == null ? 0 : name.hashCode); @override String toString() => 'Tag[id=$id, name=$name]'; @@ -55,6 +46,15 @@ class Tag { return json; } + /// Returns a new [Tag] instance and imports its values from + /// [json] if it's non-null, null if [json] is null. + static Tag fromJson(Map json) => json == null + ? null + : Tag( + id: json['id'], + name: json['name'], + ); + static List listFromJson(List json, {bool emptyIsNull, bool growable,}) => json == null || json.isEmpty ? true == emptyIsNull ? null : [] diff --git a/samples/client/petstore/dart2/petstore_client_lib/lib/model/user.dart b/samples/client/petstore/dart2/petstore_client_lib/lib/model/user.dart index 8c629089396..3d21b5822c4 100644 --- a/samples/client/petstore/dart2/petstore_client_lib/lib/model/user.dart +++ b/samples/client/petstore/dart2/petstore_client_lib/lib/model/user.dart @@ -22,21 +22,6 @@ class User { this.userStatus, }); - /// Returns a new [User] instance and optionally import its values from - /// [json] if it's non-null. - User.fromJson(Map json) { - if (json != null) { - id = json['id']; - username = json['username']; - firstName = json['firstName']; - lastName = json['lastName']; - email = json['email']; - password = json['password']; - phone = json['phone']; - userStatus = json['userStatus']; - } - } - int id; @@ -74,14 +59,14 @@ class User { @override int get hashCode => - id.hashCode + - username.hashCode + - firstName.hashCode + - lastName.hashCode + - email.hashCode + - password.hashCode + - phone.hashCode + - userStatus.hashCode; + (id == null ? 0 : id.hashCode) + + (username == null ? 0 : username.hashCode) + + (firstName == null ? 0 : firstName.hashCode) + + (lastName == null ? 0 : lastName.hashCode) + + (email == null ? 0 : email.hashCode) + + (password == null ? 0 : password.hashCode) + + (phone == null ? 0 : phone.hashCode) + + (userStatus == null ? 0 : userStatus.hashCode); @override String toString() => 'User[id=$id, username=$username, firstName=$firstName, lastName=$lastName, email=$email, password=$password, phone=$phone, userStatus=$userStatus]'; @@ -115,6 +100,21 @@ class User { return json; } + /// Returns a new [User] instance and imports its values from + /// [json] if it's non-null, null if [json] is null. + static User fromJson(Map json) => json == null + ? null + : User( + id: json['id'], + username: json['username'], + firstName: json['firstName'], + lastName: json['lastName'], + email: json['email'], + password: json['password'], + phone: json['phone'], + userStatus: json['userStatus'], + ); + static List listFromJson(List json, {bool emptyIsNull, bool growable,}) => json == null || json.isEmpty ? true == emptyIsNull ? null : []