aboutsummaryrefslogtreecommitdiff
path: root/src/Web/DevHive.Web
diff options
context:
space:
mode:
authorVictor S <57849063+transtrike@users.noreply.github.com>2021-03-03 18:42:11 +0200
committerGitHub <noreply@github.com>2021-03-03 18:42:11 +0200
commit02cf05d6cc38e6907404f65976440b811d6cc60a (patch)
tree6e536e34d2118d9bdf8854dc3d12b493162ed0f3 /src/Web/DevHive.Web
parent804d274223734ea1c67920622ceb453cca602fc9 (diff)
parentb9a9d63418d728560b17c23d49255328d16ccb11 (diff)
downloadDevHive-02cf05d6cc38e6907404f65976440b811d6cc60a.tar
DevHive-02cf05d6cc38e6907404f65976440b811d6cc60a.tar.gz
DevHive-02cf05d6cc38e6907404f65976440b811d6cc60a.zip
Merge pull request #19 from Team-Kaleidoscope/nswag
NSwag replaced Swagger; Doc prep configured
Diffstat (limited to 'src/Web/DevHive.Web')
-rw-r--r--src/Web/DevHive.Web/Configurations/Extensions/ConfigureSwagger.cs56
-rw-r--r--src/Web/DevHive.Web/DevHive.Web.csproj37
-rw-r--r--src/Web/DevHive.Web/Startup.cs2
3 files changed, 53 insertions, 42 deletions
diff --git a/src/Web/DevHive.Web/Configurations/Extensions/ConfigureSwagger.cs b/src/Web/DevHive.Web/Configurations/Extensions/ConfigureSwagger.cs
index bfa44b0..9387561 100644
--- a/src/Web/DevHive.Web/Configurations/Extensions/ConfigureSwagger.cs
+++ b/src/Web/DevHive.Web/Configurations/Extensions/ConfigureSwagger.cs
@@ -1,12 +1,8 @@
-using System;
-using System.IO;
using System.Linq;
-using System.Reflection;
using Microsoft.AspNetCore.Builder;
-using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
-using Microsoft.OpenApi.Models;
-using Swashbuckle.AspNetCore.SwaggerGen;
+using NSwag;
+using NSwag.Generation.Processors.Security;
namespace DevHive.Web.Configurations.Extensions
{
@@ -20,33 +16,49 @@ namespace DevHive.Web.Configurations.Extensions
public static void SwaggerConfiguration(this IServiceCollection services)
{
- services.AddSwaggerGen(c =>
+ services.AddOpenApiDocument(c =>
{
- c.SwaggerDoc("v0.1", new OpenApiInfo
+ c.GenerateXmlObjects = true;
+ c.UseControllerSummaryAsTagDescription = true;
+
+ c.AllowNullableBodyParameters = false;
+ c.Description = "DevHive Social Media's API Endpoints";
+
+ c.PostProcess = doc =>
{
- Version = "v0.1",
- Title = "API",
- Description = "DevHive Social Media's first official API release",
- TermsOfService = new Uri(TermsOfServiceUri),
- License = new OpenApiLicense
+ doc.Info.Version = "v0.1";
+ doc.Info.Title = "API";
+ doc.Info.Description = "DevHive Social Media's first official API release";
+ doc.Info.TermsOfService = TermsOfServiceUri;
+ doc.Info.License = new NSwag.OpenApiLicense
{
Name = LicenseName,
- Url = new Uri(LicenseUri)
- }
- });
+ Url = LicenseUri
+ };
+ };
- string xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
- string xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
- c.IncludeXmlComments(xmlPath);
+ c.AddSecurity("Bearer", Enumerable.Empty<string>(), new OpenApiSecurityScheme
+ {
+ Type = OpenApiSecuritySchemeType.ApiKey,
+ Name = "Authorization",
+ In = OpenApiSecurityApiKeyLocation.Header,
+ Description = "Type into the textbox: Bearer {your JWT token}."
+ });
+ c.OperationProcessors.Add(new AspNetCoreOperationSecurityScopeProcessor("Bearer"));
});
}
public static void UseSwaggerConfiguration(this IApplicationBuilder app)
{
- app.UseSwagger();
- app.UseSwaggerUI(c =>
+ app.UseOpenApi(c =>
+ {
+ c.DocumentName = "v0.1";
+ });
+ app.UseSwaggerUi3(c =>
{
- c.SwaggerEndpoint("/swagger/v0.1/swagger.json", "v0.1");
+ c.DocumentTitle = "DevHive API";
+ c.EnableTryItOut = false;
+ c.DocExpansion = "list";
});
}
}
diff --git a/src/Web/DevHive.Web/DevHive.Web.csproj b/src/Web/DevHive.Web/DevHive.Web.csproj
index ea9eee6..38f21e6 100644
--- a/src/Web/DevHive.Web/DevHive.Web.csproj
+++ b/src/Web/DevHive.Web/DevHive.Web.csproj
@@ -5,32 +5,31 @@
<PropertyGroup>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<AnalysisLevel>latest</AnalysisLevel>
- <GenerateDocumentationFile>true</GenerateDocumentationFile>
- <AllowUntrustedCertificate>true</AllowUntrustedCertificate>
+ <GenerateDocumentationFile>true</GenerateDocumentationFile>
+ <AllowUntrustedCertificate>true</AllowUntrustedCertificate>
</PropertyGroup>
<ItemGroup>
- <PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="5.0.3" NoWarn="NU1605" />
- <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.3" NoWarn="NU1605" />
+ <PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="5.0.3" NoWarn="NU1605"/>
+ <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.3" NoWarn="NU1605"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
- <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.2" />
- <PackageReference Include="Swashbuckle.AspNetCore" Version="6.0.7" />
- <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.1.1" />
- <PackageReference Include="AutoMapper" Version="10.1.1" />
- <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
- <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.3" />
- <PackageReference Include="SonarAnalyzer.CSharp" Version="8.18.0.27296" />
- <PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="6.0.7" />
- <PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.0.7" />
- <PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.0.7" />
- <PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="6.1.0" />
+ <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.2"/>
+ <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.1.1"/>
+ <PackageReference Include="AutoMapper" Version="10.1.1"/>
+ <PackageReference Include="Newtonsoft.Json" Version="12.0.3"/>
+ <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.3"/>
+ <PackageReference Include="SonarAnalyzer.CSharp" Version="8.19.0.28253"/>
+ <PackageReference Include="NSwag.AspNetCore" Version="13.10.7"/>
+ <PackageReference Include="NSwag.Generation.AspNetCore" Version="13.10.7"/>
+ <PackageReference Include="NSwag.Annotations" Version="13.10.7"/>
+ <PackageReference Include="NSwag.Core" Version="13.10.7"/>
</ItemGroup>
<ItemGroup>
- <ProjectReference Include="..\DevHive.Web.Models\DevHive.Web.Models.csproj" />
- <ProjectReference Include="..\..\Services\DevHive.Services\DevHive.Services.csproj" />
- <ProjectReference Include="..\..\Common\DevHive.Common.Models\DevHive.Common.Models.csproj" />
- <ProjectReference Include="..\..\Common\DevHive.Common\DevHive.Common.csproj" />
+ <ProjectReference Include="..\DevHive.Web.Models\DevHive.Web.Models.csproj"/>
+ <ProjectReference Include="..\..\Services\DevHive.Services\DevHive.Services.csproj"/>
+ <ProjectReference Include="..\..\Common\DevHive.Common.Models\DevHive.Common.Models.csproj"/>
+ <ProjectReference Include="..\..\Common\DevHive.Common\DevHive.Common.csproj"/>
</ItemGroup>
</Project>
diff --git a/src/Web/DevHive.Web/Startup.cs b/src/Web/DevHive.Web/Startup.cs
index 40f674d..ebd091e 100644
--- a/src/Web/DevHive.Web/Startup.cs
+++ b/src/Web/DevHive.Web/Startup.cs
@@ -48,7 +48,6 @@ namespace DevHive.Web
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
- app.UseSwaggerConfiguration();
}
else
{
@@ -56,6 +55,7 @@ namespace DevHive.Web
app.UseExceptionHandlerMiddlewareConfiguration();
}
+ app.UseSwaggerConfiguration();
app.UseDatabaseConfiguration();
app.UseAutoMapperConfiguration();