From 34c2c8f42440239d40da2c12c093a8a2a3cd0bcf Mon Sep 17 00:00:00 2001 From: Artem Dudarev Date: Wed, 11 Dec 2024 16:18:14 +0200 Subject: [PATCH] VCST-1735: Update Swashbuckle to version 7.2.0 (#2868) --- .../Swagger/CustomSwaggerGenerator.cs | 7 ++++--- .../Swagger/SwaggerServiceCollectionExtensions.cs | 2 +- .../VirtoCommerce.Platform.Web.csproj | 8 ++++---- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/VirtoCommerce.Platform.Web/Swagger/CustomSwaggerGenerator.cs b/src/VirtoCommerce.Platform.Web/Swagger/CustomSwaggerGenerator.cs index 1357ac87d3..63be132126 100644 --- a/src/VirtoCommerce.Platform.Web/Swagger/CustomSwaggerGenerator.cs +++ b/src/VirtoCommerce.Platform.Web/Swagger/CustomSwaggerGenerator.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics; using System.Reflection; +using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.ApiExplorer; using Microsoft.OpenApi.Models; using Swashbuckle.AspNetCore.Swagger; @@ -12,7 +13,7 @@ namespace VirtoCommerce.Platform.Web.Swagger /// /// Generate swagger schema ids for schema refs depending on document name /// - public class CustomSwaggerGenerator : ISwaggerProvider + public class CustomSwaggerGenerator : IAsyncSwaggerProvider { private readonly SwaggerGenerator _swaggerGenerator; private readonly SchemaGeneratorOptions _schemaGeneratorOptions; @@ -30,10 +31,10 @@ public CustomSwaggerGenerator(SwaggerGeneratorOptions options, IApiDescriptionGr _swaggerGenerator = new SwaggerGenerator(options, apiDescriptionsProvider, schemaGenerator); } - public OpenApiDocument GetSwagger(string documentName, string host = null, string basePath = null) + public Task GetSwaggerAsync(string documentName, string host = null, string basePath = null) { SetSchemaIdSelector(documentName); - return _swaggerGenerator.GetSwagger(documentName, host, basePath); + return _swaggerGenerator.GetSwaggerAsync(documentName, host, basePath); } private void SetSchemaIdSelector(string documentName) diff --git a/src/VirtoCommerce.Platform.Web/Swagger/SwaggerServiceCollectionExtensions.cs b/src/VirtoCommerce.Platform.Web/Swagger/SwaggerServiceCollectionExtensions.cs index 3b41503475..7a6c7bddc1 100644 --- a/src/VirtoCommerce.Platform.Web/Swagger/SwaggerServiceCollectionExtensions.cs +++ b/src/VirtoCommerce.Platform.Web/Swagger/SwaggerServiceCollectionExtensions.cs @@ -118,7 +118,7 @@ public static void AddSwagger(this IServiceCollection services, IConfiguration c // Unfortunately, we can't use .CustomSchemaIds, because it changes schema ids for all documents (impossible to change ids depending on document name). // But we need this, because PlatformUI document should contain ref schema ids as type.FullName to avoid conflict with same type names in different modules. // As a solution we use custom swagger generator that catches document name and generates schema ids depending on it. - services.AddTransient(); + services.AddTransient(); //This is important line switches the SwaggerGenerator to use the Newtonsoft contract resolver that uses the globally registered PolymorphJsonContractResolver //to propagate up to the resulting OpenAPI schema the derived types instead of base domain types diff --git a/src/VirtoCommerce.Platform.Web/VirtoCommerce.Platform.Web.csproj b/src/VirtoCommerce.Platform.Web/VirtoCommerce.Platform.Web.csproj index f4e900b559..9c5ad865ba 100644 --- a/src/VirtoCommerce.Platform.Web/VirtoCommerce.Platform.Web.csproj +++ b/src/VirtoCommerce.Platform.Web/VirtoCommerce.Platform.Web.csproj @@ -38,11 +38,11 @@ - - + + - - + +