diff options
| author | transtrike <transtrike@gmail.com> | 2021-03-03 18:35:12 +0200 |
|---|---|---|
| committer | transtrike <transtrike@gmail.com> | 2021-03-03 18:35:12 +0200 |
| commit | b9a9d63418d728560b17c23d49255328d16ccb11 (patch) | |
| tree | 6e536e34d2118d9bdf8854dc3d12b493162ed0f3 /src/Web | |
| parent | 804d274223734ea1c67920622ceb453cca602fc9 (diff) | |
| download | DevHive-nswag.tar DevHive-nswag.tar.gz DevHive-nswag.zip | |
NSwag replaced Swagger; Doc prep configurednswag
Diffstat (limited to 'src/Web')
| -rw-r--r-- | src/Web/DevHive.Web.Models/DevHive.Web.Models.csproj | 10 | ||||
| -rw-r--r-- | src/Web/DevHive.Web.Tests/DevHive.Web.Tests.csproj | 18 | ||||
| -rw-r--r-- | src/Web/DevHive.Web/Configurations/Extensions/ConfigureSwagger.cs | 56 | ||||
| -rw-r--r-- | src/Web/DevHive.Web/DevHive.Web.csproj | 37 | ||||
| -rw-r--r-- | src/Web/DevHive.Web/Startup.cs | 2 |
5 files changed, 67 insertions, 56 deletions
diff --git a/src/Web/DevHive.Web.Models/DevHive.Web.Models.csproj b/src/Web/DevHive.Web.Models/DevHive.Web.Models.csproj index 7f3f577..9d62eee 100644 --- a/src/Web/DevHive.Web.Models/DevHive.Web.Models.csproj +++ b/src/Web/DevHive.Web.Models/DevHive.Web.Models.csproj @@ -3,11 +3,11 @@ <TargetFramework>net5.0</TargetFramework> </PropertyGroup> <ItemGroup> - <ProjectReference Include="..\..\Common\DevHive.Common\DevHive.Common.csproj" /> - <ProjectReference Include="..\..\Common\DevHive.Common.Models\DevHive.Common.Models.csproj" /> + <ProjectReference Include="..\..\Common\DevHive.Common\DevHive.Common.csproj"/> + <ProjectReference Include="..\..\Common\DevHive.Common.Models\DevHive.Common.Models.csproj"/> </ItemGroup> <ItemGroup> - <PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" /> - <PackageReference Include="SonarAnalyzer.CSharp" Version="8.18.0.27296" /> + <PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2"/> + <PackageReference Include="SonarAnalyzer.CSharp" Version="8.19.0.28253"/> </ItemGroup> -</Project> +</Project>
\ No newline at end of file diff --git a/src/Web/DevHive.Web.Tests/DevHive.Web.Tests.csproj b/src/Web/DevHive.Web.Tests/DevHive.Web.Tests.csproj index 41afbd4..5099119 100644 --- a/src/Web/DevHive.Web.Tests/DevHive.Web.Tests.csproj +++ b/src/Web/DevHive.Web.Tests/DevHive.Web.Tests.csproj @@ -4,19 +4,19 @@ <IsPackable>false</IsPackable> </PropertyGroup> <ItemGroup> - <PackageReference Include="Moq" Version="4.16.1" /> - <PackageReference Include="NUnit" Version="3.13.1" /> - <PackageReference Include="NUnit3TestAdapter" Version="3.17.0" /> - <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" /> - <PackageReference Include="SonarAnalyzer.CSharp" Version="8.18.0.27296" /> + <PackageReference Include="Moq" Version="4.16.1"/> + <PackageReference Include="NUnit" Version="3.13.1"/> + <PackageReference Include="NUnit3TestAdapter" Version="3.17.0"/> + <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1"/> + <PackageReference Include="SonarAnalyzer.CSharp" Version="8.19.0.28253"/> </ItemGroup> <ItemGroup> - <ProjectReference Include="..\DevHive.Web\DevHive.Web.csproj" /> - <ProjectReference Include="..\..\Common\DevHive.Common\DevHive.Common.csproj" /> - <ProjectReference Include="..\..\Common\DevHive.Common.Models\DevHive.Common.Models.csproj" /> + <ProjectReference Include="..\DevHive.Web\DevHive.Web.csproj"/> + <ProjectReference Include="..\..\Common\DevHive.Common\DevHive.Common.csproj"/> + <ProjectReference Include="..\..\Common\DevHive.Common.Models\DevHive.Common.Models.csproj"/> </ItemGroup> <PropertyGroup> <EnableNETAnalyzers>true</EnableNETAnalyzers> <AnalysisLevel>latest</AnalysisLevel> </PropertyGroup> -</Project> +</Project>
\ No newline at end of file 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(); |
