From d5c2e1bd1573325e5585f5cf7279bd7592dbfeee Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 7 Jan 2021 20:20:44 +0800 Subject: chore: Move open api setup to its own namespace. --- .../Swagger/OpenApiServiceCollectionExtensions.cs | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 BackEnd/Timeline/Swagger/OpenApiServiceCollectionExtensions.cs (limited to 'BackEnd/Timeline/Swagger/OpenApiServiceCollectionExtensions.cs') 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()); + }); + } + } +} -- cgit v1.2.3