Browse Source

dynamite: Fix optional security

pull/233/head
jld3103 2 years ago
parent
commit
6c9a2bb572
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 19
      packages/dynamite/lib/src/openapi_builder.dart

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

@ -675,28 +675,27 @@ class OpenAPIBuilder implements Builder {
(operation.security ?? spec.security) ?? <Map<String, List<String>>>[];
final isOptionalSecurity =
securityRequirements.where((final requirement) => requirement.keys.isEmpty).isNotEmpty;
if (isOptionalSecurity) {
code.write('''
if (${isRootClient ? '' : 'rootClient.'}authentications.isNotEmpty) {
headers.addAll(${isRootClient ? '' : 'rootClient.'}authentications.first.headers);
}
''');
} else {
for (final requirement in securityRequirements) {
if (requirement.keys.isEmpty) {
continue;
}
code.write('''
if (${isRootClient ? '' : 'rootClient.'}authentications.map((final a) => a.id).contains('${requirement.keys.single}')) {
headers.addAll(${isRootClient ? '' : 'rootClient.'}authentications.singleWhere((final a) => a.id == '${requirement.keys.single}').headers);
} else
}
''');
if (!isOptionalSecurity ||
securityRequirements.indexOf(requirement) != securityRequirements.length - 1) {
code.write('else');
}
if (securityRequirements.isNotEmpty) {
}
if (securityRequirements.isNotEmpty && !isOptionalSecurity) {
code.write('''
{
throw Exception('Missing authentication for ${securityRequirements.map((final r) => r.keys.single).join(' or ')}');
}
''');
}
}
for (final parameter in parameters) {
final nullable = _isParameterNullable(

Loading…
Cancel
Save