More dart dio tests, update samples (#21975)

* more dart dio tests, update samples

* update

* update

* more tests

* update

* update
This commit is contained in:
William Cheng 2025-09-16 11:46:52 +08:00 committed by GitHub
parent 8b01ebb5c2
commit e68e3e88b3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 37 additions and 230 deletions

View File

@ -4,18 +4,20 @@ on:
push:
branches:
paths:
#- samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/**
#- samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/**
#- samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake_tests/**
#- samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/**
#- samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/**
- samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/**
- samples/openapi3/client/petstore/dart-dio/oneof/**
- samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/**
- samples/openapi3/client/petstore/dart-dio/binary_response/**
- samples/openapi3/client/petstore/dart-dio/petstore-timemachine/**
pull_request:
paths:
#- samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/**
#- samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/**
#- samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake_tests/**
#- samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/**
#- samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/**
- samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/**
- samples/openapi3/client/petstore/dart-dio/oneof/**
- samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/**
- samples/openapi3/client/petstore/dart-dio/binary_response/**
@ -29,9 +31,10 @@ jobs:
os: [ubuntu-latest, windows-latest]
sdk: ["3.9.0"]
sample:
#- samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/
#- samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/
#- samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake_tests/
#- samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/
#- samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/
- samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/
- samples/openapi3/client/petstore/dart-dio/oneof/
- samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/
- samples/openapi3/client/petstore/dart-dio/binary_response/

View File

@ -1928,8 +1928,9 @@ components:
properties:
type:
type: string
enum:
- ChildWithNullable
# comment out as it's causing compilation errors in Dart Dio client generator
#enum:
# - ChildWithNullable
nullableProperty:
type: string
nullable: true

View File

@ -35,11 +35,10 @@ class ChildWithNullable {
name: r'type',
required: false,
includeIfNull: false,
unknownEnumValue: ChildWithNullableTypeEnum.unknownDefaultOpenApi,
)
final ChildWithNullableTypeEnum? type;
final String? type;
@ -92,19 +91,3 @@ class ChildWithNullable {
}
enum ChildWithNullableTypeEnum {
@JsonValue(r'ChildWithNullable')
childWithNullable(r'ChildWithNullable'),
@JsonValue(r'unknown_default_open_api')
unknownDefaultOpenApi(r'unknown_default_open_api');
const ChildWithNullableTypeEnum(this.value);
final String value;
@override
String toString() => value;
}

View File

@ -30,11 +30,10 @@ class ParentWithNullable {
name: r'type',
required: false,
includeIfNull: false,
unknownEnumValue: ParentWithNullableTypeEnum.unknownDefaultOpenApi,
)
final ParentWithNullableTypeEnum? type;
final String? type;
@ -73,19 +72,3 @@ class ParentWithNullable {
}
enum ParentWithNullableTypeEnum {
@JsonValue(r'ChildWithNullable')
childWithNullable(r'ChildWithNullable'),
@JsonValue(r'unknown_default_open_api')
unknownDefaultOpenApi(r'unknown_default_open_api');
const ParentWithNullableTypeEnum(this.value);
final String value;
@override
String toString() => value;
}

View File

@ -3,7 +3,6 @@
//
// ignore_for_file: unused_element
import 'package:built_collection/built_collection.dart';
import 'package:openapi/src/model/parent_with_nullable.dart';
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
@ -48,7 +47,7 @@ class _$ChildWithNullableSerializer implements PrimitiveSerializer<ChildWithNull
yield r'type';
yield serializers.serialize(
object.type,
specifiedType: const FullType(ParentWithNullableTypeEnum),
specifiedType: const FullType(String),
);
}
if (object.nullableProperty != null) {
@ -91,8 +90,8 @@ class _$ChildWithNullableSerializer implements PrimitiveSerializer<ChildWithNull
case r'type':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(ParentWithNullableTypeEnum),
) as ParentWithNullableTypeEnum;
specifiedType: const FullType(String),
) as String;
result.type = valueDes;
break;
case r'nullableProperty':
@ -139,18 +138,3 @@ class _$ChildWithNullableSerializer implements PrimitiveSerializer<ChildWithNull
}
}
class ChildWithNullableTypeEnum extends EnumClass {
@BuiltValueEnumConst(wireName: r'ChildWithNullable')
static const ChildWithNullableTypeEnum childWithNullable = _$childWithNullableTypeEnum_childWithNullable;
@BuiltValueEnumConst(wireName: r'unknown_default_open_api', fallback: true)
static const ChildWithNullableTypeEnum unknownDefaultOpenApi = _$childWithNullableTypeEnum_unknownDefaultOpenApi;
static Serializer<ChildWithNullableTypeEnum> get serializer => _$childWithNullableTypeEnumSerializer;
const ChildWithNullableTypeEnum._(String name): super(name);
static BuiltSet<ChildWithNullableTypeEnum> get values => _$childWithNullableTypeEnumValues;
static ChildWithNullableTypeEnum valueOf(String name) => _$childWithNullableTypeEnumValueOf(name);
}

View File

@ -3,7 +3,6 @@
//
// ignore_for_file: unused_element
import 'package:built_collection/built_collection.dart';
import 'package:openapi/src/model/child_with_nullable.dart';
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
@ -18,8 +17,7 @@ part 'parent_with_nullable.g.dart';
@BuiltValue(instantiable: false)
abstract class ParentWithNullable {
@BuiltValueField(wireName: r'type')
ParentWithNullableTypeEnum? get type;
// enum typeEnum { ChildWithNullable, };
String? get type;
@BuiltValueField(wireName: r'nullableProperty')
String? get nullableProperty;
@ -67,7 +65,7 @@ class _$ParentWithNullableSerializer implements PrimitiveSerializer<ParentWithNu
yield r'type';
yield serializers.serialize(
object.type,
specifiedType: const FullType(ParentWithNullableTypeEnum),
specifiedType: const FullType(String),
);
}
if (object.nullableProperty != null) {
@ -154,8 +152,8 @@ class _$$ParentWithNullableSerializer implements PrimitiveSerializer<$ParentWith
case r'type':
final valueDes = serializers.deserialize(
value,
specifiedType: const FullType(ParentWithNullableTypeEnum),
) as ParentWithNullableTypeEnum;
specifiedType: const FullType(String),
) as String;
result.type = valueDes;
break;
case r'nullableProperty':
@ -195,18 +193,3 @@ class _$$ParentWithNullableSerializer implements PrimitiveSerializer<$ParentWith
}
}
class ParentWithNullableTypeEnum extends EnumClass {
@BuiltValueEnumConst(wireName: r'ChildWithNullable')
static const ParentWithNullableTypeEnum childWithNullable = _$parentWithNullableTypeEnum_childWithNullable;
@BuiltValueEnumConst(wireName: r'unknown_default_open_api', fallback: true)
static const ParentWithNullableTypeEnum unknownDefaultOpenApi = _$parentWithNullableTypeEnum_unknownDefaultOpenApi;
static Serializer<ParentWithNullableTypeEnum> get serializer => _$parentWithNullableTypeEnumSerializer;
const ParentWithNullableTypeEnum._(String name): super(name);
static BuiltSet<ParentWithNullableTypeEnum> get values => _$parentWithNullableTypeEnumValues;
static ParentWithNullableTypeEnum valueOf(String name) => _$parentWithNullableTypeEnumValueOf(name);
}

View File

@ -18,7 +18,13 @@ class ChildWithNullable {
this.otherProperty,
});
ChildWithNullableTypeEnum? type;
///
/// 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.
///
String? type;
String? nullableProperty;
@ -85,7 +91,7 @@ class ChildWithNullable {
}());
return ChildWithNullable(
type: ChildWithNullableTypeEnum.fromJson(json[r'type']),
type: mapValueOfType<String>(json, r'type'),
nullableProperty: mapValueOfType<String>(json, r'nullableProperty'),
otherProperty: mapValueOfType<String>(json, r'otherProperty'),
);
@ -138,74 +144,3 @@ class ChildWithNullable {
};
}
class ChildWithNullableTypeEnum {
/// Instantiate a new enum with the provided [value].
const ChildWithNullableTypeEnum._(this.value);
/// The underlying value of this enum member.
final String value;
@override
String toString() => value;
String toJson() => value;
static const childWithNullable = ChildWithNullableTypeEnum._(r'ChildWithNullable');
/// List of all possible values in this [enum][ChildWithNullableTypeEnum].
static const values = <ChildWithNullableTypeEnum>[
childWithNullable,
];
static ChildWithNullableTypeEnum? fromJson(dynamic value) => ChildWithNullableTypeEnumTypeTransformer().decode(value);
static List<ChildWithNullableTypeEnum> listFromJson(dynamic json, {bool growable = false,}) {
final result = <ChildWithNullableTypeEnum>[];
if (json is List && json.isNotEmpty) {
for (final row in json) {
final value = ChildWithNullableTypeEnum.fromJson(row);
if (value != null) {
result.add(value);
}
}
}
return result.toList(growable: growable);
}
}
/// Transformation class that can [encode] an instance of [ChildWithNullableTypeEnum] to String,
/// and [decode] dynamic data back to [ChildWithNullableTypeEnum].
class ChildWithNullableTypeEnumTypeTransformer {
factory ChildWithNullableTypeEnumTypeTransformer() => _instance ??= const ChildWithNullableTypeEnumTypeTransformer._();
const ChildWithNullableTypeEnumTypeTransformer._();
String encode(ChildWithNullableTypeEnum data) => data.value;
/// Decodes a [dynamic value][data] to a ChildWithNullableTypeEnum.
///
/// 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.
ChildWithNullableTypeEnum? decode(dynamic data, {bool allowNull = true}) {
if (data != null) {
switch (data) {
case r'ChildWithNullable': return ChildWithNullableTypeEnum.childWithNullable;
default:
if (!allowNull) {
throw ArgumentError('Unknown enum value to decode: $data');
}
}
}
return null;
}
/// Singleton [ChildWithNullableTypeEnumTypeTransformer] instance.
static ChildWithNullableTypeEnumTypeTransformer? _instance;
}

View File

@ -17,7 +17,13 @@ class ParentWithNullable {
this.nullableProperty,
});
ParentWithNullableTypeEnum? type;
///
/// 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.
///
String? type;
String? nullableProperty;
@ -69,7 +75,7 @@ class ParentWithNullable {
}());
return ParentWithNullable(
type: ParentWithNullableTypeEnum.fromJson(json[r'type']),
type: mapValueOfType<String>(json, r'type'),
nullableProperty: mapValueOfType<String>(json, r'nullableProperty'),
);
}
@ -121,74 +127,3 @@ class ParentWithNullable {
};
}
class ParentWithNullableTypeEnum {
/// Instantiate a new enum with the provided [value].
const ParentWithNullableTypeEnum._(this.value);
/// The underlying value of this enum member.
final String value;
@override
String toString() => value;
String toJson() => value;
static const childWithNullable = ParentWithNullableTypeEnum._(r'ChildWithNullable');
/// List of all possible values in this [enum][ParentWithNullableTypeEnum].
static const values = <ParentWithNullableTypeEnum>[
childWithNullable,
];
static ParentWithNullableTypeEnum? fromJson(dynamic value) => ParentWithNullableTypeEnumTypeTransformer().decode(value);
static List<ParentWithNullableTypeEnum> listFromJson(dynamic json, {bool growable = false,}) {
final result = <ParentWithNullableTypeEnum>[];
if (json is List && json.isNotEmpty) {
for (final row in json) {
final value = ParentWithNullableTypeEnum.fromJson(row);
if (value != null) {
result.add(value);
}
}
}
return result.toList(growable: growable);
}
}
/// Transformation class that can [encode] an instance of [ParentWithNullableTypeEnum] to String,
/// and [decode] dynamic data back to [ParentWithNullableTypeEnum].
class ParentWithNullableTypeEnumTypeTransformer {
factory ParentWithNullableTypeEnumTypeTransformer() => _instance ??= const ParentWithNullableTypeEnumTypeTransformer._();
const ParentWithNullableTypeEnumTypeTransformer._();
String encode(ParentWithNullableTypeEnum data) => data.value;
/// Decodes a [dynamic value][data] to a ParentWithNullableTypeEnum.
///
/// 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.
ParentWithNullableTypeEnum? decode(dynamic data, {bool allowNull = true}) {
if (data != null) {
switch (data) {
case r'ChildWithNullable': return ParentWithNullableTypeEnum.childWithNullable;
default:
if (!allowNull) {
throw ArgumentError('Unknown enum value to decode: $data');
}
}
}
return null;
}
/// Singleton [ParentWithNullableTypeEnumTypeTransformer] instance.
static ParentWithNullableTypeEnumTypeTransformer? _instance;
}