Browse Source

Merge pull request #227 from provokateurin/feature/dynamite-http-bearer-auth

dynamite: Support http bearer auth
pull/228/head
Kate 2 years ago committed by GitHub
parent
commit
57209f3dc4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  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(), ).accept(emitter).toString(),
); );
continue; 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()}'); throw Exception('Can not work with security scheme ${securityScheme.toJson()}');

Loading…
Cancel
Save