diff options
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());
+ });
+ }
+ }
+}
|