Skip to content

Commit

Permalink
VCST-1735: Update Swashbuckle to version 7.2.0 (#2868)
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-dudarev authored Dec 11, 2024
1 parent 807e039 commit 34c2c8f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,7 +13,7 @@ namespace VirtoCommerce.Platform.Web.Swagger
/// <summary>
/// Generate swagger schema ids for schema refs depending on document name
/// </summary>
public class CustomSwaggerGenerator : ISwaggerProvider
public class CustomSwaggerGenerator : IAsyncSwaggerProvider
{
private readonly SwaggerGenerator _swaggerGenerator;
private readonly SchemaGeneratorOptions _schemaGeneratorOptions;
Expand All @@ -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<OpenApiDocument> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ISwaggerProvider, CustomSwaggerGenerator>();
services.AddTransient<IAsyncSwaggerProvider, CustomSwaggerGenerator>();

//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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageReference Include="Serilog.Sinks.Debug" Version="3.0.0" />
<PackageReference Include="Scrutor" Version="5.0.2" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="[6.6.2,6.7)" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="[6.6.2,6.7)" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.2.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="7.2.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="8.0.2" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="[6.6.2,6.7)" />
<PackageReference Include="Swashbuckle.AspNetCore.Newtonsoft" Version="[6.6.2,6.7)" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="7.2.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Newtonsoft" Version="7.2.0" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="[8.0.1,9)" />
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
<PackageReference Include="System.Security.Cryptography.Algorithms" Version="4.3.1" />
Expand Down

0 comments on commit 34c2c8f

Please sign in to comment.