Skip to content

Commit e68e3e8

Browse files
authored
More dart dio tests, update samples (#21975)
* more dart dio tests, update samples * update * update * more tests * update * update
1 parent 8b01ebb commit e68e3e8

File tree

8 files changed

+37
-230
lines changed

8 files changed

+37
-230
lines changed

.github/workflows/samples-dart-build-test.yaml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,20 @@ on:
44
push:
55
branches:
66
paths:
7-
#- samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/**
7+
#- samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/**
88
#- samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake_tests/**
9-
#- samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/**
9+
#- samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/**
10+
- samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/**
1011
- samples/openapi3/client/petstore/dart-dio/oneof/**
1112
- samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/**
1213
- samples/openapi3/client/petstore/dart-dio/binary_response/**
1314
- samples/openapi3/client/petstore/dart-dio/petstore-timemachine/**
1415
pull_request:
1516
paths:
16-
#- samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/**
17+
#- samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/**
1718
#- samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake_tests/**
18-
#- samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/**
19+
#- samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/**
20+
- samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/**
1921
- samples/openapi3/client/petstore/dart-dio/oneof/**
2022
- samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/**
2123
- samples/openapi3/client/petstore/dart-dio/binary_response/**
@@ -29,9 +31,10 @@ jobs:
2931
os: [ubuntu-latest, windows-latest]
3032
sdk: ["3.9.0"]
3133
sample:
32-
#- samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/
34+
#- samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/
3335
#- samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake_tests/
34-
#- samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/
36+
#- samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/
37+
- samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/
3538
- samples/openapi3/client/petstore/dart-dio/oneof/
3639
- samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/
3740
- samples/openapi3/client/petstore/dart-dio/binary_response/

modules/openapi-generator/src/test/resources/3_0/dart/petstore-with-fake-endpoints-models-for-testing.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1928,8 +1928,9 @@ components:
19281928
properties:
19291929
type:
19301930
type: string
1931-
enum:
1932-
- ChildWithNullable
1931+
# comment out as it's causing compilation errors in Dart Dio client generator
1932+
#enum:
1933+
# - ChildWithNullable
19331934
nullableProperty:
19341935
type: string
19351936
nullable: true

samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/child_with_nullable.dart

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,10 @@ class ChildWithNullable {
3535
name: r'type',
3636
required: false,
3737
includeIfNull: false,
38-
unknownEnumValue: ChildWithNullableTypeEnum.unknownDefaultOpenApi,
3938
)
4039

4140

42-
final ChildWithNullableTypeEnum? type;
41+
final String? type;
4342

4443

4544

@@ -92,19 +91,3 @@ class ChildWithNullable {
9291

9392
}
9493

95-
96-
enum ChildWithNullableTypeEnum {
97-
@JsonValue(r'ChildWithNullable')
98-
childWithNullable(r'ChildWithNullable'),
99-
@JsonValue(r'unknown_default_open_api')
100-
unknownDefaultOpenApi(r'unknown_default_open_api');
101-
102-
const ChildWithNullableTypeEnum(this.value);
103-
104-
final String value;
105-
106-
@override
107-
String toString() => value;
108-
}
109-
110-

samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/lib/src/model/parent_with_nullable.dart

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,10 @@ class ParentWithNullable {
3030
name: r'type',
3131
required: false,
3232
includeIfNull: false,
33-
unknownEnumValue: ParentWithNullableTypeEnum.unknownDefaultOpenApi,
3433
)
3534

3635

37-
final ParentWithNullableTypeEnum? type;
36+
final String? type;
3837

3938

4039

@@ -73,19 +72,3 @@ class ParentWithNullable {
7372

7473
}
7574

76-
77-
enum ParentWithNullableTypeEnum {
78-
@JsonValue(r'ChildWithNullable')
79-
childWithNullable(r'ChildWithNullable'),
80-
@JsonValue(r'unknown_default_open_api')
81-
unknownDefaultOpenApi(r'unknown_default_open_api');
82-
83-
const ParentWithNullableTypeEnum(this.value);
84-
85-
final String value;
86-
87-
@override
88-
String toString() => value;
89-
}
90-
91-

samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/child_with_nullable.dart

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
//
44

55
// ignore_for_file: unused_element
6-
import 'package:built_collection/built_collection.dart';
76
import 'package:openapi/src/model/parent_with_nullable.dart';
87
import 'package:built_value/built_value.dart';
98
import 'package:built_value/serializer.dart';
@@ -48,7 +47,7 @@ class _$ChildWithNullableSerializer implements PrimitiveSerializer<ChildWithNull
4847
yield r'type';
4948
yield serializers.serialize(
5049
object.type,
51-
specifiedType: const FullType(ParentWithNullableTypeEnum),
50+
specifiedType: const FullType(String),
5251
);
5352
}
5453
if (object.nullableProperty != null) {
@@ -91,8 +90,8 @@ class _$ChildWithNullableSerializer implements PrimitiveSerializer<ChildWithNull
9190
case r'type':
9291
final valueDes = serializers.deserialize(
9392
value,
94-
specifiedType: const FullType(ParentWithNullableTypeEnum),
95-
) as ParentWithNullableTypeEnum;
93+
specifiedType: const FullType(String),
94+
) as String;
9695
result.type = valueDes;
9796
break;
9897
case r'nullableProperty':
@@ -139,18 +138,3 @@ class _$ChildWithNullableSerializer implements PrimitiveSerializer<ChildWithNull
139138
}
140139
}
141140

142-
class ChildWithNullableTypeEnum extends EnumClass {
143-
144-
@BuiltValueEnumConst(wireName: r'ChildWithNullable')
145-
static const ChildWithNullableTypeEnum childWithNullable = _$childWithNullableTypeEnum_childWithNullable;
146-
@BuiltValueEnumConst(wireName: r'unknown_default_open_api', fallback: true)
147-
static const ChildWithNullableTypeEnum unknownDefaultOpenApi = _$childWithNullableTypeEnum_unknownDefaultOpenApi;
148-
149-
static Serializer<ChildWithNullableTypeEnum> get serializer => _$childWithNullableTypeEnumSerializer;
150-
151-
const ChildWithNullableTypeEnum._(String name): super(name);
152-
153-
static BuiltSet<ChildWithNullableTypeEnum> get values => _$childWithNullableTypeEnumValues;
154-
static ChildWithNullableTypeEnum valueOf(String name) => _$childWithNullableTypeEnumValueOf(name);
155-
}
156-

samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/lib/src/model/parent_with_nullable.dart

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
//
44

55
// ignore_for_file: unused_element
6-
import 'package:built_collection/built_collection.dart';
76
import 'package:openapi/src/model/child_with_nullable.dart';
87
import 'package:built_value/built_value.dart';
98
import 'package:built_value/serializer.dart';
@@ -18,8 +17,7 @@ part 'parent_with_nullable.g.dart';
1817
@BuiltValue(instantiable: false)
1918
abstract class ParentWithNullable {
2019
@BuiltValueField(wireName: r'type')
21-
ParentWithNullableTypeEnum? get type;
22-
// enum typeEnum { ChildWithNullable, };
20+
String? get type;
2321

2422
@BuiltValueField(wireName: r'nullableProperty')
2523
String? get nullableProperty;
@@ -67,7 +65,7 @@ class _$ParentWithNullableSerializer implements PrimitiveSerializer<ParentWithNu
6765
yield r'type';
6866
yield serializers.serialize(
6967
object.type,
70-
specifiedType: const FullType(ParentWithNullableTypeEnum),
68+
specifiedType: const FullType(String),
7169
);
7270
}
7371
if (object.nullableProperty != null) {
@@ -154,8 +152,8 @@ class _$$ParentWithNullableSerializer implements PrimitiveSerializer<$ParentWith
154152
case r'type':
155153
final valueDes = serializers.deserialize(
156154
value,
157-
specifiedType: const FullType(ParentWithNullableTypeEnum),
158-
) as ParentWithNullableTypeEnum;
155+
specifiedType: const FullType(String),
156+
) as String;
159157
result.type = valueDes;
160158
break;
161159
case r'nullableProperty':
@@ -195,18 +193,3 @@ class _$$ParentWithNullableSerializer implements PrimitiveSerializer<$ParentWith
195193
}
196194
}
197195

198-
class ParentWithNullableTypeEnum extends EnumClass {
199-
200-
@BuiltValueEnumConst(wireName: r'ChildWithNullable')
201-
static const ParentWithNullableTypeEnum childWithNullable = _$parentWithNullableTypeEnum_childWithNullable;
202-
@BuiltValueEnumConst(wireName: r'unknown_default_open_api', fallback: true)
203-
static const ParentWithNullableTypeEnum unknownDefaultOpenApi = _$parentWithNullableTypeEnum_unknownDefaultOpenApi;
204-
205-
static Serializer<ParentWithNullableTypeEnum> get serializer => _$parentWithNullableTypeEnumSerializer;
206-
207-
const ParentWithNullableTypeEnum._(String name): super(name);
208-
209-
static BuiltSet<ParentWithNullableTypeEnum> get values => _$parentWithNullableTypeEnumValues;
210-
static ParentWithNullableTypeEnum valueOf(String name) => _$parentWithNullableTypeEnumValueOf(name);
211-
}
212-

samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/model/child_with_nullable.dart

Lines changed: 8 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ class ChildWithNullable {
1818
this.otherProperty,
1919
});
2020

21-
ChildWithNullableTypeEnum? type;
21+
///
22+
/// Please note: This property should have been non-nullable! Since the specification file
23+
/// does not include a default value (using the "default:" property), however, the generated
24+
/// source code must fall back to having a nullable type.
25+
/// Consider adding a "default:" property in the specification file to hide this note.
26+
///
27+
String? type;
2228

2329
String? nullableProperty;
2430

@@ -85,7 +91,7 @@ class ChildWithNullable {
8591
}());
8692

8793
return ChildWithNullable(
88-
type: ChildWithNullableTypeEnum.fromJson(json[r'type']),
94+
type: mapValueOfType<String>(json, r'type'),
8995
nullableProperty: mapValueOfType<String>(json, r'nullableProperty'),
9096
otherProperty: mapValueOfType<String>(json, r'otherProperty'),
9197
);
@@ -138,74 +144,3 @@ class ChildWithNullable {
138144
};
139145
}
140146

141-
142-
class ChildWithNullableTypeEnum {
143-
/// Instantiate a new enum with the provided [value].
144-
const ChildWithNullableTypeEnum._(this.value);
145-
146-
/// The underlying value of this enum member.
147-
final String value;
148-
149-
@override
150-
String toString() => value;
151-
152-
String toJson() => value;
153-
154-
static const childWithNullable = ChildWithNullableTypeEnum._(r'ChildWithNullable');
155-
156-
/// List of all possible values in this [enum][ChildWithNullableTypeEnum].
157-
static const values = <ChildWithNullableTypeEnum>[
158-
childWithNullable,
159-
];
160-
161-
static ChildWithNullableTypeEnum? fromJson(dynamic value) => ChildWithNullableTypeEnumTypeTransformer().decode(value);
162-
163-
static List<ChildWithNullableTypeEnum> listFromJson(dynamic json, {bool growable = false,}) {
164-
final result = <ChildWithNullableTypeEnum>[];
165-
if (json is List && json.isNotEmpty) {
166-
for (final row in json) {
167-
final value = ChildWithNullableTypeEnum.fromJson(row);
168-
if (value != null) {
169-
result.add(value);
170-
}
171-
}
172-
}
173-
return result.toList(growable: growable);
174-
}
175-
}
176-
177-
/// Transformation class that can [encode] an instance of [ChildWithNullableTypeEnum] to String,
178-
/// and [decode] dynamic data back to [ChildWithNullableTypeEnum].
179-
class ChildWithNullableTypeEnumTypeTransformer {
180-
factory ChildWithNullableTypeEnumTypeTransformer() => _instance ??= const ChildWithNullableTypeEnumTypeTransformer._();
181-
182-
const ChildWithNullableTypeEnumTypeTransformer._();
183-
184-
String encode(ChildWithNullableTypeEnum data) => data.value;
185-
186-
/// Decodes a [dynamic value][data] to a ChildWithNullableTypeEnum.
187-
///
188-
/// If [allowNull] is true and the [dynamic value][data] cannot be decoded successfully,
189-
/// then null is returned. However, if [allowNull] is false and the [dynamic value][data]
190-
/// cannot be decoded successfully, then an [UnimplementedError] is thrown.
191-
///
192-
/// The [allowNull] is very handy when an API changes and a new enum value is added or removed,
193-
/// and users are still using an old app with the old code.
194-
ChildWithNullableTypeEnum? decode(dynamic data, {bool allowNull = true}) {
195-
if (data != null) {
196-
switch (data) {
197-
case r'ChildWithNullable': return ChildWithNullableTypeEnum.childWithNullable;
198-
default:
199-
if (!allowNull) {
200-
throw ArgumentError('Unknown enum value to decode: $data');
201-
}
202-
}
203-
}
204-
return null;
205-
}
206-
207-
/// Singleton [ChildWithNullableTypeEnumTypeTransformer] instance.
208-
static ChildWithNullableTypeEnumTypeTransformer? _instance;
209-
}
210-
211-

0 commit comments

Comments
 (0)