diff --git a/modules/openapi-generator/src/main/resources/dart/libraries/dio/serialization/built_value/class_members.mustache b/modules/openapi-generator/src/main/resources/dart/libraries/dio/serialization/built_value/class_members.mustache index d3d55fb723f1..50b7f98ba60d 100644 --- a/modules/openapi-generator/src/main/resources/dart/libraries/dio/serialization/built_value/class_members.mustache +++ b/modules/openapi-generator/src/main/resources/dart/libraries/dio/serialization/built_value/class_members.mustache @@ -32,7 +32,7 @@ @BuiltValueHook(initializeBuilder: true) static void _defaults({{{classname}}}Builder b) => b{{#vendorExtensions.x-parent-discriminator}}..{{propertyName}}=b.discriminatorValue{{/vendorExtensions.x-parent-discriminator}}{{#vendorExtensions.x-self-and-ancestor-only-props}}{{#defaultValue}} - ..{{{name}}} = {{#isEnum}}{{^isContainer}}{{{defaultValue}}}{{/isContainer}}{{/isEnum}}{{^isEnum}}{{{defaultValue}}}{{/isEnum}}{{/defaultValue}}{{/vendorExtensions.x-self-and-ancestor-only-props}}; + ..{{{name}}} = {{#isEnum}}{{^isContainer}}{{#enumName}}{{enumName}}.valueOf({{{defaultValue}}}){{/enumName}}{{^enumName}}{{{defaultValue}}}{{/enumName}}{{/isContainer}}{{/isEnum}}{{^isEnum}}{{{defaultValue}}}{{/isEnum}}{{/defaultValue}}{{/vendorExtensions.x-self-and-ancestor-only-props}}; {{/vendorExtensions.x-is-parent}} @BuiltValueSerializer(custom: true) static Serializer<{{classname}}> get serializer => _${{classname}}Serializer(); \ No newline at end of file diff --git a/modules/openapi-generator/src/test/resources/3_0/dart/petstore-with-fake-endpoints-models-for-testing.yaml b/modules/openapi-generator/src/test/resources/3_0/dart/petstore-with-fake-endpoints-models-for-testing.yaml index 074a9aa468e7..a5700aa697f2 100644 --- a/modules/openapi-generator/src/test/resources/3_0/dart/petstore-with-fake-endpoints-models-for-testing.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/dart/petstore-with-fake-endpoints-models-for-testing.yaml @@ -2079,22 +2079,29 @@ components: TestEnum: type: string enum: - - "" - - "1" - - "2" + - '' + - 'value_one' + - 'value_two' title: TestEnum - TestItem: + ObjectWithEnum: type: object - required: - - test properties: - test: - type: integer - title: test - testEmum: - $ref: '#/components/schemas/TestEnum' - default: "" - title: TestItem + attribute: + allOf: + - $ref: '#/components/schemas/TestEnum' + default: '' + title: ObjectWithEnum + ObjectWithInlineEnumDefaultValue: + type: object + properties: + attribute: + description: 'Object one attribute enum with default value' + type: 'string' + enum: [ + 'value_one', + 'value_two' + ] + default: 'value_one' ObjectWithInlineEnum: type: object properties: diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/.openapi-generator/FILES b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/.openapi-generator/FILES index d8e3e213a8a9..a3483714374f 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/.openapi-generator/FILES @@ -43,7 +43,9 @@ doc/NumberOnly.md doc/ObjectThatReferencesObjectsWithDuplicateInlineEnums.md doc/ObjectWithDeprecatedFields.md doc/ObjectWithDuplicateInlineEnum.md +doc/ObjectWithEnum.md doc/ObjectWithInlineEnum.md +doc/ObjectWithInlineEnumDefaultValue.md doc/Order.md doc/OuterComposite.md doc/OuterEnum.md @@ -61,7 +63,6 @@ doc/StoreApi.md doc/Tag.md doc/TestEnum.md doc/TestInlineFreeformAdditionalPropertiesRequest.md -doc/TestItem.md doc/User.md doc/UserApi.md lib/openapi.dart @@ -116,7 +117,9 @@ lib/src/model/number_only.dart lib/src/model/object_that_references_objects_with_duplicate_inline_enums.dart lib/src/model/object_with_deprecated_fields.dart lib/src/model/object_with_duplicate_inline_enum.dart +lib/src/model/object_with_enum.dart lib/src/model/object_with_inline_enum.dart +lib/src/model/object_with_inline_enum_default_value.dart lib/src/model/order.dart lib/src/model/outer_composite.dart lib/src/model/outer_enum.dart @@ -132,6 +135,5 @@ lib/src/model/special_model_name.dart lib/src/model/tag.dart lib/src/model/test_enum.dart lib/src/model/test_inline_freeform_additional_properties_request.dart -lib/src/model/test_item.dart lib/src/model/user.dart pubspec.yaml diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/README.md b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/README.md index edc5bef4cb08..865f37dabdf7 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/README.md +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/README.md @@ -154,7 +154,9 @@ Class | Method | HTTP request | Description - [ObjectThatReferencesObjectsWithDuplicateInlineEnums](doc/ObjectThatReferencesObjectsWithDuplicateInlineEnums.md) - [ObjectWithDeprecatedFields](doc/ObjectWithDeprecatedFields.md) - [ObjectWithDuplicateInlineEnum](doc/ObjectWithDuplicateInlineEnum.md) + - [ObjectWithEnum](doc/ObjectWithEnum.md) - [ObjectWithInlineEnum](doc/ObjectWithInlineEnum.md) + - [ObjectWithInlineEnumDefaultValue](doc/ObjectWithInlineEnumDefaultValue.md) - [Order](doc/Order.md) - [OuterComposite](doc/OuterComposite.md) - [OuterEnum](doc/OuterEnum.md) @@ -170,7 +172,6 @@ Class | Method | HTTP request | Description - [Tag](doc/Tag.md) - [TestEnum](doc/TestEnum.md) - [TestInlineFreeformAdditionalPropertiesRequest](doc/TestInlineFreeformAdditionalPropertiesRequest.md) - - [TestItem](doc/TestItem.md) - [User](doc/User.md) diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/doc/TestItem.md b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/doc/ObjectWithEnum.md similarity index 74% rename from samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/doc/TestItem.md rename to samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/doc/ObjectWithEnum.md index 3988d0bc30d2..e77acb3063ee 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/doc/TestItem.md +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/doc/ObjectWithEnum.md @@ -1,4 +1,4 @@ -# openapi.model.TestItem +# openapi.model.ObjectWithEnum ## Load the model package ```dart @@ -8,8 +8,7 @@ import 'package:openapi/api.dart'; ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**test** | **int** | | -**testEmum** | [**TestEnum**](TestEnum.md) | | [optional] +**attribute** | [**TestEnum**](TestEnum.md) | | [optional] [default to TestEnum.empty] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/doc/ObjectWithInlineEnumDefaultValue.md b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/doc/ObjectWithInlineEnumDefaultValue.md new file mode 100644 index 000000000000..7a0552248119 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/doc/ObjectWithInlineEnumDefaultValue.md @@ -0,0 +1,15 @@ +# openapi.model.ObjectWithInlineEnumDefaultValue + +## Load the model package +```dart +import 'package:openapi/api.dart'; +``` + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**attribute** | **String** | Object one attribute enum with default value | [optional] [default to 'value_one'] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/openapi.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/openapi.dart index 02a5d6724df2..6f9f9c4e11ab 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/openapi.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/openapi.dart @@ -54,7 +54,9 @@ export 'package:openapi/src/model/number_only.dart'; export 'package:openapi/src/model/object_that_references_objects_with_duplicate_inline_enums.dart'; export 'package:openapi/src/model/object_with_deprecated_fields.dart'; export 'package:openapi/src/model/object_with_duplicate_inline_enum.dart'; +export 'package:openapi/src/model/object_with_enum.dart'; export 'package:openapi/src/model/object_with_inline_enum.dart'; +export 'package:openapi/src/model/object_with_inline_enum_default_value.dart'; export 'package:openapi/src/model/order.dart'; export 'package:openapi/src/model/outer_composite.dart'; export 'package:openapi/src/model/outer_enum.dart'; @@ -70,6 +72,5 @@ export 'package:openapi/src/model/special_model_name.dart'; export 'package:openapi/src/model/tag.dart'; export 'package:openapi/src/model/test_enum.dart'; export 'package:openapi/src/model/test_inline_freeform_additional_properties_request.dart'; -export 'package:openapi/src/model/test_item.dart'; export 'package:openapi/src/model/user.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/deserialize.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/deserialize.dart index a9abb804899d..ebb014d5076a 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/deserialize.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/deserialize.dart @@ -34,7 +34,9 @@ import 'package:openapi/src/model/number_only.dart'; import 'package:openapi/src/model/object_that_references_objects_with_duplicate_inline_enums.dart'; import 'package:openapi/src/model/object_with_deprecated_fields.dart'; import 'package:openapi/src/model/object_with_duplicate_inline_enum.dart'; +import 'package:openapi/src/model/object_with_enum.dart'; import 'package:openapi/src/model/object_with_inline_enum.dart'; +import 'package:openapi/src/model/object_with_inline_enum_default_value.dart'; import 'package:openapi/src/model/order.dart'; import 'package:openapi/src/model/outer_composite.dart'; import 'package:openapi/src/model/outer_object_with_enum_property.dart'; @@ -44,7 +46,6 @@ import 'package:openapi/src/model/read_only_first.dart'; import 'package:openapi/src/model/special_model_name.dart'; import 'package:openapi/src/model/tag.dart'; import 'package:openapi/src/model/test_inline_freeform_additional_properties_request.dart'; -import 'package:openapi/src/model/test_item.dart'; import 'package:openapi/src/model/user.dart'; final _regList = RegExp(r'^List<(.*)>$'); @@ -140,8 +141,12 @@ final _regMap = RegExp(r'^Map$'); return ObjectWithDeprecatedFields.fromJson(value as Map) as ReturnType; case 'ObjectWithDuplicateInlineEnum': return ObjectWithDuplicateInlineEnum.fromJson(value as Map) as ReturnType; + case 'ObjectWithEnum': + return ObjectWithEnum.fromJson(value as Map) as ReturnType; case 'ObjectWithInlineEnum': return ObjectWithInlineEnum.fromJson(value as Map) as ReturnType; + case 'ObjectWithInlineEnumDefaultValue': + return ObjectWithInlineEnumDefaultValue.fromJson(value as Map) as ReturnType; case 'Order': return Order.fromJson(value as Map) as ReturnType; case 'OuterComposite': @@ -178,8 +183,6 @@ final _regMap = RegExp(r'^Map$'); case 'TestInlineFreeformAdditionalPropertiesRequest': return TestInlineFreeformAdditionalPropertiesRequest.fromJson(value as Map) as ReturnType; - case 'TestItem': - return TestItem.fromJson(value as Map) as ReturnType; case 'User': return User.fromJson(value as Map) as ReturnType; default: diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/test_item.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/object_with_enum.dart similarity index 54% rename from samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/test_item.dart rename to samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/object_with_enum.dart index 5949d7b92460..7cbf5091e596 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/test_item.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/object_with_enum.dart @@ -7,7 +7,7 @@ import 'package:openapi/src/model/test_enum.dart'; import 'package:copy_with_extension/copy_with_extension.dart'; import 'package:json_annotation/json_annotation.dart'; -part 'test_item.g.dart'; +part 'object_with_enum.g.dart'; @CopyWith() @@ -17,55 +17,39 @@ part 'test_item.g.dart'; disallowUnrecognizedKeys: false, explicitToJson: true, ) -class TestItem { - /// Returns a new [TestItem] instance. - TestItem({ +class ObjectWithEnum { + /// Returns a new [ObjectWithEnum] instance. + ObjectWithEnum({ - required this.test, - - this.testEmum, + this.attribute = TestEnum.empty, }); @JsonKey( - - name: r'test', - required: true, - includeIfNull: false, - ) - - - final int test; - - - - @JsonKey( - - name: r'testEmum', + defaultValue: TestEnum.empty, + name: r'attribute', required: false, includeIfNull: false, unknownEnumValue: TestEnum.unknownDefaultOpenApi, ) - final TestEnum? testEmum; + final TestEnum? attribute; @override - bool operator ==(Object other) => identical(this, other) || other is TestItem && - other.test == test && - other.testEmum == testEmum; + bool operator ==(Object other) => identical(this, other) || other is ObjectWithEnum && + other.attribute == attribute; @override int get hashCode => - test.hashCode + - testEmum.hashCode; + attribute.hashCode; - factory TestItem.fromJson(Map json) => _$TestItemFromJson(json); + factory ObjectWithEnum.fromJson(Map json) => _$ObjectWithEnumFromJson(json); - Map toJson() => _$TestItemToJson(this); + Map toJson() => _$ObjectWithEnumToJson(this); @override String toString() { diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/object_with_inline_enum_default_value.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/object_with_inline_enum_default_value.dart new file mode 100644 index 000000000000..289025e07a44 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/object_with_inline_enum_default_value.dart @@ -0,0 +1,81 @@ +// +// AUTO-GENERATED FILE, DO NOT MODIFY! +// + +// ignore_for_file: unused_element +import 'package:copy_with_extension/copy_with_extension.dart'; +import 'package:json_annotation/json_annotation.dart'; + +part 'object_with_inline_enum_default_value.g.dart'; + + +@CopyWith() +@JsonSerializable( + checked: true, + createToJson: true, + disallowUnrecognizedKeys: false, + explicitToJson: true, +) +class ObjectWithInlineEnumDefaultValue { + /// Returns a new [ObjectWithInlineEnumDefaultValue] instance. + ObjectWithInlineEnumDefaultValue({ + + this.attribute = const ObjectWithInlineEnumDefaultValueAttributeEnum._('value_one'), + }); + + /// Object one attribute enum with default value + @JsonKey( + defaultValue: 'value_one', + name: r'attribute', + required: false, + includeIfNull: false, + unknownEnumValue: ObjectWithInlineEnumDefaultValueAttributeEnum.unknownDefaultOpenApi, + ) + + + final ObjectWithInlineEnumDefaultValueAttributeEnum? attribute; + + + + + + @override + bool operator ==(Object other) => identical(this, other) || other is ObjectWithInlineEnumDefaultValue && + other.attribute == attribute; + + @override + int get hashCode => + attribute.hashCode; + + factory ObjectWithInlineEnumDefaultValue.fromJson(Map json) => _$ObjectWithInlineEnumDefaultValueFromJson(json); + + Map toJson() => _$ObjectWithInlineEnumDefaultValueToJson(this); + + @override + String toString() { + return toJson().toString(); + } + +} + +/// Object one attribute enum with default value +enum ObjectWithInlineEnumDefaultValueAttributeEnum { + /// Object one attribute enum with default value +@JsonValue(r'value_one') +valueOne(r'value_one'), + /// Object one attribute enum with default value +@JsonValue(r'value_two') +valueTwo(r'value_two'), + /// Object one attribute enum with default value +@JsonValue(r'unknown_default_open_api') +unknownDefaultOpenApi(r'unknown_default_open_api'); + +const ObjectWithInlineEnumDefaultValueAttributeEnum(this.value); + +final String value; + +@override +String toString() => value; +} + + diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/test_enum.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/test_enum.dart index ac4d415ae610..29a25d1942f4 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/test_enum.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/test_enum.dart @@ -9,10 +9,10 @@ import 'package:json_annotation/json_annotation.dart'; enum TestEnum { @JsonValue(r'') empty(r''), - @JsonValue(r'1') - n1(r'1'), - @JsonValue(r'2') - n2(r'2'), + @JsonValue(r'value_one') + valueOne(r'value_one'), + @JsonValue(r'value_two') + valueTwo(r'value_two'), @JsonValue(r'unknown_default_open_api') unknownDefaultOpenApi(r'unknown_default_open_api'); diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/test/object_with_enum_test.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/test/object_with_enum_test.dart new file mode 100644 index 000000000000..1b560587dee1 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/test/object_with_enum_test.dart @@ -0,0 +1,16 @@ +import 'package:test/test.dart'; +import 'package:openapi/openapi.dart'; + +// tests for ObjectWithEnum +void main() { + final ObjectWithEnum? instance = /* ObjectWithEnum(...) */ null; + // TODO add properties to the entity + + group(ObjectWithEnum, () { + // TestEnum attribute (default value: TestEnum.empty) + test('to test the property `attribute`', () async { + // TODO + }); + + }); +} diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/test/object_with_inline_enum_default_value_test.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/test/object_with_inline_enum_default_value_test.dart new file mode 100644 index 000000000000..255e4c4b66b1 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/test/object_with_inline_enum_default_value_test.dart @@ -0,0 +1,17 @@ +import 'package:test/test.dart'; +import 'package:openapi/openapi.dart'; + +// tests for ObjectWithInlineEnumDefaultValue +void main() { + final ObjectWithInlineEnumDefaultValue? instance = /* ObjectWithInlineEnumDefaultValue(...) */ null; + // TODO add properties to the entity + + group(ObjectWithInlineEnumDefaultValue, () { + // Object one attribute enum with default value + // String attribute (default value: 'value_one') + test('to test the property `attribute`', () async { + // TODO + }); + + }); +} diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/test/test_item_test.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/test/test_item_test.dart deleted file mode 100644 index 079db4d50226..000000000000 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/test/test_item_test.dart +++ /dev/null @@ -1,21 +0,0 @@ -import 'package:test/test.dart'; -import 'package:openapi/openapi.dart'; - -// tests for TestItem -void main() { - final TestItem? instance = /* TestItem(...) */ null; - // TODO add properties to the entity - - group(TestItem, () { - // int test - test('to test the property `test`', () async { - // TODO - }); - - // TestEnum testEmum - test('to test the property `testEmum`', () async { - // TODO - }); - - }); -} diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/.openapi-generator/FILES b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/.openapi-generator/FILES index 56f51c65adca..c70cda02a13d 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/.openapi-generator/FILES @@ -42,7 +42,9 @@ doc/NumberOnly.md doc/ObjectThatReferencesObjectsWithDuplicateInlineEnums.md doc/ObjectWithDeprecatedFields.md doc/ObjectWithDuplicateInlineEnum.md +doc/ObjectWithEnum.md doc/ObjectWithInlineEnum.md +doc/ObjectWithInlineEnumDefaultValue.md doc/Order.md doc/OuterComposite.md doc/OuterEnum.md @@ -60,7 +62,6 @@ doc/StoreApi.md doc/Tag.md doc/TestEnum.md doc/TestInlineFreeformAdditionalPropertiesRequest.md -doc/TestItem.md doc/User.md doc/UserApi.md lib/openapi.dart @@ -117,7 +118,9 @@ lib/src/model/number_only.dart lib/src/model/object_that_references_objects_with_duplicate_inline_enums.dart lib/src/model/object_with_deprecated_fields.dart lib/src/model/object_with_duplicate_inline_enum.dart +lib/src/model/object_with_enum.dart lib/src/model/object_with_inline_enum.dart +lib/src/model/object_with_inline_enum_default_value.dart lib/src/model/order.dart lib/src/model/outer_composite.dart lib/src/model/outer_enum.dart @@ -133,7 +136,6 @@ lib/src/model/special_model_name.dart lib/src/model/tag.dart lib/src/model/test_enum.dart lib/src/model/test_inline_freeform_additional_properties_request.dart -lib/src/model/test_item.dart lib/src/model/user.dart lib/src/serializers.dart pubspec.yaml diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/README.md b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/README.md index 132b6bc6cf68..a15dff5f41c3 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/README.md +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/README.md @@ -153,7 +153,9 @@ Class | Method | HTTP request | Description - [ObjectThatReferencesObjectsWithDuplicateInlineEnums](doc/ObjectThatReferencesObjectsWithDuplicateInlineEnums.md) - [ObjectWithDeprecatedFields](doc/ObjectWithDeprecatedFields.md) - [ObjectWithDuplicateInlineEnum](doc/ObjectWithDuplicateInlineEnum.md) + - [ObjectWithEnum](doc/ObjectWithEnum.md) - [ObjectWithInlineEnum](doc/ObjectWithInlineEnum.md) + - [ObjectWithInlineEnumDefaultValue](doc/ObjectWithInlineEnumDefaultValue.md) - [Order](doc/Order.md) - [OuterComposite](doc/OuterComposite.md) - [OuterEnum](doc/OuterEnum.md) @@ -169,7 +171,6 @@ Class | Method | HTTP request | Description - [Tag](doc/Tag.md) - [TestEnum](doc/TestEnum.md) - [TestInlineFreeformAdditionalPropertiesRequest](doc/TestInlineFreeformAdditionalPropertiesRequest.md) - - [TestItem](doc/TestItem.md) - [User](doc/User.md) diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/doc/TestItem.md b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/doc/ObjectWithEnum.md similarity index 74% rename from samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/doc/TestItem.md rename to samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/doc/ObjectWithEnum.md index 3988d0bc30d2..e77acb3063ee 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/doc/TestItem.md +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/doc/ObjectWithEnum.md @@ -1,4 +1,4 @@ -# openapi.model.TestItem +# openapi.model.ObjectWithEnum ## Load the model package ```dart @@ -8,8 +8,7 @@ import 'package:openapi/api.dart'; ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**test** | **int** | | -**testEmum** | [**TestEnum**](TestEnum.md) | | [optional] +**attribute** | [**TestEnum**](TestEnum.md) | | [optional] [default to TestEnum.empty] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/doc/ObjectWithInlineEnumDefaultValue.md b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/doc/ObjectWithInlineEnumDefaultValue.md new file mode 100644 index 000000000000..7a0552248119 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/doc/ObjectWithInlineEnumDefaultValue.md @@ -0,0 +1,15 @@ +# openapi.model.ObjectWithInlineEnumDefaultValue + +## Load the model package +```dart +import 'package:openapi/api.dart'; +``` + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**attribute** | **String** | Object one attribute enum with default value | [optional] [default to 'value_one'] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/openapi.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/openapi.dart index b986f57dfcca..0eae8eb4a6df 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/openapi.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/openapi.dart @@ -55,7 +55,9 @@ export 'package:openapi/src/model/number_only.dart'; export 'package:openapi/src/model/object_that_references_objects_with_duplicate_inline_enums.dart'; export 'package:openapi/src/model/object_with_deprecated_fields.dart'; export 'package:openapi/src/model/object_with_duplicate_inline_enum.dart'; +export 'package:openapi/src/model/object_with_enum.dart'; export 'package:openapi/src/model/object_with_inline_enum.dart'; +export 'package:openapi/src/model/object_with_inline_enum_default_value.dart'; export 'package:openapi/src/model/order.dart'; export 'package:openapi/src/model/outer_composite.dart'; export 'package:openapi/src/model/outer_enum.dart'; @@ -71,6 +73,5 @@ export 'package:openapi/src/model/special_model_name.dart'; export 'package:openapi/src/model/tag.dart'; export 'package:openapi/src/model/test_enum.dart'; export 'package:openapi/src/model/test_inline_freeform_additional_properties_request.dart'; -export 'package:openapi/src/model/test_item.dart'; export 'package:openapi/src/model/user.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/test_item.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/object_with_enum.dart similarity index 60% rename from samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/test_item.dart rename to samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/object_with_enum.dart index dce8bef5a287..371a90703256 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/test_item.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/object_with_enum.dart @@ -7,54 +7,46 @@ import 'package:openapi/src/model/test_enum.dart'; import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; -part 'test_item.g.dart'; +part 'object_with_enum.g.dart'; -/// TestItem +/// ObjectWithEnum /// /// Properties: -/// * [test] -/// * [testEmum] +/// * [attribute] @BuiltValue() -abstract class TestItem implements Built { - @BuiltValueField(wireName: r'test') - int get test; +abstract class ObjectWithEnum implements Built { + @BuiltValueField(wireName: r'attribute') + TestEnum? get attribute; + // enum attributeEnum { , value_one, value_two, }; - @BuiltValueField(wireName: r'testEmum') - TestEnum? get testEmum; - // enum testEmumEnum { , 1, 2, }; + ObjectWithEnum._(); - TestItem._(); - - factory TestItem([void updates(TestItemBuilder b)]) = _$TestItem; + factory ObjectWithEnum([void updates(ObjectWithEnumBuilder b)]) = _$ObjectWithEnum; @BuiltValueHook(initializeBuilder: true) - static void _defaults(TestItemBuilder b) => b; + static void _defaults(ObjectWithEnumBuilder b) => b + ..attribute = TestEnum.empty; @BuiltValueSerializer(custom: true) - static Serializer get serializer => _$TestItemSerializer(); + static Serializer get serializer => _$ObjectWithEnumSerializer(); } -class _$TestItemSerializer implements PrimitiveSerializer { +class _$ObjectWithEnumSerializer implements PrimitiveSerializer { @override - final Iterable types = const [TestItem, _$TestItem]; + final Iterable types = const [ObjectWithEnum, _$ObjectWithEnum]; @override - final String wireName = r'TestItem'; + final String wireName = r'ObjectWithEnum'; Iterable _serializeProperties( Serializers serializers, - TestItem object, { + ObjectWithEnum object, { FullType specifiedType = FullType.unspecified, }) sync* { - yield r'test'; - yield serializers.serialize( - object.test, - specifiedType: const FullType(int), - ); - if (object.testEmum != null) { - yield r'testEmum'; + if (object.attribute != null) { + yield r'attribute'; yield serializers.serialize( - object.testEmum, + object.attribute, specifiedType: const FullType(TestEnum), ); } @@ -63,7 +55,7 @@ class _$TestItemSerializer implements PrimitiveSerializer { @override Object serialize( Serializers serializers, - TestItem object, { + ObjectWithEnum object, { FullType specifiedType = FullType.unspecified, }) { return _serializeProperties(serializers, object, specifiedType: specifiedType).toList(); @@ -74,26 +66,19 @@ class _$TestItemSerializer implements PrimitiveSerializer { Object serialized, { FullType specifiedType = FullType.unspecified, required List serializedList, - required TestItemBuilder result, + required ObjectWithEnumBuilder result, required List unhandled, }) { for (var i = 0; i < serializedList.length; i += 2) { final key = serializedList[i] as String; final value = serializedList[i + 1]; switch (key) { - case r'test': - final valueDes = serializers.deserialize( - value, - specifiedType: const FullType(int), - ) as int; - result.test = valueDes; - break; - case r'testEmum': + case r'attribute': final valueDes = serializers.deserialize( value, specifiedType: const FullType(TestEnum), ) as TestEnum; - result.testEmum = valueDes; + result.attribute = valueDes; break; default: unhandled.add(key); @@ -104,12 +89,12 @@ class _$TestItemSerializer implements PrimitiveSerializer { } @override - TestItem deserialize( + ObjectWithEnum deserialize( Serializers serializers, Object serialized, { FullType specifiedType = FullType.unspecified, }) { - final result = TestItemBuilder(); + final result = ObjectWithEnumBuilder(); final serializedList = (serialized as Iterable).toList(); final unhandled = []; _deserializeProperties( diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/object_with_inline_enum_default_value.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/object_with_inline_enum_default_value.dart new file mode 100644 index 000000000000..68fa4d6455dd --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/object_with_inline_enum_default_value.dart @@ -0,0 +1,132 @@ +// +// AUTO-GENERATED FILE, DO NOT MODIFY! +// + +// ignore_for_file: unused_element +import 'package:built_collection/built_collection.dart'; +import 'package:built_value/built_value.dart'; +import 'package:built_value/serializer.dart'; + +part 'object_with_inline_enum_default_value.g.dart'; + +/// ObjectWithInlineEnumDefaultValue +/// +/// Properties: +/// * [attribute] - Object one attribute enum with default value +@BuiltValue() +abstract class ObjectWithInlineEnumDefaultValue implements Built { + /// Object one attribute enum with default value + @BuiltValueField(wireName: r'attribute') + ObjectWithInlineEnumDefaultValueAttributeEnum? get attribute; + // enum attributeEnum { value_one, value_two, }; + + ObjectWithInlineEnumDefaultValue._(); + + factory ObjectWithInlineEnumDefaultValue([void updates(ObjectWithInlineEnumDefaultValueBuilder b)]) = _$ObjectWithInlineEnumDefaultValue; + + @BuiltValueHook(initializeBuilder: true) + static void _defaults(ObjectWithInlineEnumDefaultValueBuilder b) => b + ..attribute = ObjectWithInlineEnumDefaultValueAttributeEnum.valueOf('value_one'); + + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$ObjectWithInlineEnumDefaultValueSerializer(); +} + +class _$ObjectWithInlineEnumDefaultValueSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [ObjectWithInlineEnumDefaultValue, _$ObjectWithInlineEnumDefaultValue]; + + @override + final String wireName = r'ObjectWithInlineEnumDefaultValue'; + + Iterable _serializeProperties( + Serializers serializers, + ObjectWithInlineEnumDefaultValue object, { + FullType specifiedType = FullType.unspecified, + }) sync* { + if (object.attribute != null) { + yield r'attribute'; + yield serializers.serialize( + object.attribute, + specifiedType: const FullType(ObjectWithInlineEnumDefaultValueAttributeEnum), + ); + } + } + + @override + Object serialize( + Serializers serializers, + ObjectWithInlineEnumDefaultValue object, { + FullType specifiedType = FullType.unspecified, + }) { + return _serializeProperties(serializers, object, specifiedType: specifiedType).toList(); + } + + void _deserializeProperties( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + required List serializedList, + required ObjectWithInlineEnumDefaultValueBuilder result, + required List unhandled, + }) { + for (var i = 0; i < serializedList.length; i += 2) { + final key = serializedList[i] as String; + final value = serializedList[i + 1]; + switch (key) { + case r'attribute': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(ObjectWithInlineEnumDefaultValueAttributeEnum), + ) as ObjectWithInlineEnumDefaultValueAttributeEnum; + result.attribute = valueDes; + break; + default: + unhandled.add(key); + unhandled.add(value); + break; + } + } + } + + @override + ObjectWithInlineEnumDefaultValue deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) { + final result = ObjectWithInlineEnumDefaultValueBuilder(); + final serializedList = (serialized as Iterable).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } +} + +class ObjectWithInlineEnumDefaultValueAttributeEnum extends EnumClass { + + /// Object one attribute enum with default value + @BuiltValueEnumConst(wireName: r'value_one') + static const ObjectWithInlineEnumDefaultValueAttributeEnum valueOne = _$objectWithInlineEnumDefaultValueAttributeEnum_valueOne; + /// Object one attribute enum with default value + @BuiltValueEnumConst(wireName: r'value_two') + static const ObjectWithInlineEnumDefaultValueAttributeEnum valueTwo = _$objectWithInlineEnumDefaultValueAttributeEnum_valueTwo; + /// Object one attribute enum with default value + @BuiltValueEnumConst(wireName: r'unknown_default_open_api', fallback: true) + static const ObjectWithInlineEnumDefaultValueAttributeEnum unknownDefaultOpenApi = _$objectWithInlineEnumDefaultValueAttributeEnum_unknownDefaultOpenApi; + + static Serializer get serializer => _$objectWithInlineEnumDefaultValueAttributeEnumSerializer; + + const ObjectWithInlineEnumDefaultValueAttributeEnum._(String name): super(name); + + static BuiltSet get values => _$objectWithInlineEnumDefaultValueAttributeEnumValues; + static ObjectWithInlineEnumDefaultValueAttributeEnum valueOf(String name) => _$objectWithInlineEnumDefaultValueAttributeEnumValueOf(name); +} + diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/test_enum.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/test_enum.dart index 834ff705794c..83b125b97291 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/test_enum.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/test_enum.dart @@ -13,10 +13,10 @@ class TestEnum extends EnumClass { @BuiltValueEnumConst(wireName: r'') static const TestEnum empty = _$empty; - @BuiltValueEnumConst(wireName: r'1') - static const TestEnum n1 = _$n1; - @BuiltValueEnumConst(wireName: r'2') - static const TestEnum n2 = _$n2; + @BuiltValueEnumConst(wireName: r'value_one') + static const TestEnum valueOne = _$valueOne; + @BuiltValueEnumConst(wireName: r'value_two') + static const TestEnum valueTwo = _$valueTwo; @BuiltValueEnumConst(wireName: r'unknown_default_open_api', fallback: true) static const TestEnum unknownDefaultOpenApi = _$unknownDefaultOpenApi; diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/serializers.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/serializers.dart index 50e772e99ad4..9ebe575fcf79 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/serializers.dart +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/serializers.dart @@ -51,7 +51,9 @@ import 'package:openapi/src/model/number_only.dart'; import 'package:openapi/src/model/object_that_references_objects_with_duplicate_inline_enums.dart'; import 'package:openapi/src/model/object_with_deprecated_fields.dart'; import 'package:openapi/src/model/object_with_duplicate_inline_enum.dart'; +import 'package:openapi/src/model/object_with_enum.dart'; import 'package:openapi/src/model/object_with_inline_enum.dart'; +import 'package:openapi/src/model/object_with_inline_enum_default_value.dart'; import 'package:openapi/src/model/order.dart'; import 'package:openapi/src/model/outer_composite.dart'; import 'package:openapi/src/model/outer_enum.dart'; @@ -67,7 +69,6 @@ import 'package:openapi/src/model/special_model_name.dart'; import 'package:openapi/src/model/tag.dart'; import 'package:openapi/src/model/test_enum.dart'; import 'package:openapi/src/model/test_inline_freeform_additional_properties_request.dart'; -import 'package:openapi/src/model/test_item.dart'; import 'package:openapi/src/model/user.dart'; part 'serializers.g.dart'; @@ -110,7 +111,9 @@ part 'serializers.g.dart'; ObjectThatReferencesObjectsWithDuplicateInlineEnums, ObjectWithDeprecatedFields, ObjectWithDuplicateInlineEnum, + ObjectWithEnum, ObjectWithInlineEnum, + ObjectWithInlineEnumDefaultValue, Order, OuterComposite, OuterEnum, @@ -126,7 +129,6 @@ part 'serializers.g.dart'; Tag, TestEnum, TestInlineFreeformAdditionalPropertiesRequest, - TestItem, User, ]) Serializers serializers = (_$serializers.toBuilder() diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/test/object_with_enum_test.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/test/object_with_enum_test.dart new file mode 100644 index 000000000000..17b404c46f6f --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/test/object_with_enum_test.dart @@ -0,0 +1,16 @@ +import 'package:test/test.dart'; +import 'package:openapi/openapi.dart'; + +// tests for ObjectWithEnum +void main() { + final instance = ObjectWithEnumBuilder(); + // TODO add properties to the builder and call build() + + group(ObjectWithEnum, () { + // TestEnum attribute (default value: TestEnum.empty) + test('to test the property `attribute`', () async { + // TODO + }); + + }); +} diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/test/object_with_inline_enum_default_value_test.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/test/object_with_inline_enum_default_value_test.dart new file mode 100644 index 000000000000..63cc35c5cb30 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/test/object_with_inline_enum_default_value_test.dart @@ -0,0 +1,17 @@ +import 'package:test/test.dart'; +import 'package:openapi/openapi.dart'; + +// tests for ObjectWithInlineEnumDefaultValue +void main() { + final instance = ObjectWithInlineEnumDefaultValueBuilder(); + // TODO add properties to the builder and call build() + + group(ObjectWithInlineEnumDefaultValue, () { + // Object one attribute enum with default value + // String attribute (default value: 'value_one') + test('to test the property `attribute`', () async { + // TODO + }); + + }); +} diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/test/test_item_test.dart b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/test/test_item_test.dart deleted file mode 100644 index a0d333c69efa..000000000000 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/test/test_item_test.dart +++ /dev/null @@ -1,21 +0,0 @@ -import 'package:test/test.dart'; -import 'package:openapi/openapi.dart'; - -// tests for TestItem -void main() { - final instance = TestItemBuilder(); - // TODO add properties to the builder and call build() - - group(TestItem, () { - // int test - test('to test the property `test`', () async { - // TODO - }); - - // TestEnum testEmum - test('to test the property `testEmum`', () async { - // TODO - }); - - }); -} diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/.openapi-generator/FILES b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/.openapi-generator/FILES index 236d8a8ddb95..276e90e59908 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/.openapi-generator/FILES @@ -43,7 +43,9 @@ doc/NumberOnly.md doc/ObjectThatReferencesObjectsWithDuplicateInlineEnums.md doc/ObjectWithDeprecatedFields.md doc/ObjectWithDuplicateInlineEnum.md +doc/ObjectWithEnum.md doc/ObjectWithInlineEnum.md +doc/ObjectWithInlineEnumDefaultValue.md doc/Order.md doc/OuterComposite.md doc/OuterEnum.md @@ -61,7 +63,6 @@ doc/StoreApi.md doc/Tag.md doc/TestEnum.md doc/TestInlineFreeformAdditionalPropertiesRequest.md -doc/TestItem.md doc/User.md doc/UserApi.md git_push.sh @@ -118,7 +119,9 @@ lib/model/number_only.dart lib/model/object_that_references_objects_with_duplicate_inline_enums.dart lib/model/object_with_deprecated_fields.dart lib/model/object_with_duplicate_inline_enum.dart +lib/model/object_with_enum.dart lib/model/object_with_inline_enum.dart +lib/model/object_with_inline_enum_default_value.dart lib/model/order.dart lib/model/outer_composite.dart lib/model/outer_enum.dart @@ -134,6 +137,5 @@ lib/model/special_model_name.dart lib/model/tag.dart lib/model/test_enum.dart lib/model/test_inline_freeform_additional_properties_request.dart -lib/model/test_item.dart lib/model/user.dart pubspec.yaml diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/README.md b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/README.md index ad1c8a280f02..9d44f6caaef3 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/README.md +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/README.md @@ -147,7 +147,9 @@ Class | Method | HTTP request | Description - [ObjectThatReferencesObjectsWithDuplicateInlineEnums](doc//ObjectThatReferencesObjectsWithDuplicateInlineEnums.md) - [ObjectWithDeprecatedFields](doc//ObjectWithDeprecatedFields.md) - [ObjectWithDuplicateInlineEnum](doc//ObjectWithDuplicateInlineEnum.md) + - [ObjectWithEnum](doc//ObjectWithEnum.md) - [ObjectWithInlineEnum](doc//ObjectWithInlineEnum.md) + - [ObjectWithInlineEnumDefaultValue](doc//ObjectWithInlineEnumDefaultValue.md) - [Order](doc//Order.md) - [OuterComposite](doc//OuterComposite.md) - [OuterEnum](doc//OuterEnum.md) @@ -163,7 +165,6 @@ Class | Method | HTTP request | Description - [Tag](doc//Tag.md) - [TestEnum](doc//TestEnum.md) - [TestInlineFreeformAdditionalPropertiesRequest](doc//TestInlineFreeformAdditionalPropertiesRequest.md) - - [TestItem](doc//TestItem.md) - [User](doc//User.md) diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/doc/TestItem.md b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/doc/ObjectWithEnum.md similarity index 74% rename from samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/doc/TestItem.md rename to samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/doc/ObjectWithEnum.md index 3988d0bc30d2..e77acb3063ee 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/doc/TestItem.md +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/doc/ObjectWithEnum.md @@ -1,4 +1,4 @@ -# openapi.model.TestItem +# openapi.model.ObjectWithEnum ## Load the model package ```dart @@ -8,8 +8,7 @@ import 'package:openapi/api.dart'; ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**test** | **int** | | -**testEmum** | [**TestEnum**](TestEnum.md) | | [optional] +**attribute** | [**TestEnum**](TestEnum.md) | | [optional] [default to TestEnum.empty] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/doc/ObjectWithInlineEnumDefaultValue.md b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/doc/ObjectWithInlineEnumDefaultValue.md new file mode 100644 index 000000000000..7a0552248119 --- /dev/null +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/doc/ObjectWithInlineEnumDefaultValue.md @@ -0,0 +1,15 @@ +# openapi.model.ObjectWithInlineEnumDefaultValue + +## Load the model package +```dart +import 'package:openapi/api.dart'; +``` + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**attribute** | **String** | Object one attribute enum with default value | [optional] [default to 'value_one'] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api.dart index c9c83967e85c..4dd7698021e2 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api.dart @@ -73,7 +73,9 @@ part 'model/number_only.dart'; part 'model/object_that_references_objects_with_duplicate_inline_enums.dart'; part 'model/object_with_deprecated_fields.dart'; part 'model/object_with_duplicate_inline_enum.dart'; +part 'model/object_with_enum.dart'; part 'model/object_with_inline_enum.dart'; +part 'model/object_with_inline_enum_default_value.dart'; part 'model/order.dart'; part 'model/outer_composite.dart'; part 'model/outer_enum.dart'; @@ -89,7 +91,6 @@ part 'model/special_model_name.dart'; part 'model/tag.dart'; part 'model/test_enum.dart'; part 'model/test_inline_freeform_additional_properties_request.dart'; -part 'model/test_item.dart'; part 'model/user.dart'; diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api_client.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api_client.dart index 6d0c7f91e67f..7deaf18cebeb 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api_client.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api_client.dart @@ -256,8 +256,12 @@ class ApiClient { return ObjectWithDeprecatedFields.fromJson(value); case 'ObjectWithDuplicateInlineEnum': return ObjectWithDuplicateInlineEnum.fromJson(value); + case 'ObjectWithEnum': + return ObjectWithEnum.fromJson(value); case 'ObjectWithInlineEnum': return ObjectWithInlineEnum.fromJson(value); + case 'ObjectWithInlineEnumDefaultValue': + return ObjectWithInlineEnumDefaultValue.fromJson(value); case 'Order': return Order.fromJson(value); case 'OuterComposite': @@ -288,8 +292,6 @@ class ApiClient { return TestEnumTypeTransformer().decode(value); case 'TestInlineFreeformAdditionalPropertiesRequest': return TestInlineFreeformAdditionalPropertiesRequest.fromJson(value); - case 'TestItem': - return TestItem.fromJson(value); case 'User': return User.fromJson(value); default: diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/object_with_enum.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/object_with_enum.dart new file mode 100644 index 000000000000..8bdfa6bf4d3e --- /dev/null +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/object_with_enum.dart @@ -0,0 +1,108 @@ +// +// AUTO-GENERATED FILE, DO NOT MODIFY! +// +// @dart=2.18 + +// ignore_for_file: unused_element, unused_import +// ignore_for_file: always_put_required_named_parameters_first +// ignore_for_file: constant_identifier_names +// ignore_for_file: lines_longer_than_80_chars + +part of openapi.api; + +class ObjectWithEnum { + /// Returns a new [ObjectWithEnum] instance. + ObjectWithEnum({ + this.attribute = TestEnum.empty, + }); + + TestEnum attribute; + + @override + bool operator ==(Object other) => identical(this, other) || other is ObjectWithEnum && + other.attribute == attribute; + + @override + int get hashCode => + // ignore: unnecessary_parenthesis + (attribute.hashCode); + + @override + String toString() => 'ObjectWithEnum[attribute=$attribute]'; + + Map toJson() { + final json = {}; + json[r'attribute'] = this.attribute; + return json; + } + + /// Returns a new [ObjectWithEnum] instance and imports its values from + /// [value] if it's a [Map], null otherwise. + // ignore: prefer_constructors_over_static_methods + static ObjectWithEnum? fromJson(dynamic value) { + if (value is Map) { + final json = value.cast(); + + // Ensure that the map contains the required keys. + // Note 1: the values aren't checked for validity beyond being non-null. + // Note 2: this code is stripped in release mode! + assert(() { + requiredKeys.forEach((key) { + assert(json.containsKey(key), 'Required key "ObjectWithEnum[$key]" is missing from JSON.'); + assert(json[key] != null, 'Required key "ObjectWithEnum[$key]" has a null value in JSON.'); + }); + return true; + }()); + + return ObjectWithEnum( + attribute: TestEnum.fromJson(json[r'attribute']) ?? TestEnum.empty, + ); + } + return null; + } + + static List listFromJson(dynamic json, {bool growable = false,}) { + final result = []; + if (json is List && json.isNotEmpty) { + for (final row in json) { + final value = ObjectWithEnum.fromJson(row); + if (value != null) { + result.add(value); + } + } + } + return result.toList(growable: growable); + } + + static Map mapFromJson(dynamic json) { + final map = {}; + if (json is Map && json.isNotEmpty) { + json = json.cast(); // ignore: parameter_assignments + for (final entry in json.entries) { + final value = ObjectWithEnum.fromJson(entry.value); + if (value != null) { + map[entry.key] = value; + } + } + } + return map; + } + + // maps a json object with a list of ObjectWithEnum-objects as value to a dart map + static Map> mapListFromJson(dynamic json, {bool growable = false,}) { + final map = >{}; + if (json is Map && json.isNotEmpty) { + // ignore: parameter_assignments + json = json.cast(); + for (final entry in json.entries) { + map[entry.key] = ObjectWithEnum.listFromJson(entry.value, growable: growable,); + } + } + return map; + } + + /// The list of required keys that must be present in a JSON. + static const requiredKeys = { + }; +} + diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/object_with_inline_enum_default_value.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/object_with_inline_enum_default_value.dart new file mode 100644 index 000000000000..022d412c7988 --- /dev/null +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/object_with_inline_enum_default_value.dart @@ -0,0 +1,183 @@ +// +// AUTO-GENERATED FILE, DO NOT MODIFY! +// +// @dart=2.18 + +// ignore_for_file: unused_element, unused_import +// ignore_for_file: always_put_required_named_parameters_first +// ignore_for_file: constant_identifier_names +// ignore_for_file: lines_longer_than_80_chars + +part of openapi.api; + +class ObjectWithInlineEnumDefaultValue { + /// Returns a new [ObjectWithInlineEnumDefaultValue] instance. + ObjectWithInlineEnumDefaultValue({ + this.attribute = const ObjectWithInlineEnumDefaultValueAttributeEnum._('value_one'), + }); + + /// Object one attribute enum with default value + ObjectWithInlineEnumDefaultValueAttributeEnum attribute; + + @override + bool operator ==(Object other) => identical(this, other) || other is ObjectWithInlineEnumDefaultValue && + other.attribute == attribute; + + @override + int get hashCode => + // ignore: unnecessary_parenthesis + (attribute.hashCode); + + @override + String toString() => 'ObjectWithInlineEnumDefaultValue[attribute=$attribute]'; + + Map toJson() { + final json = {}; + json[r'attribute'] = this.attribute; + return json; + } + + /// Returns a new [ObjectWithInlineEnumDefaultValue] instance and imports its values from + /// [value] if it's a [Map], null otherwise. + // ignore: prefer_constructors_over_static_methods + static ObjectWithInlineEnumDefaultValue? fromJson(dynamic value) { + if (value is Map) { + final json = value.cast(); + + // Ensure that the map contains the required keys. + // Note 1: the values aren't checked for validity beyond being non-null. + // Note 2: this code is stripped in release mode! + assert(() { + requiredKeys.forEach((key) { + assert(json.containsKey(key), 'Required key "ObjectWithInlineEnumDefaultValue[$key]" is missing from JSON.'); + assert(json[key] != null, 'Required key "ObjectWithInlineEnumDefaultValue[$key]" has a null value in JSON.'); + }); + return true; + }()); + + return ObjectWithInlineEnumDefaultValue( + attribute: ObjectWithInlineEnumDefaultValueAttributeEnum.fromJson(json[r'attribute']) ?? 'value_one', + ); + } + return null; + } + + static List listFromJson(dynamic json, {bool growable = false,}) { + final result = []; + if (json is List && json.isNotEmpty) { + for (final row in json) { + final value = ObjectWithInlineEnumDefaultValue.fromJson(row); + if (value != null) { + result.add(value); + } + } + } + return result.toList(growable: growable); + } + + static Map mapFromJson(dynamic json) { + final map = {}; + if (json is Map && json.isNotEmpty) { + json = json.cast(); // ignore: parameter_assignments + for (final entry in json.entries) { + final value = ObjectWithInlineEnumDefaultValue.fromJson(entry.value); + if (value != null) { + map[entry.key] = value; + } + } + } + return map; + } + + // maps a json object with a list of ObjectWithInlineEnumDefaultValue-objects as value to a dart map + static Map> mapListFromJson(dynamic json, {bool growable = false,}) { + final map = >{}; + if (json is Map && json.isNotEmpty) { + // ignore: parameter_assignments + json = json.cast(); + for (final entry in json.entries) { + map[entry.key] = ObjectWithInlineEnumDefaultValue.listFromJson(entry.value, growable: growable,); + } + } + return map; + } + + /// The list of required keys that must be present in a JSON. + static const requiredKeys = { + }; +} + +/// Object one attribute enum with default value +class ObjectWithInlineEnumDefaultValueAttributeEnum { + /// Instantiate a new enum with the provided [value]. + const ObjectWithInlineEnumDefaultValueAttributeEnum._(this.value); + + /// The underlying value of this enum member. + final String value; + + @override + String toString() => value; + + String toJson() => value; + + static const valueOne = ObjectWithInlineEnumDefaultValueAttributeEnum._(r'value_one'); + static const valueTwo = ObjectWithInlineEnumDefaultValueAttributeEnum._(r'value_two'); + + /// List of all possible values in this [enum][ObjectWithInlineEnumDefaultValueAttributeEnum]. + static const values = [ + valueOne, + valueTwo, + ]; + + static ObjectWithInlineEnumDefaultValueAttributeEnum? fromJson(dynamic value) => ObjectWithInlineEnumDefaultValueAttributeEnumTypeTransformer().decode(value); + + static List listFromJson(dynamic json, {bool growable = false,}) { + final result = []; + if (json is List && json.isNotEmpty) { + for (final row in json) { + final value = ObjectWithInlineEnumDefaultValueAttributeEnum.fromJson(row); + if (value != null) { + result.add(value); + } + } + } + return result.toList(growable: growable); + } +} + +/// Transformation class that can [encode] an instance of [ObjectWithInlineEnumDefaultValueAttributeEnum] to String, +/// and [decode] dynamic data back to [ObjectWithInlineEnumDefaultValueAttributeEnum]. +class ObjectWithInlineEnumDefaultValueAttributeEnumTypeTransformer { + factory ObjectWithInlineEnumDefaultValueAttributeEnumTypeTransformer() => _instance ??= const ObjectWithInlineEnumDefaultValueAttributeEnumTypeTransformer._(); + + const ObjectWithInlineEnumDefaultValueAttributeEnumTypeTransformer._(); + + String encode(ObjectWithInlineEnumDefaultValueAttributeEnum data) => data.value; + + /// Decodes a [dynamic value][data] to a ObjectWithInlineEnumDefaultValueAttributeEnum. + /// + /// If [allowNull] is true and the [dynamic value][data] cannot be decoded successfully, + /// then null is returned. However, if [allowNull] is false and the [dynamic value][data] + /// cannot be decoded successfully, then an [UnimplementedError] is thrown. + /// + /// The [allowNull] is very handy when an API changes and a new enum value is added or removed, + /// and users are still using an old app with the old code. + ObjectWithInlineEnumDefaultValueAttributeEnum? decode(dynamic data, {bool allowNull = true}) { + if (data != null) { + switch (data) { + case r'value_one': return ObjectWithInlineEnumDefaultValueAttributeEnum.valueOne; + case r'value_two': return ObjectWithInlineEnumDefaultValueAttributeEnum.valueTwo; + default: + if (!allowNull) { + throw ArgumentError('Unknown enum value to decode: $data'); + } + } + } + return null; + } + + /// Singleton [ObjectWithInlineEnumDefaultValueAttributeEnumTypeTransformer] instance. + static ObjectWithInlineEnumDefaultValueAttributeEnumTypeTransformer? _instance; +} + + diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/test_enum.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/test_enum.dart index c88e6cc0be29..ac5e197d09c6 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/test_enum.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/test_enum.dart @@ -24,14 +24,14 @@ class TestEnum { String toJson() => value; static const empty = TestEnum._(r''); - static const n1 = TestEnum._(r'1'); - static const n2 = TestEnum._(r'2'); + static const valueOne = TestEnum._(r'value_one'); + static const valueTwo = TestEnum._(r'value_two'); /// List of all possible values in this [enum][TestEnum]. static const values = [ empty, - n1, - n2, + valueOne, + valueTwo, ]; static TestEnum? fromJson(dynamic value) => TestEnumTypeTransformer().decode(value); @@ -71,8 +71,8 @@ class TestEnumTypeTransformer { if (data != null) { switch (data) { case r'': return TestEnum.empty; - case r'1': return TestEnum.n1; - case r'2': return TestEnum.n2; + case r'value_one': return TestEnum.valueOne; + case r'value_two': return TestEnum.valueTwo; default: if (!allowNull) { throw ArgumentError('Unknown enum value to decode: $data'); diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/test_item.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/test_item.dart deleted file mode 100644 index b4b5aef1f60c..000000000000 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/test_item.dart +++ /dev/null @@ -1,126 +0,0 @@ -// -// AUTO-GENERATED FILE, DO NOT MODIFY! -// -// @dart=2.18 - -// ignore_for_file: unused_element, unused_import -// ignore_for_file: always_put_required_named_parameters_first -// ignore_for_file: constant_identifier_names -// ignore_for_file: lines_longer_than_80_chars - -part of openapi.api; - -class TestItem { - /// Returns a new [TestItem] instance. - TestItem({ - required this.test, - this.testEmum, - }); - - int test; - - /// - /// Please note: This property should have been non-nullable! Since the specification file - /// does not include a default value (using the "default:" property), however, the generated - /// source code must fall back to having a nullable type. - /// Consider adding a "default:" property in the specification file to hide this note. - /// - TestEnum? testEmum; - - @override - bool operator ==(Object other) => identical(this, other) || other is TestItem && - other.test == test && - other.testEmum == testEmum; - - @override - int get hashCode => - // ignore: unnecessary_parenthesis - (test.hashCode) + - (testEmum == null ? 0 : testEmum!.hashCode); - - @override - String toString() => 'TestItem[test=$test, testEmum=$testEmum]'; - - Map toJson() { - final json = {}; - json[r'test'] = this.test; - if (this.testEmum != null) { - json[r'testEmum'] = this.testEmum; - } else { - json[r'testEmum'] = null; - } - return json; - } - - /// Returns a new [TestItem] instance and imports its values from - /// [value] if it's a [Map], null otherwise. - // ignore: prefer_constructors_over_static_methods - static TestItem? fromJson(dynamic value) { - if (value is Map) { - final json = value.cast(); - - // Ensure that the map contains the required keys. - // Note 1: the values aren't checked for validity beyond being non-null. - // Note 2: this code is stripped in release mode! - assert(() { - requiredKeys.forEach((key) { - assert(json.containsKey(key), 'Required key "TestItem[$key]" is missing from JSON.'); - assert(json[key] != null, 'Required key "TestItem[$key]" has a null value in JSON.'); - }); - return true; - }()); - - return TestItem( - test: mapValueOfType(json, r'test')!, - testEmum: TestEnum.fromJson(json[r'testEmum']), - ); - } - return null; - } - - static List listFromJson(dynamic json, {bool growable = false,}) { - final result = []; - if (json is List && json.isNotEmpty) { - for (final row in json) { - final value = TestItem.fromJson(row); - if (value != null) { - result.add(value); - } - } - } - return result.toList(growable: growable); - } - - static Map mapFromJson(dynamic json) { - final map = {}; - if (json is Map && json.isNotEmpty) { - json = json.cast(); // ignore: parameter_assignments - for (final entry in json.entries) { - final value = TestItem.fromJson(entry.value); - if (value != null) { - map[entry.key] = value; - } - } - } - return map; - } - - // maps a json object with a list of TestItem-objects as value to a dart map - static Map> mapListFromJson(dynamic json, {bool growable = false,}) { - final map = >{}; - if (json is Map && json.isNotEmpty) { - // ignore: parameter_assignments - json = json.cast(); - for (final entry in json.entries) { - map[entry.key] = TestItem.listFromJson(entry.value, growable: growable,); - } - } - return map; - } - - /// The list of required keys that must be present in a JSON. - static const requiredKeys = { - 'test', - }; -} - diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/test/test_item_test.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/test/object_with_enum_test.dart similarity index 60% rename from samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/test/test_item_test.dart rename to samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/test/object_with_enum_test.dart index 38c9d87409af..a93713979fd1 100644 --- a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/test/test_item_test.dart +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/test/object_with_enum_test.dart @@ -11,18 +11,13 @@ import 'package:openapi/api.dart'; import 'package:test/test.dart'; -// tests for TestItem +// tests for ObjectWithEnum void main() { - // final instance = TestItem(); + // final instance = ObjectWithEnum(); - group('test TestItem', () { - // int test - test('to test the property `test`', () async { - // TODO - }); - - // TestEnum testEmum - test('to test the property `testEmum`', () async { + group('test ObjectWithEnum', () { + // TestEnum attribute (default value: TestEnum.empty) + test('to test the property `attribute`', () async { // TODO }); diff --git a/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/test/object_with_inline_enum_default_value_test.dart b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/test/object_with_inline_enum_default_value_test.dart new file mode 100644 index 000000000000..9e8f1ad4bf57 --- /dev/null +++ b/samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/test/object_with_inline_enum_default_value_test.dart @@ -0,0 +1,28 @@ +// +// AUTO-GENERATED FILE, DO NOT MODIFY! +// +// @dart=2.18 + +// ignore_for_file: unused_element, unused_import +// ignore_for_file: always_put_required_named_parameters_first +// ignore_for_file: constant_identifier_names +// ignore_for_file: lines_longer_than_80_chars + +import 'package:openapi/api.dart'; +import 'package:test/test.dart'; + +// tests for ObjectWithInlineEnumDefaultValue +void main() { + // final instance = ObjectWithInlineEnumDefaultValue(); + + group('test ObjectWithInlineEnumDefaultValue', () { + // Object one attribute enum with default value + // String attribute (default value: 'value_one') + test('to test the property `attribute`', () async { + // TODO + }); + + + }); + +}