|
|
@ -356,40 +356,37 @@ class OpenAPIBuilder implements Builder { |
|
|
|
b.annotations.add(refer('Deprecated').call([refer("''")])); |
|
|
|
b.annotations.add(refer('Deprecated').call([refer("''")])); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
final acceptHeader = operation.responses?.values |
|
|
|
final acceptHeader = (operation.responses?.values |
|
|
|
.map((final response) => response.content?.keys) |
|
|
|
.map((final response) => response.content?.keys) |
|
|
|
.reduce((final a, final b) => [...?a, ...?b]) |
|
|
|
.whereNotNull() |
|
|
|
?.toSet() |
|
|
|
.expand((final element) => element) |
|
|
|
|
|
|
|
.toSet() ?? |
|
|
|
|
|
|
|
{}) |
|
|
|
.join(','); |
|
|
|
.join(','); |
|
|
|
final code = StringBuffer(''' |
|
|
|
final code = StringBuffer(''' |
|
|
|
var path = '$path'; |
|
|
|
var path = '$path'; |
|
|
|
final queryParameters = <String, dynamic>{}; |
|
|
|
final queryParameters = <String, dynamic>{}; |
|
|
|
final headers = <String, String>{${acceptHeader != null ? "'Accept': '$acceptHeader'," : ''}}; |
|
|
|
final headers = <String, String>{${acceptHeader.isNotEmpty ? "'Accept': '$acceptHeader'," : ''}}; |
|
|
|
Uint8List? body; |
|
|
|
Uint8List? body; |
|
|
|
'''); |
|
|
|
'''); |
|
|
|
|
|
|
|
|
|
|
|
final securityRequirements = |
|
|
|
final security = operation.security ?? spec.security ?? []; |
|
|
|
(operation.security ?? spec.security) ?? <Map<String, List<String>>>[]; |
|
|
|
final securityRequirements = security.where((final requirement) => requirement.isNotEmpty); |
|
|
|
final isOptionalSecurity = |
|
|
|
final isOptionalSecurity = securityRequirements.length != security.length; |
|
|
|
securityRequirements.where((final requirement) => requirement.keys.isEmpty).isNotEmpty; |
|
|
|
|
|
|
|
for (final requirement in securityRequirements) { |
|
|
|
for (final requirement in securityRequirements) { |
|
|
|
if (requirement.keys.isEmpty) { |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
final securityScheme = spec.components!.securitySchemes![requirement.keys.single]!; |
|
|
|
final securityScheme = spec.components!.securitySchemes![requirement.keys.single]!; |
|
|
|
code.write(''' |
|
|
|
code.write(''' |
|
|
|
if (${isRootClient ? '' : 'rootClient.'}authentications.where((final a) => a.type == '${securityScheme.type}' && a.scheme == '${securityScheme.scheme}').isNotEmpty) { |
|
|
|
if (${isRootClient ? '' : 'rootClient.'}authentications.where((final a) => a.type == '${securityScheme.type}' && a.scheme == '${securityScheme.scheme}').isNotEmpty) { |
|
|
|
headers.addAll(${isRootClient ? '' : 'rootClient.'}authentications.singleWhere((final a) => a.type == '${securityScheme.type}' && a.scheme == '${securityScheme.scheme}').headers); |
|
|
|
headers.addAll(${isRootClient ? '' : 'rootClient.'}authentications.singleWhere((final a) => a.type == '${securityScheme.type}' && a.scheme == '${securityScheme.scheme}').headers); |
|
|
|
} |
|
|
|
} |
|
|
|
'''); |
|
|
|
'''); |
|
|
|
if (!isOptionalSecurity || |
|
|
|
if (securityRequirements.last != requirement) { |
|
|
|
securityRequirements.indexOf(requirement) != securityRequirements.length - 1) { |
|
|
|
|
|
|
|
code.write('else'); |
|
|
|
code.write('else'); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (securityRequirements.isNotEmpty && !isOptionalSecurity) { |
|
|
|
if (securityRequirements.isNotEmpty && !isOptionalSecurity) { |
|
|
|
code.write(''' |
|
|
|
code.write(''' |
|
|
|
{ |
|
|
|
else { |
|
|
|
throw Exception('Missing authentication for ${securityRequirements.map((final r) => r.keys.single).join(' or ')}'); // coverage:ignore-line |
|
|
|
throw Exception('Missing authentication for ${securityRequirements.map((final r) => r.keys.single).join(' or ')}'); // coverage:ignore-line |
|
|
|
} |
|
|
|
} |
|
|
|
'''); |
|
|
|
'''); |
|
|
|