Browse Source

dynamite: Support http bearer auth

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

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

@ -326,6 +326,53 @@ class OpenAPIBuilder implements Builder {
).accept(emitter).toString(),
);
continue;
case 'bearer':
output.add(
Class(
(final b) {
b
..name = '${prefix}HttpBearerAuthentication'
..extend = refer('${prefix}Authentication')
..constructors.add(
Constructor(
(final b) => b
..optionalParameters.add(
Parameter(
(final b) => b
..name = 'token'
..toThis = true
..named = true
..required = true,
),
),
),
)
..fields.add(
Field(
(final b) => b
..name = 'token'
..type = refer('String')
..modifier = FieldModifier.final$,
),
)
..methods.add(
Method(
(final b) => b
..name = 'headers'
..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()}');

Loading…
Cancel
Save