Browse Source

refactor(dynamite): unify resolvedTypes and resolvedTypeCombinations

pull/501/head
Nikolas Rimikis 1 year ago
parent
commit
7a71e010b6
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 21
      packages/dynamite/dynamite/lib/src/openapi_builder.dart

21
packages/dynamite/dynamite/lib/src/openapi_builder.dart

@ -710,13 +710,10 @@ class OpenAPIBuilder implements Builder {
output.addAll(state.output.map((final e) => e.accept(emitter).toString()));
if (state.resolvedTypeCombinations.isNotEmpty) {
if (state.resolvedTypes.isNotEmpty) {
output.addAll([
'final Serializers _serializers = (Serializers().toBuilder()',
...state.resolvedTypeCombinations
.map((final type) => type.serializers)
.expand((final element) => element)
.toSet(),
...state.resolvedTypes.map((final type) => type.serializers).expand((final element) => element).toSet(),
').build();',
'',
'Serializers get ${variablePrefix}Serializers => _serializers;',
@ -926,9 +923,8 @@ class State {
State(this.prefix);
final String prefix;
final resolvedTypes = <String>{};
final output = <Spec>[];
final resolvedTypeCombinations = <TypeResult>{};
final resolvedTypes = <TypeResult>{};
}
TypeResult resolveObject(
@ -940,8 +936,7 @@ TypeResult resolveObject(
final bool nullable = false,
final bool isHeader = false,
}) {
if (!state.resolvedTypes.contains('${state.prefix}$identifier')) {
state.resolvedTypes.add('${state.prefix}$identifier');
if (state.resolvedTypes.add(TypeResultObject('${state.prefix}$identifier'))) {
state.output.add(
Class(
(final b) {
@ -1268,8 +1263,7 @@ TypeResult resolveType(
nullable: nullable,
);
} else if (schema.ofs != null) {
if (!state.resolvedTypes.contains('${state.prefix}$identifier')) {
state.resolvedTypes.add('${state.prefix}$identifier');
if (state.resolvedTypes.add(TypeResultObject('${state.prefix}$identifier'))) {
final results = schema.ofs!
.map(
(final s) => resolveType(
@ -1659,8 +1653,7 @@ TypeResult resolveType(
if (result != null) {
if (!ignoreEnum && schema.enum_ != null) {
if (!state.resolvedTypes.contains('${state.prefix}$identifier')) {
state.resolvedTypes.add('${state.prefix}$identifier');
if (state.resolvedTypes.add(TypeResultEnum('${state.prefix}$identifier', result))) {
state.output.add(
Class(
(final b) => b
@ -1764,7 +1757,7 @@ TypeResult resolveType(
);
}
state.resolvedTypeCombinations.add(result);
state.resolvedTypes.add(result);
return result;
}

Loading…
Cancel
Save