From d841eada42e0f1f08f488a24752d2f2ae090cb53 Mon Sep 17 00:00:00 2001 From: transtrike Date: Thu, 25 Feb 2021 18:51:29 +0200 Subject: Initial Swagger configuration setup --- .../Configurations/Extensions/ConfigureSwagger.cs | 36 ++++++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) (limited to 'src/Web/DevHive.Web/Configurations') diff --git a/src/Web/DevHive.Web/Configurations/Extensions/ConfigureSwagger.cs b/src/Web/DevHive.Web/Configurations/Extensions/ConfigureSwagger.cs index a0641ab..bfa44b0 100644 --- a/src/Web/DevHive.Web/Configurations/Extensions/ConfigureSwagger.cs +++ b/src/Web/DevHive.Web/Configurations/Extensions/ConfigureSwagger.cs @@ -1,23 +1,53 @@ +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; namespace DevHive.Web.Configurations.Extensions { public static class SwaggerExtensions { +#pragma warning disable S1075 + private const string LicenseName = "GPL-3.0 License"; + private const string LicenseUri = "https://github.com/Team-Kaleidoscope/DevHive/blob/main/LICENSE"; + private const string TermsOfServiceUri = "https://example.com/terms"; +#pragma warning restore S1075 + public static void SwaggerConfiguration(this IServiceCollection services) { services.AddSwaggerGen(c => { - c.SwaggerDoc("v1", new OpenApiInfo { Title = "API", Version = "v1" }); + c.SwaggerDoc("v0.1", new OpenApiInfo + { + Version = "v0.1", + Title = "API", + Description = "DevHive Social Media's first official API release", + TermsOfService = new Uri(TermsOfServiceUri), + License = new OpenApiLicense + { + Name = LicenseName, + Url = new Uri(LicenseUri) + } + }); + + string xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; + string xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); + c.IncludeXmlComments(xmlPath); }); } public static void UseSwaggerConfiguration(this IApplicationBuilder app) { app.UseSwagger(); - app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "API v1")); + app.UseSwaggerUI(c => + { + c.SwaggerEndpoint("/swagger/v0.1/swagger.json", "v0.1"); + }); } } -} \ No newline at end of file +} -- cgit v1.2.3