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 | d5c2e1bd1573325e5585f5cf7279bd7592dbfeee (patch) | |
tree | ccf114de32f524fe3553968e0aef5fb9e28f8c0f /BackEnd/Timeline/Swagger | |
parent | 8efb9dc9bec7e52aa76a741d820bdeaf9eb45fec (diff) | |
download | timeline-d5c2e1bd1573325e5585f5cf7279bd7592dbfeee.tar.gz timeline-d5c2e1bd1573325e5585f5cf7279bd7592dbfeee.tar.bz2 timeline-d5c2e1bd1573325e5585f5cf7279bd7592dbfeee.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());
+ });
+ }
+ }
+}
|