Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Original file line number Diff line number Diff line change
Expand Up @@ -2079,22 +2079,29 @@ components:
TestEnum:
type: string
enum:
- ""
- "1"
- "2"
- ''
- 'value_one'
- 'value_two'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shall we keep the same test schemas and add new one covered by this PR instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous test schemas were actually incorrect — they were missing an allOf, which caused inconsistent behavior.
I fixed that and renamed the test and parameters to make them consistent with the other tests in the project.

Additionally, I added a new test that covers a separate case where the enum is defined inline.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not keep the same

      enum:
        - ""
        - "1"
        - "2"

?

why do you need to change the enum values to something else?

wouldn't "1", "2" still work with the fix?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you need to change the enum values to something else?

These enum values ​​are not similar to the values ​​of other enums in other test cases.
This change only affects consistency.
Leaving these changes unchanged will not change anything.

wouldn't "1", "2" still work with the fix?

Its will work.

I can return these values ​​back if it is important.

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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# openapi.model.TestItem
# openapi.model.ObjectWithEnum

## Load the model package
```dart
Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
@@ -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)


Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';

Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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<(.*)>$');
Expand Down Expand Up @@ -140,8 +141,12 @@ final _regMap = RegExp(r'^Map<String,(.*)>$');
return ObjectWithDeprecatedFields.fromJson(value as Map<String, dynamic>) as ReturnType;
case 'ObjectWithDuplicateInlineEnum':
return ObjectWithDuplicateInlineEnum.fromJson(value as Map<String, dynamic>) as ReturnType;
case 'ObjectWithEnum':
return ObjectWithEnum.fromJson(value as Map<String, dynamic>) as ReturnType;
case 'ObjectWithInlineEnum':
return ObjectWithInlineEnum.fromJson(value as Map<String, dynamic>) as ReturnType;
case 'ObjectWithInlineEnumDefaultValue':
return ObjectWithInlineEnumDefaultValue.fromJson(value as Map<String, dynamic>) as ReturnType;
case 'Order':
return Order.fromJson(value as Map<String, dynamic>) as ReturnType;
case 'OuterComposite':
Expand Down Expand Up @@ -178,8 +183,6 @@ final _regMap = RegExp(r'^Map<String,(.*)>$');

case 'TestInlineFreeformAdditionalPropertiesRequest':
return TestInlineFreeformAdditionalPropertiesRequest.fromJson(value as Map<String, dynamic>) as ReturnType;
case 'TestItem':
return TestItem.fromJson(value as Map<String, dynamic>) as ReturnType;
case 'User':
return User.fromJson(value as Map<String, dynamic>) as ReturnType;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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<String, dynamic> json) => _$TestItemFromJson(json);
factory ObjectWithEnum.fromJson(Map<String, dynamic> json) => _$ObjectWithEnumFromJson(json);

Map<String, dynamic> toJson() => _$TestItemToJson(this);
Map<String, dynamic> toJson() => _$ObjectWithEnumToJson(this);

@override
String toString() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, dynamic> json) => _$ObjectWithInlineEnumDefaultValueFromJson(json);

Map<String, dynamic> 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;
}


Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
Original file line number Diff line number Diff line change
@@ -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
});

});
}
Loading
Loading