diff --git a/modules/openapi-generator/src/main/resources/dart2/dart_constructor.mustache b/modules/openapi-generator/src/main/resources/dart2/dart_constructor.mustache index dc5dfec5f2a7..97675f9152c8 100644 --- a/modules/openapi-generator/src/main/resources/dart2/dart_constructor.mustache +++ b/modules/openapi-generator/src/main/resources/dart2/dart_constructor.mustache @@ -5,6 +5,6 @@ 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}}{{{.}}}{{#isEnum}}{{^isContainer}}){{/isContainer}}{{/isEnum}}{{/defaultValue}}, + {{#required}}{{^defaultValue}}required {{/defaultValue}}{{/required}}this.{{{name}}}{{#defaultValue}} = {{#isEnum}}{{^isContainer}}{{^isNumeric}}const {{{enumName}}}._({{/isNumeric}}{{/isContainer}}{{/isEnum}}{{{.}}}{{#isEnum}}{{^isContainer}}{{^isNumeric}}){{/isNumeric}}{{/isContainer}}{{/isEnum}}{{/defaultValue}}, {{/vars}} }); diff --git a/modules/openapi-generator/src/main/resources/dart2/serialization/native/native_class.mustache b/modules/openapi-generator/src/main/resources/dart2/serialization/native/native_class.mustache index 1d406ea46318..a47fccf7682a 100644 --- a/modules/openapi-generator/src/main/resources/dart2/serialization/native/native_class.mustache +++ b/modules/openapi-generator/src/main/resources/dart2/serialization/native/native_class.mustache @@ -109,7 +109,6 @@ class {{{classname}}} { /// Returns a new [{{{classname}}}] instance and imports its values from /// [value] if it's a [Map], null otherwise. - // ignore: prefer_constructors_over_static_methods static {{{classname}}}? fromJson(dynamic value) { if (value is Map) { final json = value.cast(); @@ -219,8 +218,7 @@ class {{{classname}}} { {{^isEnum}} {{{name}}}: mapValueOfType<{{{datatypeWithEnum}}}>(json, r'{{{baseName}}}'){{#required}}{{^isNullable}}!{{/isNullable}}{{/required}}{{^required}}{{#defaultValue}} ?? {{{.}}}{{/defaultValue}}{{/required}}, {{/isEnum}} - {{#isEnum}} - {{{name}}}: {{{enumName}}}.fromJson(json[r'{{{baseName}}}']){{#required}}{{^isNullable}}!{{/isNullable}}{{/required}}{{^required}}{{#defaultValue}} ?? {{{.}}}{{/defaultValue}}{{/required}}, + {{#isEnum}}{{{name}}}: {{{enumName}}}.fromJson(json[r'{{{baseName}}}']){{#required}}{{^isNullable}}!{{/isNullable}}{{/required}}{{^required}}{{#defaultValue}} ?? {{#isEnum}}{{^isContainer}}{{^isNumeric}}const {{{enumName}}}._({{/isNumeric}}{{/isContainer}}{{/isEnum}}{{{.}}}{{#isEnum}}{{^isContainer}}{{^isNumeric}}){{/isNumeric}}{{/isContainer}}{{/isEnum}}{{/defaultValue}}{{/required}}, {{/isEnum}} {{/isNumber}} {{/isMap}} diff --git a/modules/openapi-generator/src/main/resources/dart2/serialization/native/native_enum.mustache b/modules/openapi-generator/src/main/resources/dart2/serialization/native/native_enum.mustache index 84217b702b9e..482241875791 100644 --- a/modules/openapi-generator/src/main/resources/dart2/serialization/native/native_enum.mustache +++ b/modules/openapi-generator/src/main/resources/dart2/serialization/native/native_enum.mustache @@ -40,6 +40,13 @@ class {{{classname}}} { } return result.toList(growable: growable); } + + + @override + bool operator ==(Object other) => identical(this, other) || other is {{{classname}}} && other.value == value; + + @override + int get hashCode => value.hashCode; } /// Transformation class that can [encode] an instance of [{{{classname}}}] to {{{dataType}}}, diff --git a/modules/openapi-generator/src/main/resources/dart2/serialization/native/native_enum_inline.mustache b/modules/openapi-generator/src/main/resources/dart2/serialization/native/native_enum_inline.mustache index 1fe4428dcb31..aca3d5454717 100644 --- a/modules/openapi-generator/src/main/resources/dart2/serialization/native/native_enum_inline.mustache +++ b/modules/openapi-generator/src/main/resources/dart2/serialization/native/native_enum_inline.mustache @@ -40,6 +40,12 @@ class {{{enumName}}} { } return result.toList(growable: growable); } + + @override + bool operator ==(Object other) => identical(this, other) || other is {{{enumName}}} && other.value == value; + + @override + int get hashCode => value.hashCode; } /// Transformation class that can [encode] an instance of [{{{enumName}}}] to {{{dataType}}}, diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/model/order.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/model/order.dart index 75f8dbee2240..60ca8b13e9b0 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/model/order.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/model/order.dart @@ -134,6 +134,7 @@ class Order { petId: mapValueOfType(json, r'petId'), quantity: mapValueOfType(json, r'quantity'), shipDate: mapDateTime(json, r'shipDate', r''), + status: OrderStatusEnum.fromJson(json[r'status']), complete: mapValueOfType(json, r'complete') ?? false, ); @@ -224,6 +225,12 @@ class OrderStatusEnum { } return result.toList(growable: growable); } + + @override + bool operator ==(Object other) => identical(this, other) || other is OrderStatusEnum && other.value == value; + + @override + int get hashCode => value.hashCode; } /// Transformation class that can [encode] an instance of [OrderStatusEnum] to String, diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/model/pet.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/model/pet.dart index 8c17a4010ddf..6734ebc9dd0f 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/model/pet.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/model/pet.dart @@ -117,6 +117,7 @@ class Pet { ? (json[r'photoUrls'] as Iterable).cast().toList(growable: false) : const [], tags: Tag.listFromJson(json[r'tags']), + status: PetStatusEnum.fromJson(json[r'status']), ); } @@ -208,6 +209,12 @@ class PetStatusEnum { } return result.toList(growable: growable); } + + @override + bool operator ==(Object other) => identical(this, other) || other is PetStatusEnum && other.value == value; + + @override + int get hashCode => value.hashCode; } /// Transformation class that can [encode] an instance of [PetStatusEnum] to String, diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/child_with_nullable.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/child_with_nullable.dart index 7ade7785fc73..0c5e9a41f572 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/child_with_nullable.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/child_with_nullable.dart @@ -85,6 +85,7 @@ class ChildWithNullable { }()); return ChildWithNullable( + type: ChildWithNullableTypeEnum.fromJson(json[r'type']), nullableProperty: mapValueOfType(json, r'nullableProperty'), otherProperty: mapValueOfType(json, r'otherProperty'), @@ -172,6 +173,12 @@ class ChildWithNullableTypeEnum { } return result.toList(growable: growable); } + + @override + bool operator ==(Object other) => identical(this, other) || other is ChildWithNullableTypeEnum && other.value == value; + + @override + int get hashCode => value.hashCode; } /// Transformation class that can [encode] an instance of [ChildWithNullableTypeEnum] to String, diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/enum_arrays.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/enum_arrays.dart index 467ff1aaaf78..71966a58a809 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/enum_arrays.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/enum_arrays.dart @@ -65,6 +65,7 @@ class EnumArrays { }()); return EnumArrays( + justSymbol: EnumArraysJustSymbolEnum.fromJson(json[r'just_symbol']), arrayEnum: EnumArraysArrayEnumEnum.listFromJson(json[r'array_enum']), ); @@ -153,6 +154,12 @@ class EnumArraysJustSymbolEnum { } return result.toList(growable: growable); } + + @override + bool operator ==(Object other) => identical(this, other) || other is EnumArraysJustSymbolEnum && other.value == value; + + @override + int get hashCode => value.hashCode; } /// Transformation class that can [encode] an instance of [EnumArraysJustSymbolEnum] to String, @@ -227,6 +234,12 @@ class EnumArraysArrayEnumEnum { } return result.toList(growable: growable); } + + @override + bool operator ==(Object other) => identical(this, other) || other is EnumArraysArrayEnumEnum && other.value == value; + + @override + int get hashCode => value.hashCode; } /// Transformation class that can [encode] an instance of [EnumArraysArrayEnumEnum] to String, diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/enum_class.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/enum_class.dart index a8a811e6d924..a71a97ceaeef 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/enum_class.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/enum_class.dart @@ -48,6 +48,13 @@ class EnumClass { } return result.toList(growable: growable); } + + + @override + bool operator ==(Object other) => identical(this, other) || other is EnumClass && other.value == value; + + @override + int get hashCode => value.hashCode; } /// Transformation class that can [encode] an instance of [EnumClass] to String, diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/enum_test.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/enum_test.dart index d3e405221f9b..9675243e9759 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/enum_test.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/enum_test.dart @@ -143,9 +143,13 @@ class EnumTest { }()); return EnumTest( + enumString: EnumTestEnumStringEnum.fromJson(json[r'enum_string']), + enumStringRequired: EnumTestEnumStringRequiredEnum.fromJson(json[r'enum_string_required'])!, + enumInteger: EnumTestEnumIntegerEnum.fromJson(json[r'enum_integer']), + enumNumber: EnumTestEnumNumberEnum.fromJson(json[r'enum_number']), outerEnum: OuterEnum.fromJson(json[r'outerEnum']), outerEnumInteger: OuterEnumInteger.fromJson(json[r'outerEnumInteger']), @@ -240,6 +244,12 @@ class EnumTestEnumStringEnum { } return result.toList(growable: growable); } + + @override + bool operator ==(Object other) => identical(this, other) || other is EnumTestEnumStringEnum && other.value == value; + + @override + int get hashCode => value.hashCode; } /// Transformation class that can [encode] an instance of [EnumTestEnumStringEnum] to String, @@ -317,6 +327,12 @@ class EnumTestEnumStringRequiredEnum { } return result.toList(growable: growable); } + + @override + bool operator ==(Object other) => identical(this, other) || other is EnumTestEnumStringRequiredEnum && other.value == value; + + @override + int get hashCode => value.hashCode; } /// Transformation class that can [encode] an instance of [EnumTestEnumStringRequiredEnum] to String, @@ -392,6 +408,12 @@ class EnumTestEnumIntegerEnum { } return result.toList(growable: growable); } + + @override + bool operator ==(Object other) => identical(this, other) || other is EnumTestEnumIntegerEnum && other.value == value; + + @override + int get hashCode => value.hashCode; } /// Transformation class that can [encode] an instance of [EnumTestEnumIntegerEnum] to int, @@ -466,6 +488,12 @@ class EnumTestEnumNumberEnum { } return result.toList(growable: growable); } + + @override + bool operator ==(Object other) => identical(this, other) || other is EnumTestEnumNumberEnum && other.value == value; + + @override + int get hashCode => value.hashCode; } /// Transformation class that can [encode] an instance of [EnumTestEnumNumberEnum] to double, diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/map_test.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/map_test.dart index 487af40478b1..f01838b55e7e 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/map_test.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/map_test.dart @@ -163,6 +163,12 @@ class MapTestMapOfEnumStringEnum { } return result.toList(growable: growable); } + + @override + bool operator ==(Object other) => identical(this, other) || other is MapTestMapOfEnumStringEnum && other.value == value; + + @override + int get hashCode => value.hashCode; } /// Transformation class that can [encode] an instance of [MapTestMapOfEnumStringEnum] to String, diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/order.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/order.dart index 4871871516fe..c536dd599294 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/order.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/order.dart @@ -134,6 +134,7 @@ class Order { petId: mapValueOfType(json, r'petId'), quantity: mapValueOfType(json, r'quantity'), shipDate: mapDateTime(json, r'shipDate', r''), + status: OrderStatusEnum.fromJson(json[r'status']), complete: mapValueOfType(json, r'complete') ?? false, ); @@ -224,6 +225,12 @@ class OrderStatusEnum { } return result.toList(growable: growable); } + + @override + bool operator ==(Object other) => identical(this, other) || other is OrderStatusEnum && other.value == value; + + @override + int get hashCode => value.hashCode; } /// Transformation class that can [encode] an instance of [OrderStatusEnum] to String, diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/outer_enum.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/outer_enum.dart index 61e17c3bde96..59fb3d057c00 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/outer_enum.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/outer_enum.dart @@ -48,6 +48,13 @@ class OuterEnum { } return result.toList(growable: growable); } + + + @override + bool operator ==(Object other) => identical(this, other) || other is OuterEnum && other.value == value; + + @override + int get hashCode => value.hashCode; } /// Transformation class that can [encode] an instance of [OuterEnum] to String, diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/outer_enum_default_value.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/outer_enum_default_value.dart index cbbcc7597c61..76e6f17d86e8 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/outer_enum_default_value.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/outer_enum_default_value.dart @@ -48,6 +48,13 @@ class OuterEnumDefaultValue { } return result.toList(growable: growable); } + + + @override + bool operator ==(Object other) => identical(this, other) || other is OuterEnumDefaultValue && other.value == value; + + @override + int get hashCode => value.hashCode; } /// Transformation class that can [encode] an instance of [OuterEnumDefaultValue] to String, diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/outer_enum_integer.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/outer_enum_integer.dart index d9583ad84c67..c858196cdaa1 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/outer_enum_integer.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/outer_enum_integer.dart @@ -48,6 +48,13 @@ class OuterEnumInteger { } return result.toList(growable: growable); } + + + @override + bool operator ==(Object other) => identical(this, other) || other is OuterEnumInteger && other.value == value; + + @override + int get hashCode => value.hashCode; } /// Transformation class that can [encode] an instance of [OuterEnumInteger] to int, diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/outer_enum_integer_default_value.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/outer_enum_integer_default_value.dart index a62d9b7ecd95..006031009ce9 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/outer_enum_integer_default_value.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/outer_enum_integer_default_value.dart @@ -48,6 +48,13 @@ class OuterEnumIntegerDefaultValue { } return result.toList(growable: growable); } + + + @override + bool operator ==(Object other) => identical(this, other) || other is OuterEnumIntegerDefaultValue && other.value == value; + + @override + int get hashCode => value.hashCode; } /// Transformation class that can [encode] an instance of [OuterEnumIntegerDefaultValue] to int, diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/parent_with_nullable.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/parent_with_nullable.dart index 24f4ee75874e..1bf3e778bb1c 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/parent_with_nullable.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/parent_with_nullable.dart @@ -69,6 +69,7 @@ class ParentWithNullable { }()); return ParentWithNullable( + type: ParentWithNullableTypeEnum.fromJson(json[r'type']), nullableProperty: mapValueOfType(json, r'nullableProperty'), ); @@ -155,6 +156,12 @@ class ParentWithNullableTypeEnum { } return result.toList(growable: growable); } + + @override + bool operator ==(Object other) => identical(this, other) || other is ParentWithNullableTypeEnum && other.value == value; + + @override + int get hashCode => value.hashCode; } /// Transformation class that can [encode] an instance of [ParentWithNullableTypeEnum] to String, diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/pet.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/pet.dart index 5c1cf7243841..c4eb914c7674 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/pet.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/pet.dart @@ -117,6 +117,7 @@ class Pet { ? (json[r'photoUrls'] as Iterable).cast().toSet() : const {}, tags: Tag.listFromJson(json[r'tags']), + status: PetStatusEnum.fromJson(json[r'status']), ); } @@ -208,6 +209,12 @@ class PetStatusEnum { } return result.toList(growable: growable); } + + @override + bool operator ==(Object other) => identical(this, other) || other is PetStatusEnum && other.value == value; + + @override + int get hashCode => value.hashCode; } /// Transformation class that can [encode] an instance of [PetStatusEnum] to String, diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/single_ref_type.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/single_ref_type.dart index f750f7ff7de0..9c691e89cb7a 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/single_ref_type.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/single_ref_type.dart @@ -46,6 +46,13 @@ class SingleRefType { } return result.toList(growable: growable); } + + + @override + bool operator ==(Object other) => identical(this, other) || other is SingleRefType && other.value == value; + + @override + int get hashCode => value.hashCode; } /// Transformation class that can [encode] an instance of [SingleRefType] to String,