Skip to content

Commit

Permalink
Merge pull request #1207 from nextcloud/refactor/dynamite/remove_cust…
Browse files Browse the repository at this point in the history
…om_header_serializers
  • Loading branch information
Leptopoda authored Nov 30, 2023
2 parents fdcbc16 + 18049b3 commit 405636c
Show file tree
Hide file tree
Showing 17 changed files with 1,190 additions and 1,174 deletions.
139 changes: 0 additions & 139 deletions packages/dynamite/dynamite/lib/src/builder/header_serializer.dart

This file was deleted.

17 changes: 10 additions & 7 deletions packages/dynamite/dynamite/lib/src/builder/resolve_object.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:built_collection/built_collection.dart';
import 'package:code_builder/code_builder.dart';
import 'package:dynamite/src/builder/header_serializer.dart';
import 'package:dynamite/src/builder/resolve_interface.dart';
import 'package:dynamite/src/builder/resolve_type.dart';
import 'package:dynamite/src/builder/state.dart';
Expand Down Expand Up @@ -41,7 +40,7 @@ TypeResultObject resolveObject(
final propertySchema = property.value;
final dartName = toDartName(propertyName);

final result = resolveType(
var result = resolveType(
spec,
state,
'${identifier}_${toDartName(propertyName, uppercaseFirstCharacter: true)}',
Expand All @@ -52,6 +51,15 @@ TypeResultObject resolveObject(
),
);

if (isHeader && result.className != 'String') {
result = TypeResultObject(
'ContentString',
generics: [result],
nullable: result.nullable,
);
state.resolvedTypes.add(result);
}

final method = generateProperty(
result,
propertyName,
Expand All @@ -76,17 +84,12 @@ TypeResultObject resolveObject(
identifier,
defaults: defaults.build(),
validators: validators.build(),
customSerializer: isHeader,
);

state.output.addAll([
$interface,
$class,
]);

if (isHeader) {
state.output.add(buildHeaderSerializer(state, identifier, spec, schema));
}
}
return result;
}
126 changes: 3 additions & 123 deletions packages/dynamite/dynamite_end_to_end_test/lib/headers.openapi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -201,47 +201,7 @@ abstract class GetHeaders implements $GetHeadersInterface, Built<GetHeaders, Get

Map<String, dynamic> toJson() => _jsonSerializers.serializeWith(serializer, this)! as Map<String, dynamic>;

@BuiltValueSerializer(custom: true)
static Serializer<GetHeaders> get serializer => _$GetHeadersSerializer();
}

class _$GetHeadersSerializer implements StructuredSerializer<GetHeaders> {
@override
final Iterable<Type> types = const [GetHeaders, _$GetHeaders];

@override
final String wireName = 'GetHeaders';

@override
Iterable<Object?> serialize(
final Serializers serializers,
final GetHeaders object, {
final FullType specifiedType = FullType.unspecified,
}) {
throw UnimplementedError();
}

@override
GetHeaders deserialize(
final Serializers serializers,
final Iterable<Object?> serialized, {
final FullType specifiedType = FullType.unspecified,
}) {
final result = GetHeadersBuilder();

final iterator = serialized.iterator;
while (iterator.moveNext()) {
final key = iterator.current! as String;
iterator.moveNext();
final value = iterator.current! as String;
switch (key) {
case 'my-header':
result.myHeader = value;
}
}

return result.build();
}
static Serializer<GetHeaders> get serializer => _$getHeadersSerializer;
}

@BuiltValue(instantiable: false)
Expand All @@ -264,47 +224,7 @@ abstract class WithContentOperationIdHeaders

Map<String, dynamic> toJson() => _jsonSerializers.serializeWith(serializer, this)! as Map<String, dynamic>;

@BuiltValueSerializer(custom: true)
static Serializer<WithContentOperationIdHeaders> get serializer => _$WithContentOperationIdHeadersSerializer();
}

class _$WithContentOperationIdHeadersSerializer implements StructuredSerializer<WithContentOperationIdHeaders> {
@override
final Iterable<Type> types = const [WithContentOperationIdHeaders, _$WithContentOperationIdHeaders];

@override
final String wireName = 'WithContentOperationIdHeaders';

@override
Iterable<Object?> serialize(
final Serializers serializers,
final WithContentOperationIdHeaders object, {
final FullType specifiedType = FullType.unspecified,
}) {
throw UnimplementedError();
}

@override
WithContentOperationIdHeaders deserialize(
final Serializers serializers,
final Iterable<Object?> serialized, {
final FullType specifiedType = FullType.unspecified,
}) {
final result = WithContentOperationIdHeadersBuilder();

final iterator = serialized.iterator;
while (iterator.moveNext()) {
final key = iterator.current! as String;
iterator.moveNext();
final value = iterator.current! as String;
switch (key) {
case 'my-header':
result.myHeader = value;
}
}

return result.build();
}
static Serializer<WithContentOperationIdHeaders> get serializer => _$withContentOperationIdHeadersSerializer;
}

@BuiltValue(instantiable: false)
Expand All @@ -324,47 +244,7 @@ abstract class GetWithContentHeaders

Map<String, dynamic> toJson() => _jsonSerializers.serializeWith(serializer, this)! as Map<String, dynamic>;

@BuiltValueSerializer(custom: true)
static Serializer<GetWithContentHeaders> get serializer => _$GetWithContentHeadersSerializer();
}

class _$GetWithContentHeadersSerializer implements StructuredSerializer<GetWithContentHeaders> {
@override
final Iterable<Type> types = const [GetWithContentHeaders, _$GetWithContentHeaders];

@override
final String wireName = 'GetWithContentHeaders';

@override
Iterable<Object?> serialize(
final Serializers serializers,
final GetWithContentHeaders object, {
final FullType specifiedType = FullType.unspecified,
}) {
throw UnimplementedError();
}

@override
GetWithContentHeaders deserialize(
final Serializers serializers,
final Iterable<Object?> serialized, {
final FullType specifiedType = FullType.unspecified,
}) {
final result = GetWithContentHeadersBuilder();

final iterator = serialized.iterator;
while (iterator.moveNext()) {
final key = iterator.current! as String;
iterator.moveNext();
final value = iterator.current! as String;
switch (key) {
case 'my-header':
result.myHeader = value;
}
}

return result.build();
}
static Serializer<GetWithContentHeaders> get serializer => _$getWithContentHeadersSerializer;
}

// coverage:ignore-start
Expand Down
Loading

0 comments on commit 405636c

Please sign in to comment.