Skip to content

Commit

Permalink
fix(dynamite): fix header name generation with empty operationID
Browse files Browse the repository at this point in the history
Signed-off-by: Nikolas Rimikis <[email protected]>
  • Loading branch information
Leptopoda committed Oct 27, 2023
1 parent f78feb1 commit 79e2f5e
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions packages/dynamite/dynamite/lib/src/builder/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -183,19 +183,19 @@ Iterable<Method> buildTags(
for (final operationEntry in pathEntry.value.operations.entries) {
final httpMethod = operationEntry.key.name;
final operation = operationEntry.value;
final operationId = operation.operationId ?? toDartName('$httpMethod-${pathEntry.key}');
final operationName = operation.operationId ?? toDartName('$httpMethod-${pathEntry.key}');
final parameters = [
...?pathEntry.value.parameters,
...?operation.parameters,
]..sort(sortRequiredParameters);
final name = toDartName(filterMethodName(operationId, tag ?? ''));
final name = toDartName(filterMethodName(operationName, tag ?? ''));

var responses = <openapi.Response, List<int>>{};
if (operation.responses != null) {
for (final responseEntry in operation.responses!.entries) {
final statusCode = int.tryParse(responseEntry.key);
if (statusCode == null) {
print('Default responses are not supported right now. Skipping it for $operationId');
print('Default responses are not supported right now. Skipping it for $operationName');
continue;
}
final response = responseEntry.value;
Expand All @@ -205,7 +205,7 @@ Iterable<Method> buildTags(
}

if (responses.length > 1) {
print('$operationId uses more than one response schema but we only generate the first one');
print('$operationName uses more than one response schema but we only generate the first one');
responses = Map.fromEntries([responses.entries.first]);
}
}
Expand Down Expand Up @@ -251,7 +251,7 @@ Iterable<Method> buildTags(
spec,
state,
toDartName(
'$operationId-${parameter.name}',
'$operationName-${parameter.name}',
uppercaseFirstCharacter: true,
),
parameter.schema!,
Expand All @@ -277,20 +277,26 @@ Iterable<Method> buildTags(
buildPatternCheck(result, parameter).forEach(code.writeln);
buildParameterSerialization(result, parameter).forEach(code.writeln);
}
resolveMimeTypeEncode(operation, spec, state, operationId, operationParameters).forEach(code.writeln);
resolveMimeTypeEncode(operation, spec, state, operationName, operationParameters).forEach(code.writeln);

for (final responseEntry in responses.entries) {
final response = responseEntry.key;
final statusCodes = responseEntry.value;

TypeResult? headersType;

if (response.headers != null) {
final identifier =
'${tag != null ? toDartName(tag, uppercaseFirstCharacter: true) : null}${toDartName(operationId, uppercaseFirstCharacter: true)}Headers';
final identifierBuilder = StringBuffer();
if (tag != null) {
identifierBuilder.write(toDartName(tag, uppercaseFirstCharacter: true));
}
identifierBuilder
..write(toDartName(operationName, uppercaseFirstCharacter: true))
..write('Headers');
headersType = resolveObject(
spec,
state,
identifier,
identifierBuilder.toString(),
openapi.Schema(
(final b) => b
..properties.replace(
Expand All @@ -306,14 +312,20 @@ Iterable<Method> buildTags(
);
}

final identifierBuilder = StringBuffer()
..write(operationName)
..write('-response');
if (responses.entries.length > 1) {
identifierBuilder
..write('-')
..write(responses.entries.toList().indexOf(responseEntry));
}

final dataType = resolveMimeTypeDecode(
response,
spec,
state,
toDartName(
'$operationId-response${responses.entries.length > 1 ? '-${responses.entries.toList().indexOf(responseEntry)}' : ''}',
uppercaseFirstCharacter: true,
),
toDartName(identifierBuilder.toString(), uppercaseFirstCharacter: true),
);

var path = pathEntry.key;
Expand Down

0 comments on commit 79e2f5e

Please sign in to comment.