|
|
|
@ -173,137 +173,6 @@ class OpenAPIBuilder implements Builder {
|
|
|
|
|
).accept(emitter).toString(), |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
if (spec.components?.securitySchemes != null) { |
|
|
|
|
for (final name in spec.components!.securitySchemes!.keys) { |
|
|
|
|
final securityScheme = spec.components!.securitySchemes![name]!; |
|
|
|
|
switch (securityScheme.type) { |
|
|
|
|
case 'http': |
|
|
|
|
switch (securityScheme.scheme) { |
|
|
|
|
case 'basic': |
|
|
|
|
output.add( |
|
|
|
|
Class( |
|
|
|
|
(final b) { |
|
|
|
|
final fields = ['username', 'password']; |
|
|
|
|
b |
|
|
|
|
..name = '${prefix}HttpBasicAuthentication' |
|
|
|
|
..extend = refer('DynamiteAuthentication') |
|
|
|
|
..constructors.add( |
|
|
|
|
Constructor( |
|
|
|
|
(final b) => b |
|
|
|
|
..optionalParameters.addAll( |
|
|
|
|
fields.map( |
|
|
|
|
(final name) => Parameter( |
|
|
|
|
(final b) => b |
|
|
|
|
..name = name |
|
|
|
|
..toThis = true |
|
|
|
|
..named = true |
|
|
|
|
..required = true, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
) |
|
|
|
|
..fields.addAll( |
|
|
|
|
fields.map( |
|
|
|
|
(final name) => Field( |
|
|
|
|
(final b) => b |
|
|
|
|
..name = name |
|
|
|
|
..type = refer('String') |
|
|
|
|
..modifier = FieldModifier.final$, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
) |
|
|
|
|
..methods.addAll([ |
|
|
|
|
Method( |
|
|
|
|
(final b) => b |
|
|
|
|
..name = 'id' |
|
|
|
|
..annotations.add(refer('override')) |
|
|
|
|
..type = MethodType.getter |
|
|
|
|
..lambda = true |
|
|
|
|
..returns = refer('String') |
|
|
|
|
..body = Code("'$name'"), |
|
|
|
|
), |
|
|
|
|
Method( |
|
|
|
|
(final b) => b |
|
|
|
|
..name = 'headers' |
|
|
|
|
..annotations.add(refer('override')) |
|
|
|
|
..type = MethodType.getter |
|
|
|
|
..returns = refer('Map<String, String>') |
|
|
|
|
..lambda = true |
|
|
|
|
..body = const Code(r''' |
|
|
|
|
{ |
|
|
|
|
'Authorization': 'Basic ${base64.encode(utf8.encode('$username:$password'))}', |
|
|
|
|
} |
|
|
|
|
'''), |
|
|
|
|
), |
|
|
|
|
]); |
|
|
|
|
}, |
|
|
|
|
).accept(emitter).toString(), |
|
|
|
|
); |
|
|
|
|
continue; |
|
|
|
|
case 'bearer': |
|
|
|
|
output.add( |
|
|
|
|
Class( |
|
|
|
|
(final b) { |
|
|
|
|
b |
|
|
|
|
..name = '${prefix}HttpBearerAuthentication' |
|
|
|
|
..extend = refer('DynamiteAuthentication') |
|
|
|
|
..constructors.add( |
|
|
|
|
Constructor( |
|
|
|
|
(final b) => b |
|
|
|
|
..optionalParameters.add( |
|
|
|
|
Parameter( |
|
|
|
|
(final b) => b |
|
|
|
|
..name = 'token' |
|
|
|
|
..toThis = true |
|
|
|
|
..named = true |
|
|
|
|
..required = true, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
) |
|
|
|
|
..fields.addAll([ |
|
|
|
|
Field( |
|
|
|
|
(final b) => b |
|
|
|
|
..name = 'token' |
|
|
|
|
..type = refer('String') |
|
|
|
|
..modifier = FieldModifier.final$, |
|
|
|
|
), |
|
|
|
|
]) |
|
|
|
|
..methods.addAll([ |
|
|
|
|
Method( |
|
|
|
|
(final b) => b |
|
|
|
|
..name = 'id' |
|
|
|
|
..annotations.add(refer('override')) |
|
|
|
|
..type = MethodType.getter |
|
|
|
|
..lambda = true |
|
|
|
|
..returns = refer('String') |
|
|
|
|
..body = Code("'$name'"), |
|
|
|
|
), |
|
|
|
|
Method( |
|
|
|
|
(final b) => b |
|
|
|
|
..name = 'headers' |
|
|
|
|
..annotations.add(refer('override')) |
|
|
|
|
..type = MethodType.getter |
|
|
|
|
..returns = refer('Map<String, String>') |
|
|
|
|
..lambda = true |
|
|
|
|
..body = const Code(r''' |
|
|
|
|
{ |
|
|
|
|
'Authorization': 'Bearer $token', |
|
|
|
|
} |
|
|
|
|
'''), |
|
|
|
|
), |
|
|
|
|
]); |
|
|
|
|
}, |
|
|
|
|
).accept(emitter).toString(), |
|
|
|
|
); |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
throw Exception('Can not work with security scheme ${securityScheme.toJson()}'); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (final tag in tags) { |
|
|
|
|
final isRootClient = tag == null; |
|
|
|
|
final paths = <String, PathItem>{}; |
|
|
|
|