Skip to content
Merged
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
15 changes: 9 additions & 6 deletions .github/workflows/samples-dart-build-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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/**
Expand All @@ -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/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@ class ChildWithNullable {
name: r'type',
required: false,
includeIfNull: false,
unknownEnumValue: ChildWithNullableTypeEnum.unknownDefaultOpenApi,
)


final ChildWithNullableTypeEnum? type;
final String? type;



Expand Down Expand Up @@ -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;
}


Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ class ParentWithNullable {
name: r'type',
required: false,
includeIfNull: false,
unknownEnumValue: ParentWithNullableTypeEnum.unknownDefaultOpenApi,
)


final ParentWithNullableTypeEnum? type;
final String? type;



Expand Down Expand Up @@ -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;
}


Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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':
Expand Down Expand Up @@ -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);
}

Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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':
Expand Down Expand Up @@ -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);
}

Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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'),
);
Expand Down Expand Up @@ -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;
}


Loading
Loading