Browse Source

Merge pull request #233 from provokateurin/fix/optional-security

dynamite: Fix optional security
pull/234/head
Kate 2 years ago committed by GitHub
parent
commit
c3ac8e1bbd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  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