diff --git a/modules/openapi-generator/src/main/resources/dart2/api.mustache b/modules/openapi-generator/src/main/resources/dart2/api.mustache
index bbdc28b44624419d69fafac65871c532ba20ca3f..6b01841dacdf47c3b594135241db3162ec3b9922 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 = <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;
diff --git a/modules/openapi-generator/src/main/resources/dart2/class.mustache b/modules/openapi-generator/src/main/resources/dart2/class.mustache
index cfd45cf3a2e0c70342bea2cc7cc2c1273872c3fa..ce7d8a4a9c9b0102517b0895889ab509a6d5009b 100644
--- a/modules/openapi-generator/src/main/resources/dart2/class.mustache
+++ b/modules/openapi-generator/src/main/resources/dart2/class.mustache
@@ -6,33 +6,105 @@ 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}}
+  {{#description}}/// {{{description}}}{{/description}}
+  {{^isEnum}}
+  {{{dataType}}} {{{name}}};
+  {{/isEnum}}
+  {{#isEnum}}
+    {{#isContainer}}
+      {{#isArray}}
+  List<{{{classname}}}{{{enumName}}}> {{{name}}};
+      {{/isArray}}
+      {{#isMap}}
+  Map<String, dynamic> {{{name}}};
+      {{/isMap}}
+    {{/isContainer}}
+    {{^isContainer}}
+      {{#allowableValues}}
+  {{#min}} // range from {{{min}}} to {{{max}}}{{/min}}{{{classname}}}{{{enumName}}} {{{name}}}{{#required}} = {{{classname}}}{{{enumName}}}._({{{defaultValue}}}){{/required}}{{^required}}{{/required}};
+      {{/allowableValues}}
+    {{/isContainer}}
+  {{/isEnum}}
+
+  {{/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}}
+    ({{{name}}} == null ? 0 : {{{name}}}.hashCode){{^-last}} +{{/-last}}{{#-last}};{{/-last}}
+  {{/vars}}
+
+  @override
+  String toString() => '{{{classname}}}[{{#vars}}{{{name}}}=${{{name}}}{{^-last}}, {{/-last}}{{/vars}}]';
+
+  Map<String, dynamic> toJson() {
+    final json = <String, dynamic>{};
+  {{#vars}}
+    if ({{{name}}} != null) {
+    {{#isDateTime}}
+      {{#pattern}}
+      json['{{{baseName}}}'] = _dateEpochMarker == '{{{pattern}}}'
+        ? {{{name}}}.millisecondsSinceEpoch
+        : {{{name}}}.toUtc().toIso8601String();
+      {{/pattern}}
+      {{^pattern}}
+      json['{{{baseName}}}'] = {{{name}}}.toUtc().toIso8601String();
+      {{/pattern}}
+    {{/isDateTime}}
+    {{#isDate}}
+      {{#pattern}}
+      json['{{{baseName}}}'] = _dateEpochMarker == '{{{pattern}}}'
+        ? {{{name}}}.millisecondsSinceEpoch
+        : _dateFormatter.format({{{name}}}.toUtc());
+      {{/pattern}}
+      {{^pattern}}
+      json['{{{baseName}}}'] = _dateFormatter.format({{{name}}}.toUtc());
+      {{/pattern}}
+    {{/isDate}}
+    {{^isDateTime}}
+      {{^isDate}}
+      json['{{{baseName}}}'] = {{{name}}};
+      {{/isDate}}
+    {{/isDateTime}}
+    }
+  {{/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
+        {{{name}}}: json['{{{baseName}}}'] == null
+          ? null
     {{#pattern}}
-        : _dateEpochMarker == '{{{pattern}}}'
-          ? DateTime.fromMillisecondsSinceEpoch(json['{{{baseName}}}'] as int, isUtc: true)
-          : DateTime.parse(json['{{{baseName}}}']);
+          : _dateEpochMarker == '{{{pattern}}}'
+            ? DateTime.fromMillisecondsSinceEpoch(json['{{{baseName}}}'] as int, isUtc: true)
+            : DateTime.parse(json['{{{baseName}}}']),
 	{{/pattern}}
     {{^pattern}}
-        : DateTime.parse(json['{{{baseName}}}']);
+          : DateTime.parse(json['{{{baseName}}}']),
 	{{/pattern}}
   {{/isDateTime}}
   {{#isDate}}
-      {{{name}}} = json['{{{baseName}}}'] == null
-        ? null
+        {{{name}}}: json['{{{baseName}}}'] == null
+          ? null
     {{#pattern}}
-        : _dateEpochMarker == '{{{pattern}}}'
-          ? DateTime.fromMillisecondsSinceEpoch(json['{{{baseName}}}'] as int, isUtc: true)
-          : DateTime.parse(json['{{{baseName}}}']);
+          : _dateEpochMarker == '{{{pattern}}}'
+            ? DateTime.fromMillisecondsSinceEpoch(json['{{{baseName}}}'] as int, isUtc: true)
+            : DateTime.parse(json['{{{baseName}}}']),
 	{{/pattern}}
     {{^pattern}}
-        : DateTime.parse(json['{{{baseName}}}']);
+          : DateTime.parse(json['{{{baseName}}}']),
 	{{/pattern}}
   {{/isDate}}
   {{^isDateTime}}
@@ -40,73 +112,73 @@ class {{{classname}}} {
     {{#complexType}}
       {{#isArray}}
         {{#items.isArray}}
-      {{{name}}} = json['{{{baseName}}}'] == null
-        ? null
-        : (json['{{{baseName}}}'] as List).map(
+        {{{name}}}: json['{{{baseName}}}'] == null
+          ? null
+          : (json['{{{baseName}}}'] as List).map(
       {{#items.complexType}}
-            {{items.complexType}}.listFromJson(json['{{{baseName}}}'])
+              {{items.complexType}}.listFromJson(json['{{{baseName}}}'])
       {{/items.complexType}}
       {{^items.complexType}}
-            (e) => e == null ? null : (e as List).cast<{{items.items.dataType}}>()
+              (e) => e == null ? null : (e as List).cast<{{items.items.dataType}}>()
       {{/items.complexType}}
-          ).toList(growable: false);
+            ).toList(growable: false),
         {{/items.isArray}}
         {{^items.isArray}}
-      {{{name}}} = {{{complexType}}}.listFromJson(json['{{{baseName}}}']);
+        {{{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}}
+        {{{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}}}']);
+        {{{name}}}: json['{{{baseName}}}'] == null
+          ? null
+          : {{{complexType}}}.mapFromJson(json['{{{baseName}}}']),
           {{/items.isArray}}
         {{/isMap}}
         {{^isMap}}
-      {{{name}}} = {{{complexType}}}.fromJson(json['{{{baseName}}}']);
+        {{{name}}}: {{{complexType}}}.fromJson(json['{{{baseName}}}']),
         {{/isMap}}
       {{/isArray}}
     {{/complexType}}
     {{^complexType}}
       {{#isArray}}
         {{#isEnum}}
-      {{{name}}} = {{{classname}}}{{{items.datatypeWithEnum}}}.listFromJson(json['{{{baseName}}}']);
+        {{{name}}}: {{{classname}}}{{{items.datatypeWithEnum}}}.listFromJson(json['{{{baseName}}}']),
         {{/isEnum}}
         {{^isEnum}}
-      {{{name}}} = json['{{{baseName}}}'] == null
-        ? null
-        : (json['{{{baseName}}}'] as List).cast<{{{items.datatype}}}>();
+        {{{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}}}>();
+        {{{name}}}: json['{{{baseName}}}'] == null ?
+          null :
+          (json['{{{baseName}}}'] as Map).cast<String, {{{items.datatype}}}>(),
         {{/isMap}}
         {{^isMap}}
           {{#isNumber}}
-      {{{name}}} = json['{{{baseName}}}'] == null ?
-        null :
-        json['{{{baseName}}}'].toDouble();
+        {{{name}}}: json['{{{baseName}}}'] == null ?
+          null :
+          json['{{{baseName}}}'].toDouble(),
           {{/isNumber}}
           {{^isNumber}}
     {{^isEnum}}
-      {{{name}}} = json['{{{baseName}}}'];
+        {{{name}}}: json['{{{baseName}}}'],
     {{/isEnum}}
     {{#isEnum}}
-      {{{name}}} = {{{classname}}}{{{enumName}}}.fromJson(json['{{{baseName}}}']);
+        {{{name}}}: {{{classname}}}{{{enumName}}}.fromJson(json['{{{baseName}}}']),
     {{/isEnum}}
           {{/isNumber}}
         {{/isMap}}
@@ -115,79 +187,7 @@ class {{{classname}}} {
   {{/isDate}}
   {{/isDateTime}}
   {{/vars}}
-    }
-  }
-
-  {{#vars}}
-  {{#description}}/// {{{description}}}{{/description}}
-  {{^isEnum}}
-  {{{dataType}}} {{{name}}};
-  {{/isEnum}}
-  {{#isEnum}}
-    {{#isContainer}}
-      {{#isArray}}
-  List<{{{classname}}}{{{enumName}}}> {{{name}}};
-      {{/isArray}}
-      {{#isMap}}
-  Map<String, dynamic> {{{name}}};
-      {{/isMap}}
-    {{/isContainer}}
-    {{^isContainer}}
-      {{#allowableValues}}
-  {{#min}} // range from {{{min}}} to {{{max}}}{{/min}}{{{classname}}}{{{enumName}}} {{{name}}}{{#required}} = {{{classname}}}{{{enumName}}}._({{{defaultValue}}}){{/required}}{{^required}}{{/required}};
-      {{/allowableValues}}
-    {{/isContainer}}
-  {{/isEnum}}
-
-  {{/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}}}?.hashCode ?? 0){{/isNullable}}{{^isNullable}}{{{name}}}.hashCode{{/isNullable}}{{^-last}} +{{/-last}}{{#-last}};{{/-last}}
-  {{/vars}}
-
-  @override
-  String toString() => '{{{classname}}}[{{#vars}}{{{name}}}=${{{name}}}{{^-last}}, {{/-last}}{{/vars}}]';
-
-  Map<String, dynamic> toJson() {
-    final json = <String, dynamic>{};
-{{#vars}}
-    if ({{{name}}} != null) {
-  {{#isDateTime}}
-    {{#pattern}}
-      json['{{{baseName}}}'] = _dateEpochMarker == '{{{pattern}}}'
-        ? {{{name}}}.millisecondsSinceEpoch
-        : {{{name}}}.toUtc().toIso8601String();
-    {{/pattern}}
-    {{^pattern}}
-      json['{{{baseName}}}'] = {{{name}}}.toUtc().toIso8601String();
-    {{/pattern}}
-  {{/isDateTime}}
-  {{#isDate}}
-    {{#pattern}}
-      json['{{{baseName}}}'] = _dateEpochMarker == '{{{pattern}}}'
-        ? {{{name}}}.millisecondsSinceEpoch
-        : _dateFormatter.format({{{name}}}.toUtc());
-    {{/pattern}}
-    {{^pattern}}
-      json['{{{baseName}}}'] = _dateFormatter.format({{{name}}}.toUtc());
-    {{/pattern}}
-  {{/isDate}}
-  {{^isDateTime}}
-    {{^isDate}}
-      json['{{{baseName}}}'] = {{{name}}};
-    {{/isDate}}
-  {{/isDateTime}}
-    }
-{{/vars}}
-    return json;
-  }
+    );
 
   static List<{{{classname}}}> listFromJson(List<dynamic> json, {bool emptyIsNull, bool growable,}) =>
     json == null || json.isEmpty
diff --git a/modules/openapi-generator/src/main/resources/dart2/enum.mustache b/modules/openapi-generator/src/main/resources/dart2/enum.mustache
index 683e0d8528cc02f9834ed852347c1bba8036d707..9d6dd3022fa5f8b14ef8a27b177714a522831d73 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<dynamic> 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 44ab77cceb5ce1ae3a0ab90959dec0ae0401f814..f77a0a3710379771e1e51a04a47cc913abe0c35f 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<dynamic> 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 c5ae7ae2bed20d541c56fb6dc11658dc5bfa0277..3d685f86bb61c79ea3c44df0687ec92f5ee61bc9 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 = <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'];
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 dca969b77edddeb9c63db6119eadeefbf1bda7f3..6b6004a16ce0524837bae9cd0fab3ef78c4c8110 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 = <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>[];
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 575660e344465a7c7d280fdc274d26826495b1d8..cfa14ee2e8b7bb8c7ba3e5ab3b5f71c3f68fa879 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 = <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>[];
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 04e7edc10770c3b43ca200008875c6373e619c76..4724017e846769318500baeb84773e55ff4f740f 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<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>[]
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 50043602747230a6ff0439db4da7f75c1eda1271..0500aa5c93f133bde7b53aa2e51e1fedb75194e0 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<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>[]
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 9de203f1feca41f68ecd571a04ed3a5a6f849b2e..67b1b43c7d55379fc89870d3aa67607d1d7ffb12 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<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,}) =>
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 cd77997466e717a35baed390c0c40d5691b52c4b..668b567ec4ec3204cbc7e9389fd6e870dfd1f4c8 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<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,}) =>
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 9533f955d44bbb57b50b511ee67ff802e2d73c7a..dd24d1e0cd63b0e42927b0ba71a2e6e6cbeaba3a 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<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>[]
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 8c62908939638096d4c5faeaf7653e6e43e9c082..3d21b5822c43020ade6789093abafa3ef536c0d6 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<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>[]