Skip to content

Commit

Permalink
async changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmednfwela committed Aug 2, 2023
1 parent c9fb20e commit f5236ef
Show file tree
Hide file tree
Showing 129 changed files with 1,378 additions and 534 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ public String getTypeDeclaration(Schema p) {
if (ModelUtils.isMapSchema(target)) {
// Note: ModelUtils.isMapSchema(p) returns true when p is a composed schema that also defines
// additionalproperties: true
Schema<?> inner = getAdditionalProperties(target);
Schema<?> inner = ModelUtils.getAdditionalProperties(target);
if (inner == null) {
LOGGER.error("`{}` (map property) does not have a proper inner type defined. Default to type:string", p.getName());
inner = new StringSchema().description("TODO default missing map inner type to string");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -740,8 +740,8 @@ private void adaptToDartInheritance(Map<String, ModelsMap> objs) {
/// setLegacyDiscriminatorBehavior(false)
/// this ensures 1-1 schema mapping instead of 1-many
@Override
protected CodegenDiscriminator createDiscriminator(String schemaName, Schema schema, OpenAPI openAPI) {
CodegenDiscriminator sub = super.createDiscriminator(schemaName, schema, openAPI);
protected CodegenDiscriminator createDiscriminator(String schemaName, Schema schema) {
CodegenDiscriminator sub = super.createDiscriminator(schemaName, schema);
Discriminator originalDiscriminator = schema.getDiscriminator();
if (originalDiscriminator != null) {
Map<String, String> originalMapping = originalDiscriminator.getMapping();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class {{classname}} {
{{#hasFormParams}}
final _bodyMap = <String, dynamic>{
{{#formParams}}
{{^required}}if ({{{paramName}}} != null) {{/required}}r'{{{baseName}}}': encodeFormParameter(_repository, {{{paramName}}}, {{>types/recursion_type_info}}),
{{^required}}if ({{{paramName}}} != null) {{/required}}r'{{{baseName}}}': await encodeFormParameter(_repository, {{{paramName}}}, {{>types/recursion_type_info}}),
{{/formParams}}
};
{{#isMultipart}}
Expand All @@ -54,15 +54,15 @@ class {{classname}} {
{{/isMultipart}}
{{/hasFormParams}}
{{#bodyParam}}
_bodyData = encodeBodyParameter(_repository, {{{paramName}}}, {{>types/recursion_type_info}});
_bodyData = await encodeBodyParameter(_repository, {{{paramName}}}, {{>types/recursion_type_info}});
{{/bodyParam}}
{{/hasBodyOrFormParams}}

final _response = await rawApi.{{nickname}}(
{{#allParams}}{{#isPathParam}}
{{paramName}}: encodeStringParameter(_repository, {{paramName}}, {{>types/recursion_type_info}}),{{/isPathParam}}{{#isQueryParam}}
{{paramName}}: encodeQueryParameter(_repository, {{paramName}}, {{>types/recursion_type_info}}, {{#collectionFormat}}format: ListFormat.{{.}},{{/collectionFormat}}),{{/isQueryParam}}{{#isHeaderParam}}
{{paramName}}: encodeStringParameter(_repository, {{paramName}}, {{>types/recursion_type_info}}), {{/isHeaderParam}}{{/allParams}}
{{paramName}}: await encodeStringParameter(_repository, {{paramName}}, {{>types/recursion_type_info}}),{{/isPathParam}}{{#isQueryParam}}
{{paramName}}: await encodeQueryParameter(_repository, {{paramName}}, {{>types/recursion_type_info}}, {{#collectionFormat}}format: ListFormat.{{.}},{{/collectionFormat}}),{{/isQueryParam}}{{#isHeaderParam}}
{{paramName}}: await encodeStringParameter(_repository, {{paramName}}, {{>types/recursion_type_info}}), {{/isHeaderParam}}{{/allParams}}
{{#hasConsumes}}
body: _bodyData,
requestContentType: '{{#prioritizedContentTypes}}{{#-first}}{{{mediaType}}}{{/-first}}{{/prioritizedContentTypes}}',{{/hasConsumes}}
Expand All @@ -83,7 +83,7 @@ class {{classname}} {
try {
final rawResponse = _response.data;
{{#returnProperty}}
_responseData = rawResponse == null ? null : decodeResponse(_repository, rawResponse, {{>types/recursion_type_info}});
_responseData = rawResponse == null ? null : await decodeResponse(_repository, rawResponse, {{>types/recursion_type_info}});
{{/returnProperty}}
} catch (error, stackTrace) {
throw DioException(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,57 +1,48 @@
import 'package:dio/dio.dart';
import 'dart:async';
import 'dart:convert';
import 'package:openapi/models.dart';
import 'dart:typed_data';

/// Format the given form parameter object into something that Dio can handle.
/// Returns primitive or String.
/// Returns List/Map if the value is BuildList/BuiltMap.
Object encodeFormParameter<T>(
Future<Object?> encodeFormParameter<T extends Object?>(
SerializationRepositoryBase repository,
T value,
TypeInfo type,
) {
if (value == null) {
return '';
}
final serialized = repository.serialize(
value,
type,
);
return serialized;
) async {
return repository.serialize(
value,
type,
);
}

String encodeStringParameter<T>(
Future<String?> encodeStringParameter<T extends Object?>(
SerializationRepositoryBase repository,
T value,
TypeInfo type,
) {
return repository.serialize(value, type).toString();
) async {
return (await repository.serialize(value, type)).toString();
}

Object encodeBodyParameter<T>(
Future<Object?> encodeBodyParameter<T extends Object?>(
SerializationRepositoryBase repository,
T value,
TypeInfo type,
) {
if (value == null) {
return '';
}
final serialized = repository.serialize(
) async {
return await repository.serialize(
value,
type,
);
return serialized;
);
}

Object encodeQueryParameter<T>(
Future<Object?> encodeQueryParameter<T extends Object?>(
SerializationRepositoryBase repository,
T value,
TypeInfo type, {
ListFormat format = ListFormat.multi,
}) {
}) async {
if (value == null) {
return '';
return null;
}
if (value is String || value is num || value is bool) {
return value;
Expand All @@ -67,22 +58,25 @@ Object encodeQueryParameter<T>(
return serialized;
}

ListParam<Object?> encodeCollectionQueryParameter<T>(
Future<ListParam<Object?>> encodeCollectionQueryParameter<T extends Object?>(
SerializationRepositoryBase repository,
Iterable<T> value,
TypeInfo type, {
ListFormat format = ListFormat.multi,
}) {
final serialized = repository.serialize(
}) async {
final serialized = await repository.serialize(
value,
type,
);
if (serialized == null) {
return ListParam([], format);
}
if (serialized is Iterable) {
return ListParam(serialized.toList(), format);
}
throw ArgumentError('Invalid value passed to encodeCollectionQueryParameter');
}

TOutput decodeResponse<TOutput, TInput extends Object>(SerializationRepositoryBase repository, TInput value, TypeInfo type) {
return repository.deserialize(value, type);
Future<TOutput?> decodeResponse<TOutput, TInput extends Object>(SerializationRepositoryBase repository, TInput value, TypeInfo type) async {
return await repository.deserialize(value, type);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{>header}}

import 'dart:async';
import 'dart:convert';
import 'dart:typed_data';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:convert';
import 'dart:async';
import 'dart:typed_data';
import 'repository_base.dart';
import 'package:{{pubName}}/models.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:async';

/// The general rule for implementing this class is
/// json == serialize<T>(deserialize<T>(json))
/// object == deserialize<T>(serialize<T>(object))
Expand All @@ -6,8 +8,8 @@
abstract class SerializationRepositoryBase {
const SerializationRepositoryBase();
FutureOr<Object?> serialize<T>(T src, TypeInfo inputTypeInfo, {Object? context,});
FutureOr<T> deserialize<T>(Object? value, TypeInfo targetTypeInfo, {Object? context,});
FutureOr<Object?> serialize<T extends Object?>(T src, TypeInfo inputTypeInfo, {Object? context,});
FutureOr<T> deserialize<T extends Object?>(Object? value, TypeInfo targetTypeInfo, {Object? context,});
}

/// A modified version of `built_value`'s `FullType` class, found here
Expand Down
109 changes: 109 additions & 0 deletions samples/client/echo_api/dart/dio/built_value/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,112 @@ lib/src/repository_base.dart
lib/src/repository_impl.dart
lib/src/serializers.dart
pubspec.yaml
test/additional_properties_class_test.dart
test/addressable_test.dart
test/all_of_with_single_ref_test.dart
test/animal_test.dart
test/another_fake_api_test.dart
test/api_response_test.dart
test/apple_all_of_disc_test.dart
test/apple_grandparent_disc_test.dart
test/apple_one_of_disc_test.dart
test/apple_req_disc_test.dart
test/apple_test.dart
test/apple_variant1_test.dart
test/array_of_array_of_number_only_test.dart
test/array_of_number_only_test.dart
test/array_test_test.dart
test/banana_all_of_disc_test.dart
test/banana_grandparent_disc_test.dart
test/banana_one_of_disc_test.dart
test/banana_req_disc_test.dart
test/banana_test.dart
test/bar_api_test.dart
test/bar_create_test.dart
test/bar_ref_or_value_test.dart
test/bar_ref_test.dart
test/bar_test.dart
test/capitalization_test.dart
test/cat_test.dart
test/category_test.dart
test/class_model_test.dart
test/composed_disc_missing_from_properties_test.dart
test/composed_disc_optional_type_correct_test.dart
test/composed_disc_optional_type_inconsistent_test.dart
test/composed_disc_optional_type_incorrect_test.dart
test/composed_disc_required_inconsistent_test.dart
test/composed_disc_type_inconsistent_test.dart
test/composed_disc_type_incorrect_test.dart
test/default_api_test.dart
test/deprecated_object_test.dart
test/disc_missing_from_properties_test.dart
test/disc_optional_type_correct_test.dart
test/disc_optional_type_incorrect_test.dart
test/disc_type_incorrect_test.dart
test/dog_test.dart
test/entity_ref_test.dart
test/entity_test.dart
test/enum_arrays_test.dart
test/enum_test_test.dart
test/extensible_test.dart
test/fake_api_test.dart
test/fake_classname_tags123_api_test.dart
test/file_schema_test_class_test.dart
test/foo_api_test.dart
test/foo_basic_get_default_response_test.dart
test/foo_ref_or_value_test.dart
test/foo_ref_test.dart
test/foo_test.dart
test/format_test_test.dart
test/fruit_all_of_disc_test.dart
test/fruit_any_of_disc_test.dart
test/fruit_grandparent_disc_test.dart
test/fruit_inline_disc_one_of1_test.dart
test/fruit_inline_disc_one_of_test.dart
test/fruit_inline_disc_test.dart
test/fruit_inline_inline_disc_one_of1_test.dart
test/fruit_inline_inline_disc_one_of_one_of_test.dart
test/fruit_inline_inline_disc_one_of_test.dart
test/fruit_inline_inline_disc_test.dart
test/fruit_one_of_disc_test.dart
test/fruit_req_disc_test.dart
test/fruit_test.dart
test/fruit_type_test.dart
test/fruit_variant1_test.dart
test/giga_one_of_test.dart
test/grape_variant1_test.dart
test/has_only_read_only_test.dart
test/health_check_result_test.dart
test/map_test_test.dart
test/mixed_properties_and_additional_properties_class_test.dart
test/model200_response_test.dart
test/model_client_test.dart
test/model_enum_class_test.dart
test/model_file_test.dart
test/model_list_test.dart
test/model_return_test.dart
test/name_test.dart
test/nullable_class_test.dart
test/number_only_test.dart
test/object_with_deprecated_fields_test.dart
test/one_of_primitive_child_test.dart
test/order_test.dart
test/outer_composite_test.dart
test/outer_enum_default_value_test.dart
test/outer_enum_integer_default_value_test.dart
test/outer_enum_integer_test.dart
test/outer_enum_test.dart
test/outer_object_with_enum_property_test.dart
test/parent_test.dart
test/pasta_test.dart
test/pet_api_test.dart
test/pet_test.dart
test/pizza_speziale_test.dart
test/pizza_test.dart
test/read_only_first_test.dart
test/single_ref_type_test.dart
test/special_model_name_test.dart
test/store_api_test.dart
test/tag_test.dart
test/user_api_test.dart
test/user_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import 'package:openapi/src/api_util.dart';
import 'package:openapi/models.dart';
import 'package:openapi/src/model/model_client.dart';

part 'another_fake_api.g.dart';

class AnotherFakeApi {

Expand Down Expand Up @@ -45,7 +44,7 @@ class AnotherFakeApi {
ProgressCallback? onReceiveProgress,
}) async {
Object? _bodyData;
_bodyData = encodeBodyParameter(_repository, modelClient, const TypeInfo(
_bodyData = await encodeBodyParameter(_repository, modelClient, const TypeInfo(


ModelClient
Expand All @@ -69,7 +68,7 @@ class AnotherFakeApi {

try {
final rawResponse = _response.data;
_responseData = rawResponse == null ? null : decodeResponse(_repository, rawResponse, const TypeInfo(
_responseData = rawResponse == null ? null : await decodeResponse(_repository, rawResponse, const TypeInfo(

ModelClient

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import 'package:openapi/models.dart';
import 'package:openapi/src/model/bar.dart';
import 'package:openapi/src/model/bar_create.dart';

part 'bar_api.g.dart';

class BarApi {

Expand Down Expand Up @@ -46,7 +45,7 @@ class BarApi {
ProgressCallback? onReceiveProgress,
}) async {
Object? _bodyData;
_bodyData = encodeBodyParameter(_repository, barCreate, const TypeInfo(
_bodyData = await encodeBodyParameter(_repository, barCreate, const TypeInfo(


BarCreate
Expand All @@ -70,7 +69,7 @@ class BarApi {

try {
final rawResponse = _response.data;
_responseData = rawResponse == null ? null : decodeResponse(_repository, rawResponse, const TypeInfo(
_responseData = rawResponse == null ? null : await decodeResponse(_repository, rawResponse, const TypeInfo(

Bar

Expand Down
Loading

0 comments on commit f5236ef

Please sign in to comment.