Skip to content

Commit b8a9e33

Browse files
committed
more tests
1 parent 363d6c2 commit b8a9e33

File tree

3 files changed

+19
-146
lines changed

3 files changed

+19
-146
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
push:
55
branches:
66
paths:
7+
- samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/**
78
#- samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake_tests/**
89
#- samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/**
910
- samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/**
@@ -13,6 +14,7 @@ on:
1314
- samples/openapi3/client/petstore/dart-dio/petstore-timemachine/**
1415
pull_request:
1516
paths:
17+
- samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/**
1618
#- samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake_tests/**
1719
#- samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/**
1820
- samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/**
@@ -29,6 +31,7 @@ jobs:
2931
os: [ubuntu-latest, windows-latest]
3032
sdk: ["3.9.0"]
3133
sample:
34+
- samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/
3235
#- samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake_tests/
3336
#- samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/
3437
- samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/

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-

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

Lines changed: 8 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ class ParentWithNullable {
1717
this.nullableProperty,
1818
});
1919

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

2228
String? nullableProperty;
2329

@@ -69,7 +75,7 @@ class ParentWithNullable {
6975
}());
7076

7177
return ParentWithNullable(
72-
type: ParentWithNullableTypeEnum.fromJson(json[r'type']),
78+
type: mapValueOfType<String>(json, r'type'),
7379
nullableProperty: mapValueOfType<String>(json, r'nullableProperty'),
7480
);
7581
}
@@ -121,74 +127,3 @@ class ParentWithNullable {
121127
};
122128
}
123129

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

0 commit comments

Comments
 (0)