mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-10-14 00:13:50 +00:00
* [dart-dio] Fix compile error in enum properties with "default" values(#20495) * Add a test schema with enum properties
This commit is contained in:
parent
0f305a5958
commit
f632ab7977
@ -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();
|
@ -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
|
||||
|
@ -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
|
||||
@ -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
|
||||
|
@ -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)
|
||||
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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';
|
||||
|
||||
|
@ -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<(.*)>$');
|
||||
@ -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:
|
||||
|
@ -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;
|
||||
}
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,9 @@
|
||||
import 'package:test/test.dart';
|
||||
import 'package:openapi/openapi.dart';
|
||||
|
||||
// tests for TestEnum
|
||||
void main() {
|
||||
|
||||
group(TestEnum, () {
|
||||
});
|
||||
}
|
@ -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
|
||||
});
|
||||
|
||||
});
|
||||
}
|
@ -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
|
||||
@ -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
|
||||
|
@ -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)
|
||||
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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';
|
||||
|
||||
|
@ -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;
|
||||
|
@ -0,0 +1,126 @@
|
||||
//
|
||||
// AUTO-GENERATED FILE, DO NOT MODIFY!
|
||||
//
|
||||
|
||||
// ignore_for_file: unused_element
|
||||
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';
|
||||
|
||||
/// TestItem
|
||||
///
|
||||
/// Properties:
|
||||
/// * [test]
|
||||
/// * [testEmum]
|
||||
@BuiltValue()
|
||||
abstract class TestItem implements Built<TestItem, TestItemBuilder> {
|
||||
@BuiltValueField(wireName: r'test')
|
||||
int get test;
|
||||
|
||||
@BuiltValueField(wireName: r'testEmum')
|
||||
TestEnum? get testEmum;
|
||||
// enum testEmumEnum { , 1, 2, };
|
||||
|
||||
TestItem._();
|
||||
|
||||
factory TestItem([void updates(TestItemBuilder b)]) = _$TestItem;
|
||||
|
||||
@BuiltValueHook(initializeBuilder: true)
|
||||
static void _defaults(TestItemBuilder b) => b;
|
||||
|
||||
@BuiltValueSerializer(custom: true)
|
||||
static Serializer<TestItem> get serializer => _$TestItemSerializer();
|
||||
}
|
||||
|
||||
class _$TestItemSerializer implements PrimitiveSerializer<TestItem> {
|
||||
@override
|
||||
final Iterable<Type> types = const [TestItem, _$TestItem];
|
||||
|
||||
@override
|
||||
final String wireName = r'TestItem';
|
||||
|
||||
Iterable<Object?> _serializeProperties(
|
||||
Serializers serializers,
|
||||
TestItem 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';
|
||||
yield serializers.serialize(
|
||||
object.testEmum,
|
||||
specifiedType: const FullType(TestEnum),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Object serialize(
|
||||
Serializers serializers,
|
||||
TestItem object, {
|
||||
FullType specifiedType = FullType.unspecified,
|
||||
}) {
|
||||
return _serializeProperties(serializers, object, specifiedType: specifiedType).toList();
|
||||
}
|
||||
|
||||
void _deserializeProperties(
|
||||
Serializers serializers,
|
||||
Object serialized, {
|
||||
FullType specifiedType = FullType.unspecified,
|
||||
required List<Object?> serializedList,
|
||||
required TestItemBuilder result,
|
||||
required List<Object?> 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':
|
||||
final valueDes = serializers.deserialize(
|
||||
value,
|
||||
specifiedType: const FullType(TestEnum),
|
||||
) as TestEnum;
|
||||
result.testEmum = valueDes;
|
||||
break;
|
||||
default:
|
||||
unhandled.add(key);
|
||||
unhandled.add(value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
TestItem deserialize(
|
||||
Serializers serializers,
|
||||
Object serialized, {
|
||||
FullType specifiedType = FullType.unspecified,
|
||||
}) {
|
||||
final result = TestItemBuilder();
|
||||
final serializedList = (serialized as Iterable<Object?>).toList();
|
||||
final unhandled = <Object?>[];
|
||||
_deserializeProperties(
|
||||
serializers,
|
||||
serialized,
|
||||
specifiedType: specifiedType,
|
||||
serializedList: serializedList,
|
||||
unhandled: unhandled,
|
||||
result: result,
|
||||
);
|
||||
return result.build();
|
||||
}
|
||||
}
|
||||
|
@ -62,7 +62,9 @@ import 'package:openapi/src/model/read_only_first.dart';
|
||||
import 'package:openapi/src/model/single_ref_type.dart';
|
||||
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';
|
||||
@ -116,7 +118,9 @@ part 'serializers.g.dart';
|
||||
SingleRefType,
|
||||
SpecialModelName,
|
||||
Tag,
|
||||
TestEnum,
|
||||
TestInlineFreeformAdditionalPropertiesRequest,
|
||||
TestItem,
|
||||
User,
|
||||
])
|
||||
Serializers serializers = (_$serializers.toBuilder()
|
||||
|
@ -0,0 +1,9 @@
|
||||
import 'package:test/test.dart';
|
||||
import 'package:openapi/openapi.dart';
|
||||
|
||||
// tests for TestEnum
|
||||
void main() {
|
||||
|
||||
group(TestEnum, () {
|
||||
});
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
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
|
||||
});
|
||||
|
||||
});
|
||||
}
|
@ -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
|
||||
git_push.sh
|
||||
@ -124,6 +126,8 @@ lib/model/read_only_first.dart
|
||||
lib/model/single_ref_type.dart
|
||||
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
|
||||
|
@ -157,7 +157,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)
|
||||
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -84,7 +84,9 @@ part 'model/read_only_first.dart';
|
||||
part 'model/single_ref_type.dart';
|
||||
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';
|
||||
|
||||
|
||||
|
@ -278,8 +278,12 @@ class ApiClient {
|
||||
return SpecialModelName.fromJson(value);
|
||||
case 'Tag':
|
||||
return Tag.fromJson(value);
|
||||
case 'TestEnum':
|
||||
return TestEnumTypeTransformer().decode(value);
|
||||
case 'TestInlineFreeformAdditionalPropertiesRequest':
|
||||
return TestInlineFreeformAdditionalPropertiesRequest.fromJson(value);
|
||||
case 'TestItem':
|
||||
return TestItem.fromJson(value);
|
||||
case 'User':
|
||||
return User.fromJson(value);
|
||||
default:
|
||||
|
@ -73,6 +73,9 @@ String parameterToString(dynamic value) {
|
||||
if (value is SingleRefType) {
|
||||
return SingleRefTypeTypeTransformer().encode(value).toString();
|
||||
}
|
||||
if (value is TestEnum) {
|
||||
return TestEnumTypeTransformer().encode(value).toString();
|
||||
}
|
||||
return value.toString();
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,88 @@
|
||||
//
|
||||
// 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 TestEnum {
|
||||
/// Instantiate a new enum with the provided [value].
|
||||
const TestEnum._(this.value);
|
||||
|
||||
/// The underlying value of this enum member.
|
||||
final String value;
|
||||
|
||||
@override
|
||||
String toString() => value;
|
||||
|
||||
String toJson() => value;
|
||||
|
||||
static const empty = TestEnum._(r'');
|
||||
static const n1 = TestEnum._(r'1');
|
||||
static const n2 = TestEnum._(r'2');
|
||||
|
||||
/// List of all possible values in this [enum][TestEnum].
|
||||
static const values = <TestEnum>[
|
||||
empty,
|
||||
n1,
|
||||
n2,
|
||||
];
|
||||
|
||||
static TestEnum? fromJson(dynamic value) => TestEnumTypeTransformer().decode(value);
|
||||
|
||||
static List<TestEnum> listFromJson(dynamic json, {bool growable = false,}) {
|
||||
final result = <TestEnum>[];
|
||||
if (json is List && json.isNotEmpty) {
|
||||
for (final row in json) {
|
||||
final value = TestEnum.fromJson(row);
|
||||
if (value != null) {
|
||||
result.add(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result.toList(growable: growable);
|
||||
}
|
||||
}
|
||||
|
||||
/// Transformation class that can [encode] an instance of [TestEnum] to String,
|
||||
/// and [decode] dynamic data back to [TestEnum].
|
||||
class TestEnumTypeTransformer {
|
||||
factory TestEnumTypeTransformer() => _instance ??= const TestEnumTypeTransformer._();
|
||||
|
||||
const TestEnumTypeTransformer._();
|
||||
|
||||
String encode(TestEnum data) => data.value;
|
||||
|
||||
/// Decodes a [dynamic value][data] to a TestEnum.
|
||||
///
|
||||
/// 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.
|
||||
TestEnum? decode(dynamic data, {bool allowNull = true}) {
|
||||
if (data != null) {
|
||||
switch (data) {
|
||||
case r'': return TestEnum.empty;
|
||||
case r'1': return TestEnum.n1;
|
||||
case r'2': return TestEnum.n2;
|
||||
default:
|
||||
if (!allowNull) {
|
||||
throw ArgumentError('Unknown enum value to decode: $data');
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// Singleton [TestEnumTypeTransformer] instance.
|
||||
static TestEnumTypeTransformer? _instance;
|
||||
}
|
||||
|
@ -0,0 +1,126 @@
|
||||
//
|
||||
// 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<String, dynamic> toJson() {
|
||||
final json = <String, dynamic>{};
|
||||
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<String, dynamic>();
|
||||
|
||||
// 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<int>(json, r'test')!,
|
||||
testEmum: TestEnum.fromJson(json[r'testEmum']),
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static List<TestItem> listFromJson(dynamic json, {bool growable = false,}) {
|
||||
final result = <TestItem>[];
|
||||
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<String, TestItem> mapFromJson(dynamic json) {
|
||||
final map = <String, TestItem>{};
|
||||
if (json is Map && json.isNotEmpty) {
|
||||
json = json.cast<String, dynamic>(); // 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<String, List<TestItem>> mapListFromJson(dynamic json, {bool growable = false,}) {
|
||||
final map = <String, List<TestItem>>{};
|
||||
if (json is Map && json.isNotEmpty) {
|
||||
// ignore: parameter_assignments
|
||||
json = json.cast<String, dynamic>();
|
||||
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 = <String>{
|
||||
'test',
|
||||
};
|
||||
}
|
||||
|
@ -0,0 +1,21 @@
|
||||
//
|
||||
// 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 TestEnum
|
||||
void main() {
|
||||
|
||||
group('test TestEnum', () {
|
||||
|
||||
});
|
||||
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
//
|
||||
// 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 TestItem
|
||||
void main() {
|
||||
// final instance = TestItem();
|
||||
|
||||
group('test TestItem', () {
|
||||
// int test
|
||||
test('to test the property `test`', () async {
|
||||
// TODO
|
||||
});
|
||||
|
||||
// TestEnum testEmum
|
||||
test('to test the property `testEmum`', () async {
|
||||
// TODO
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user