aboutsummaryrefslogtreecommitdiff
path: root/Timeline/Startup.cs
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-08-23 18:15:25 +0800
committerGitHub <noreply@github.com>2020-08-23 18:15:25 +0800
commita9edf94e42e5288c0d46994546eef6a507768fcf (patch)
tree7edfeca01b33e2bff98f10148b371d473e73a299 /Timeline/Startup.cs
parentc28848a35b0f31a59f9d02641571495822ad0db8 (diff)
parentb1b10b7dda86138d020b1545b4de55b37ee793b3 (diff)
downloadtimeline-a9edf94e42e5288c0d46994546eef6a507768fcf.tar.gz
timeline-a9edf94e42e5288c0d46994546eef6a507768fcf.tar.bz2
timeline-a9edf94e42e5288c0d46994546eef6a507768fcf.zip
Merge pull request #150 from crupest/swagger
Enhance swagger docs.
Diffstat (limited to 'Timeline/Startup.cs')
-rw-r--r--Timeline/Startup.cs9
1 files changed, 7 insertions, 2 deletions
diff --git a/Timeline/Startup.cs b/Timeline/Startup.cs
index 86bdaf54..82c231cb 100644
--- a/Timeline/Startup.cs
+++ b/Timeline/Startup.cs
@@ -1,6 +1,7 @@
using AutoMapper;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
+using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
@@ -11,6 +12,7 @@ using NSwag;
using NSwag.Generation.Processors.Security;
using System;
using System.ComponentModel;
+using System.Net.Mime;
using System.Text.Json.Serialization;
using Timeline.Auth;
using Timeline.Configs;
@@ -50,6 +52,8 @@ namespace Timeline
{
setup.InputFormatters.Add(new StringInputFormatter());
setup.InputFormatters.Add(new BytesInputFormatter());
+ setup.Filters.Add(new ConsumesAttribute(MediaTypeNames.Application.Json, "text/json"));
+ setup.Filters.Add(new ProducesAttribute(MediaTypeNames.Application.Json, "text/json"));
setup.UseApiRoutePrefix("api");
})
.AddJsonOptions(options =>
@@ -104,6 +108,7 @@ namespace Timeline
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
@@ -111,7 +116,7 @@ namespace Timeline
Type = OpenApiSecuritySchemeType.ApiKey,
Name = "Authorization",
In = OpenApiSecurityApiKeyLocation.Header,
- Description = "Type into the textbox: Bearer {your JWT token}."
+ Description = "Create token via `/api/token/create` ."
}));
document.OperationProcessors.Add(new AspNetCoreOperationSecurityScopeProcessor("JWT"));
document.OperationProcessors.Add(new DefaultDescriptionOperationProcessor());
@@ -153,7 +158,7 @@ namespace Timeline
}
app.UseOpenApi();
- app.UseSwaggerUi3();
+ app.UseReDoc();
app.UseAuthentication();
app.UseAuthorization();