diff options
author | crupest <crupest@outlook.com> | 2021-01-07 20:20:44 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-01-07 20:20:44 +0800 |
commit | 2ec9433d0d9547383a7431e97c0577ffcc98ea97 (patch) | |
tree | db150f97b04072797e5100fa91537a38407939ae /BackEnd/Timeline/Swagger | |
parent | e02871ff8bba7fccebdaaeea29141ed5e3289c09 (diff) | |
download | timeline-2ec9433d0d9547383a7431e97c0577ffcc98ea97.tar.gz timeline-2ec9433d0d9547383a7431e97c0577ffcc98ea97.tar.bz2 timeline-2ec9433d0d9547383a7431e97c0577ffcc98ea97.zip |
chore: Move open api setup to its own namespace.
Diffstat (limited to 'BackEnd/Timeline/Swagger')
-rw-r--r-- | BackEnd/Timeline/Swagger/OpenApiServiceCollectionExtensions.cs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/BackEnd/Timeline/Swagger/OpenApiServiceCollectionExtensions.cs b/BackEnd/Timeline/Swagger/OpenApiServiceCollectionExtensions.cs new file mode 100644 index 00000000..e1266d7a --- /dev/null +++ b/BackEnd/Timeline/Swagger/OpenApiServiceCollectionExtensions.cs @@ -0,0 +1,32 @@ +using Microsoft.Extensions.DependencyInjection;
+using NSwag;
+using NSwag.Generation.Processors.Security;
+
+namespace Timeline.Swagger
+{
+ public static class OpenApiServiceCollectionExtensions
+ {
+ public static void AddOpenApiDocs(this IServiceCollection services)
+ {
+ services.AddSwaggerDocument(document =>
+ {
+ document.DocumentName = "Timeline";
+ document.Title = "Timeline REST API Reference";
+ document.Version = typeof(Startup).Assembly.GetName().Version?.ToString() ?? "unknown version";
+ document.DocumentProcessors.Add(new DocumentDescriptionDocumentProcessor());
+ document.DocumentProcessors.Add(
+ new SecurityDefinitionAppender("JWT",
+ new OpenApiSecurityScheme
+ {
+ Type = OpenApiSecuritySchemeType.ApiKey,
+ Name = "Authorization",
+ In = OpenApiSecurityApiKeyLocation.Header,
+ Description = "Create token via `/api/token/create` ."
+ }));
+ document.OperationProcessors.Add(new AspNetCoreOperationSecurityScopeProcessor("JWT"));
+ document.OperationProcessors.Add(new DefaultDescriptionOperationProcessor());
+ document.OperationProcessors.Add(new ByteDataRequestOperationProcessor());
+ });
+ }
+ }
+}
|