forked from loafle/openapi-generator-original
[DART2] A couple of bug fixes (#7969)
* Fixed a couple of problems with current implementation. 1) When encoding non-String header values, the client will forwar to parameterToString() for encoding. 2) fromJson() now accepts a dynamic value since the type transformer accepts a dynamic value. * Updated Pet Store files. * Proper spacing between blocks. * Adjust spacing. * Make fromJson() as a static function, thus not instantiating a new object if JSON is null. * Adjust doc for fromJson() function.
This commit is contained in:
parent
08c8296e33
commit
91e64f47fc
@ -69,19 +69,31 @@ class {{{classname}}} {
|
||||
final queryParams = <QueryParam>[];
|
||||
final headerParams = <String, String>{};
|
||||
final formParams = <String, String>{};
|
||||
{{#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 = <String>[{{#consumes}}'{{{mediaType}}}'{{^-last}}, {{/-last}}{{/consumes}}];
|
||||
final nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null;
|
||||
|
@ -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<String, dynamic> 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<String, List>();
|
||||
{{/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<String, {{{items.datatype}}}>();
|
||||
{{/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<String, dynamic> toJson() {
|
||||
final json = <String, dynamic>{};
|
||||
{{#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<String, dynamic> 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<String, List>(),
|
||||
{{/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<String, {{{items.datatype}}}>(),
|
||||
{{/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<dynamic> json, {bool emptyIsNull, bool growable,}) =>
|
||||
json == null || json.isEmpty
|
||||
? true == emptyIsNull ? null : <{{{classname}}}>[]
|
||||
|
@ -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<dynamic> json, {bool emptyIsNull, bool growable,}) =>
|
||||
|
@ -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<dynamic> json, {bool emptyIsNull, bool growable,}) =>
|
||||
|
@ -37,7 +37,6 @@ class PetApi {
|
||||
final headerParams = <String, String>{};
|
||||
final formParams = <String, String>{};
|
||||
|
||||
|
||||
final contentTypes = <String>['application/json', 'application/xml'];
|
||||
final nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null;
|
||||
final authNames = <String>['petstore_auth'];
|
||||
@ -104,7 +103,9 @@ class PetApi {
|
||||
final headerParams = <String, String>{};
|
||||
final formParams = <String, String>{};
|
||||
|
||||
headerParams['api_key'] = apiKey;
|
||||
if (apiKey != null) {
|
||||
headerParams['api_key'] = parameterToString(apiKey);
|
||||
}
|
||||
|
||||
final contentTypes = <String>[];
|
||||
final nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null;
|
||||
@ -330,7 +331,6 @@ class PetApi {
|
||||
final headerParams = <String, String>{};
|
||||
final formParams = <String, String>{};
|
||||
|
||||
|
||||
final contentTypes = <String>[];
|
||||
final nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null;
|
||||
final authNames = <String>['api_key'];
|
||||
@ -403,7 +403,6 @@ class PetApi {
|
||||
final headerParams = <String, String>{};
|
||||
final formParams = <String, String>{};
|
||||
|
||||
|
||||
final contentTypes = <String>['application/json', 'application/xml'];
|
||||
final nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null;
|
||||
final authNames = <String>['petstore_auth'];
|
||||
@ -474,7 +473,6 @@ class PetApi {
|
||||
final headerParams = <String, String>{};
|
||||
final formParams = <String, String>{};
|
||||
|
||||
|
||||
final contentTypes = <String>['application/x-www-form-urlencoded'];
|
||||
final nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null;
|
||||
final authNames = <String>['petstore_auth'];
|
||||
@ -565,7 +563,6 @@ class PetApi {
|
||||
final headerParams = <String, String>{};
|
||||
final formParams = <String, String>{};
|
||||
|
||||
|
||||
final contentTypes = <String>['multipart/form-data'];
|
||||
final nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null;
|
||||
final authNames = <String>['petstore_auth'];
|
||||
|
@ -40,7 +40,6 @@ class StoreApi {
|
||||
final headerParams = <String, String>{};
|
||||
final formParams = <String, String>{};
|
||||
|
||||
|
||||
final contentTypes = <String>[];
|
||||
final nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null;
|
||||
final authNames = <String>[];
|
||||
@ -98,7 +97,6 @@ class StoreApi {
|
||||
final headerParams = <String, String>{};
|
||||
final formParams = <String, String>{};
|
||||
|
||||
|
||||
final contentTypes = <String>[];
|
||||
final nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null;
|
||||
final authNames = <String>['api_key'];
|
||||
@ -169,7 +167,6 @@ class StoreApi {
|
||||
final headerParams = <String, String>{};
|
||||
final formParams = <String, String>{};
|
||||
|
||||
|
||||
final contentTypes = <String>[];
|
||||
final nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null;
|
||||
final authNames = <String>[];
|
||||
@ -242,7 +239,6 @@ class StoreApi {
|
||||
final headerParams = <String, String>{};
|
||||
final formParams = <String, String>{};
|
||||
|
||||
|
||||
final contentTypes = <String>[];
|
||||
final nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null;
|
||||
final authNames = <String>[];
|
||||
|
@ -39,7 +39,6 @@ class UserApi {
|
||||
final headerParams = <String, String>{};
|
||||
final formParams = <String, String>{};
|
||||
|
||||
|
||||
final contentTypes = <String>[];
|
||||
final nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null;
|
||||
final authNames = <String>[];
|
||||
@ -105,7 +104,6 @@ class UserApi {
|
||||
final headerParams = <String, String>{};
|
||||
final formParams = <String, String>{};
|
||||
|
||||
|
||||
final contentTypes = <String>[];
|
||||
final nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null;
|
||||
final authNames = <String>[];
|
||||
@ -169,7 +167,6 @@ class UserApi {
|
||||
final headerParams = <String, String>{};
|
||||
final formParams = <String, String>{};
|
||||
|
||||
|
||||
final contentTypes = <String>[];
|
||||
final nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null;
|
||||
final authNames = <String>[];
|
||||
@ -236,7 +233,6 @@ class UserApi {
|
||||
final headerParams = <String, String>{};
|
||||
final formParams = <String, String>{};
|
||||
|
||||
|
||||
final contentTypes = <String>[];
|
||||
final nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null;
|
||||
final authNames = <String>[];
|
||||
@ -303,7 +299,6 @@ class UserApi {
|
||||
final headerParams = <String, String>{};
|
||||
final formParams = <String, String>{};
|
||||
|
||||
|
||||
final contentTypes = <String>[];
|
||||
final nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null;
|
||||
final authNames = <String>[];
|
||||
@ -446,7 +441,6 @@ class UserApi {
|
||||
final headerParams = <String, String>{};
|
||||
final formParams = <String, String>{};
|
||||
|
||||
|
||||
final contentTypes = <String>[];
|
||||
final nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null;
|
||||
final authNames = <String>[];
|
||||
@ -514,7 +508,6 @@ class UserApi {
|
||||
final headerParams = <String, String>{};
|
||||
final formParams = <String, String>{};
|
||||
|
||||
|
||||
final contentTypes = <String>[];
|
||||
final nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null;
|
||||
final authNames = <String>[];
|
||||
|
@ -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<String, dynamic> 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<String, dynamic> json) => json == null
|
||||
? null
|
||||
: ApiResponse(
|
||||
code: json['code'],
|
||||
type: json['type'],
|
||||
message: json['message'],
|
||||
);
|
||||
|
||||
static List<ApiResponse> listFromJson(List<dynamic> json, {bool emptyIsNull, bool growable,}) =>
|
||||
json == null || json.isEmpty
|
||||
? true == emptyIsNull ? null : <ApiResponse>[]
|
||||
|
@ -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<String, dynamic> 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<String, dynamic> json) => json == null
|
||||
? null
|
||||
: Category(
|
||||
id: json['id'],
|
||||
name: json['name'],
|
||||
);
|
||||
|
||||
static List<Category> listFromJson(List<dynamic> json, {bool emptyIsNull, bool growable,}) =>
|
||||
json == null || json.isEmpty
|
||||
? true == emptyIsNull ? null : <Category>[]
|
||||
|
@ -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<String, dynamic> 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<String, dynamic> 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<Order> listFromJson(List<dynamic> json, {bool emptyIsNull, bool growable,}) =>
|
||||
json == null || json.isEmpty
|
||||
? true == emptyIsNull ? null : <Order>[]
|
||||
@ -154,7 +154,7 @@ class OrderStatusEnum {
|
||||
delivered_,
|
||||
];
|
||||
|
||||
static OrderStatusEnum fromJson(String value) =>
|
||||
static OrderStatusEnum fromJson(dynamic value) =>
|
||||
OrderStatusEnumTypeTransformer().decode(value);
|
||||
|
||||
static List<OrderStatusEnum> listFromJson(List<dynamic> json, {bool emptyIsNull, bool growable,}) =>
|
||||
|
@ -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<String, dynamic> 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<String>();
|
||||
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<String, dynamic> 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<String>(),
|
||||
tags: Tag.listFromJson(json['tags']),
|
||||
status: PetStatusEnum.fromJson(json['status']),
|
||||
);
|
||||
|
||||
static List<Pet> listFromJson(List<dynamic> json, {bool emptyIsNull, bool growable,}) =>
|
||||
json == null || json.isEmpty
|
||||
? true == emptyIsNull ? null : <Pet>[]
|
||||
@ -154,7 +154,7 @@ class PetStatusEnum {
|
||||
sold_,
|
||||
];
|
||||
|
||||
static PetStatusEnum fromJson(String value) =>
|
||||
static PetStatusEnum fromJson(dynamic value) =>
|
||||
PetStatusEnumTypeTransformer().decode(value);
|
||||
|
||||
static List<PetStatusEnum> listFromJson(List<dynamic> json, {bool emptyIsNull, bool growable,}) =>
|
||||
|
@ -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<String, dynamic> 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<String, dynamic> json) => json == null
|
||||
? null
|
||||
: Tag(
|
||||
id: json['id'],
|
||||
name: json['name'],
|
||||
);
|
||||
|
||||
static List<Tag> listFromJson(List<dynamic> json, {bool emptyIsNull, bool growable,}) =>
|
||||
json == null || json.isEmpty
|
||||
? true == emptyIsNull ? null : <Tag>[]
|
||||
|
@ -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<String, dynamic> 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<String, dynamic> 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<User> listFromJson(List<dynamic> json, {bool emptyIsNull, bool growable,}) =>
|
||||
json == null || json.isEmpty
|
||||
? true == emptyIsNull ? null : <User>[]
|
||||
|
Loading…
x
Reference in New Issue
Block a user