From 7c6221cc22d83b5dacc93a2a656d70beb0a686fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Onurkan=20Bak=C4=B1rc=C4=B1?= Date: Mon, 21 Mar 2022 15:33:02 +0300 Subject: [PATCH] Swagger comment support added Catalog, Webhook, Order and Basket services. Swagger and swagger comment support added to Identity Service --- .../Basket/Basket.API/Basket.API.csproj | 5 +++- src/Services/Basket/Basket.API/Startup.cs | 17 ++++++++++++- .../Catalog/Catalog.API/Catalog.API.csproj | 5 +++- src/Services/Catalog/Catalog.API/Startup.cs | 17 ++++++++++++- .../Identity/Identity.API/Identity.API.csproj | 5 ++++ src/Services/Identity/Identity.API/Startup.cs | 25 ++++++++++++++++++- .../Ordering/Ordering.API/Ordering.API.csproj | 5 +++- src/Services/Ordering/Ordering.API/Startup.cs | 19 ++++++++++++-- src/Services/Webhooks/Webhooks.API/Startup.cs | 17 ++++++++++++- .../Webhooks/Webhooks.API/Webhooks.API.csproj | 5 +++- 10 files changed, 110 insertions(+), 10 deletions(-) diff --git a/src/Services/Basket/Basket.API/Basket.API.csproj b/src/Services/Basket/Basket.API/Basket.API.csproj index ebb224824..16d662ea6 100644 --- a/src/Services/Basket/Basket.API/Basket.API.csproj +++ b/src/Services/Basket/Basket.API/Basket.API.csproj @@ -6,7 +6,10 @@ false true - + + true + $(NoWarn);1591 + PreserveNewest diff --git a/src/Services/Basket/Basket.API/Startup.cs b/src/Services/Basket/Basket.API/Startup.cs index 082560048..cfe95dcc5 100644 --- a/src/Services/Basket/Basket.API/Startup.cs +++ b/src/Services/Basket/Basket.API/Startup.cs @@ -29,11 +29,26 @@ public class Startup services.AddSwaggerGen(options => { + var basePath = AppDomain.CurrentDomain.BaseDirectory; + var fileName = typeof(Program).GetTypeInfo().Assembly.GetName().Name + ".xml"; + var xmlComments = Path.Combine(basePath, fileName); + options.IncludeXmlComments(xmlComments); options.SwaggerDoc("v1", new OpenApiInfo { Title = "eShopOnContainers - Basket HTTP API", Version = "v1", - Description = "The Basket Service HTTP API" + Description = "The Basket Service HTTP API", + TermsOfService = new Uri("https://microsoft.com/"), + Contact = new OpenApiContact + { + Name = "Microsoft Contact", + Url = new Uri("https://microsoft.com/") + }, + License = new OpenApiLicense + { + Name = "Microsoft License", + Url = new Uri("https://microsoft.com/") + } }); options.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme diff --git a/src/Services/Catalog/Catalog.API/Catalog.API.csproj b/src/Services/Catalog/Catalog.API/Catalog.API.csproj index b78ce2af3..7de11b7c2 100644 --- a/src/Services/Catalog/Catalog.API/Catalog.API.csproj +++ b/src/Services/Catalog/Catalog.API/Catalog.API.csproj @@ -11,7 +11,10 @@ false true - + + true + $(NoWarn);1591 + diff --git a/src/Services/Catalog/Catalog.API/Startup.cs b/src/Services/Catalog/Catalog.API/Startup.cs index f7b46cb6f..39048cb61 100644 --- a/src/Services/Catalog/Catalog.API/Startup.cs +++ b/src/Services/Catalog/Catalog.API/Startup.cs @@ -222,11 +222,26 @@ public static class CustomExtensionMethods { services.AddSwaggerGen(options => { + var basePath = AppDomain.CurrentDomain.BaseDirectory; + var fileName = typeof(Program).GetTypeInfo().Assembly.GetName().Name + ".xml"; + var xmlComments = Path.Combine(basePath, fileName); + options.IncludeXmlComments(xmlComments); options.SwaggerDoc("v1", new OpenApiInfo { Title = "eShopOnContainers - Catalog HTTP API", Version = "v1", - Description = "The Catalog Microservice HTTP API. This is a Data-Driven/CRUD microservice sample" + Description = "The Catalog Microservice HTTP API. This is a Data-Driven/CRUD microservice sample", + TermsOfService = new Uri("https://microsoft.com/terms"), + Contact = new OpenApiContact + { + Name = "Microsoft Contact", + Url = new Uri("https://microsoft.com/contact") + }, + License = new OpenApiLicense + { + Name = "Microsoft License", + Url = new Uri("https://microsoft.com/license") + } }); }); diff --git a/src/Services/Identity/Identity.API/Identity.API.csproj b/src/Services/Identity/Identity.API/Identity.API.csproj index 0398ccb4b..e484b7730 100644 --- a/src/Services/Identity/Identity.API/Identity.API.csproj +++ b/src/Services/Identity/Identity.API/Identity.API.csproj @@ -8,6 +8,11 @@ true + + true + $(NoWarn);1591 + + PreserveNewest diff --git a/src/Services/Identity/Identity.API/Startup.cs b/src/Services/Identity/Identity.API/Startup.cs index 43662acdd..2528d88a1 100644 --- a/src/Services/Identity/Identity.API/Startup.cs +++ b/src/Services/Identity/Identity.API/Startup.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.DataProtection; +using Microsoft.AspNetCore.DataProtection; namespace Microsoft.eShopOnContainers.Services.Identity.API { @@ -89,6 +89,29 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API services.AddControllersWithViews(); services.AddRazorPages(); + var basePath = AppDomain.CurrentDomain.BaseDirectory; + var fileName = typeof(Program).GetTypeInfo().Assembly.GetName().Name + ".xml"; + var xmlComments = Path.Combine(basePath, fileName); + options.IncludeXmlComments(xmlComments); + options.SwaggerDoc("v1", new OpenApiInfo + { + Title = "Microsoft - Identity HTTP API", + Version = "v1", + Description = "The Identity Service HTTP API", + TermsOfService = new Uri("https://microsoft.com/"), + Contact = new OpenApiContact + { + Name = "Microsoft Contact", + Url = new Uri("https://microsoft.com/") + }, + License = new OpenApiLicense + { + Name = "Microsoft License", + Url = new Uri("https://microsoft.com/") + } + }); + }); + var container = new ContainerBuilder(); container.Populate(services); diff --git a/src/Services/Ordering/Ordering.API/Ordering.API.csproj b/src/Services/Ordering/Ordering.API/Ordering.API.csproj index 5b011d037..18b6ea0e8 100644 --- a/src/Services/Ordering/Ordering.API/Ordering.API.csproj +++ b/src/Services/Ordering/Ordering.API/Ordering.API.csproj @@ -8,7 +8,10 @@ false true - + + true + $(NoWarn);1591 + PreserveNewest diff --git a/src/Services/Ordering/Ordering.API/Startup.cs b/src/Services/Ordering/Ordering.API/Startup.cs index 501a55361..c48b77d7e 100644 --- a/src/Services/Ordering/Ordering.API/Startup.cs +++ b/src/Services/Ordering/Ordering.API/Startup.cs @@ -214,12 +214,27 @@ static class CustomExtensionsMethods public static IServiceCollection AddCustomSwagger(this IServiceCollection services, IConfiguration configuration) { services.AddSwaggerGen(options => - { + { + var basePath = AppDomain.CurrentDomain.BaseDirectory; + var fileName = typeof(Program).GetTypeInfo().Assembly.GetName().Name + ".xml"; + var xmlComments = Path.Combine(basePath, fileName); + options.IncludeXmlComments(xmlComments); options.SwaggerDoc("v1", new OpenApiInfo { Title = "eShopOnContainers - Ordering HTTP API", Version = "v1", - Description = "The Ordering Service HTTP API" + Description = "The Ordering Service HTTP API", + TermsOfService = new Uri("https://microsoft.com/terms"), + Contact = new OpenApiContact + { + Name = "Microsoft Contact", + Url = new Uri("https://microsoft.com/") + }, + License = new OpenApiLicense + { + Name = "Microsoft License", + Url = new Uri("https://microsoft.com/") + } }); options.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme { diff --git a/src/Services/Webhooks/Webhooks.API/Startup.cs b/src/Services/Webhooks/Webhooks.API/Startup.cs index 256941efa..1d9359ffa 100644 --- a/src/Services/Webhooks/Webhooks.API/Startup.cs +++ b/src/Services/Webhooks/Webhooks.API/Startup.cs @@ -139,11 +139,26 @@ static class CustomExtensionMethods { services.AddSwaggerGen(options => { + var basePath = AppDomain.CurrentDomain.BaseDirectory; + var fileName = typeof(Program).GetTypeInfo().Assembly.GetName().Name + ".xml"; + var xmlComments = Path.Combine(basePath, fileName); + options.IncludeXmlComments(xmlComments); options.SwaggerDoc("v1", new OpenApiInfo { Title = "eShopOnContainers - Webhooks HTTP API", Version = "v1", - Description = "The Webhooks Microservice HTTP API. This is a simple webhooks CRUD registration entrypoint" + Description = "The Webhooks Microservice HTTP API. This is a simple webhooks CRUD registration entrypoint", + TermsOfService = new Uri("https://microsoft.com/"), + Contact = new OpenApiContact + { + Name = "Microsoft Contact", + Url = new Uri("https://microsoft.com/") + }, + License = new OpenApiLicense + { + Name = "Microsoft License", + Url = new Uri("https://microsoft.com/") + } }); options.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme diff --git a/src/Services/Webhooks/Webhooks.API/Webhooks.API.csproj b/src/Services/Webhooks/Webhooks.API/Webhooks.API.csproj index 063a01cf3..98e8efcaf 100644 --- a/src/Services/Webhooks/Webhooks.API/Webhooks.API.csproj +++ b/src/Services/Webhooks/Webhooks.API/Webhooks.API.csproj @@ -8,7 +8,10 @@ false true - + + true + $(NoWarn);1591 +