Skip to content

[dart-dio] Fix compile error in enum properties with "default" values (#20495) #21355

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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}}const {{{enumName}}}._({{/isContainer}}{{/isEnum}}{{{defaultValue}}}{{#isEnum}}{{^isContainer}}){{/isContainer}}{{/isEnum}}{{/defaultValue}}{{/vendorExtensions.x-self-and-ancestor-only-props}};
..{{{name}}} = {{#isEnum}}{{^isContainer}}{{{defaultValue}}}{{/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 @@ -2062,3 +2062,22 @@ components:
enum:
- admin
- user
TestEnum:
type: string
enum:
- ""
- "1"
- "2"
title: TestEnum
TestItem:
type: object
required:
- test
properties:
test:
type: integer
title: test
testEmum:
$ref: '#/components/schemas/TestEnum'
default: ""
title: TestItem
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ doc/SingleRefType.md
doc/SpecialModelName.md
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 @@ -122,6 +124,8 @@ lib/src/model/read_only_first.dart
lib/src/model/single_ref_type.dart
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 @@ -164,7 +164,9 @@ Class | Method | HTTP request | Description
- [SingleRefType](doc/SingleRefType.md)
- [SpecialModelName](doc/SpecialModelName.md)
- [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
@@ -0,0 +1,14 @@
# openapi.model.TestEnum

## Load the model package
```dart
import 'package:openapi/api.dart';
```

## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------

[[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
@@ -0,0 +1,16 @@
# openapi.model.TestItem

## Load the model package
```dart
import 'package:openapi/api.dart';
```

## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**test** | **int** | |
**testEmum** | [**TestEnum**](TestEnum.md) | | [optional]

[[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 @@ -65,6 +65,8 @@ export 'package:openapi/src/model/read_only_first.dart';
export 'package:openapi/src/model/single_ref_type.dart';
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 @@ -41,6 +41,7 @@ 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 @@ -163,8 +164,13 @@ final _regMap = RegExp(r'^Map<String,(.*)>$');
return SpecialModelName.fromJson(value as Map<String, dynamic>) as ReturnType;
case 'Tag':
return Tag.fromJson(value as Map<String, dynamic>) as ReturnType;
case 'TestEnum':


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
@@ -0,0 +1,25 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//

// ignore_for_file: unused_element
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'unknown_default_open_api')
unknownDefaultOpenApi(r'unknown_default_open_api');

const TestEnum(this.value);

final String value;

@override
String toString() => value;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//

// ignore_for_file: unused_element
import 'package:openapi/src/model/test_enum.dart';
import 'package:json_annotation/json_annotation.dart';

part 'test_item.g.dart';


@JsonSerializable(
checked: true,
createToJson: true,
disallowUnrecognizedKeys: false,
explicitToJson: true,
)
class TestItem {
/// Returns a new [TestItem] instance.
TestItem({

required this.test,

this.testEmum,
});

@JsonKey(

name: r'test',
required: true,
includeIfNull: false,
)


final int test;



@JsonKey(

name: r'testEmum',
required: false,
includeIfNull: false,
unknownEnumValue: TestEnum.unknownDefaultOpenApi,
)


final TestEnum? testEmum;





@override
bool operator ==(Object other) => identical(this, other) || other is TestItem &&
other.test == test &&
other.testEmum == testEmum;

@override
int get hashCode =>
test.hashCode +
testEmum.hashCode;

factory TestItem.fromJson(Map<String, dynamic> json) => _$TestItemFromJson(json);

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

@override
String toString() {
return toJson().toString();
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import 'package:test/test.dart';
import 'package:openapi/openapi.dart';

// tests for TestEnum
void main() {

group(TestEnum, () {
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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
});

});
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ doc/SingleRefType.md
doc/SpecialModelName.md
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 @@ -123,7 +125,9 @@ lib/src/model/read_only_first.dart
lib/src/model/single_ref_type.dart
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
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ Class | Method | HTTP request | Description
- [SingleRefType](doc/SingleRefType.md)
- [SpecialModelName](doc/SpecialModelName.md)
- [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
@@ -0,0 +1,14 @@
# openapi.model.TestEnum

## Load the model package
```dart
import 'package:openapi/api.dart';
```

## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------

[[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
@@ -0,0 +1,16 @@
# openapi.model.TestItem

## Load the model package
```dart
import 'package:openapi/api.dart';
```

## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**test** | **int** | |
**testEmum** | [**TestEnum**](TestEnum.md) | | [optional]

[[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 @@ -66,6 +66,8 @@ export 'package:openapi/src/model/read_only_first.dart';
export 'package:openapi/src/model/single_ref_type.dart';
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
@@ -0,0 +1,38 @@
//
// 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 'test_enum.g.dart';

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'unknown_default_open_api', fallback: true)
static const TestEnum unknownDefaultOpenApi = _$unknownDefaultOpenApi;

static Serializer<TestEnum> get serializer => _$testEnumSerializer;

const TestEnum._(String name): super(name);

static BuiltSet<TestEnum> get values => _$values;
static TestEnum valueOf(String name) => _$valueOf(name);
}

/// Optionally, enum_class can generate a mixin to go with your enum for use
/// with Angular. It exposes your enum constants as getters. So, if you mix it
/// in to your Dart component class, the values become available to the
/// corresponding Angular template.
///
/// Trigger mixin generation by writing a line like this one next to your enum.
abstract class TestEnumMixin = Object with _$TestEnumMixin;

Loading
Loading