字典请求返回格式化
This commit is contained in:
@@ -209,6 +209,7 @@ public static class SimApiExtensions
|
|||||||
x.OperationFilter<SimApiSignOperationFilter>();
|
x.OperationFilter<SimApiSignOperationFilter>();
|
||||||
x.OperationFilter<AesBodyOperationFilter>();
|
x.OperationFilter<AesBodyOperationFilter>();
|
||||||
x.SchemaFilter<GlobalDynamicObjectSchemaFilter>();
|
x.SchemaFilter<GlobalDynamicObjectSchemaFilter>();
|
||||||
|
x.SchemaFilter<DictionarySchemaFilter>();
|
||||||
x.DocumentFilter<RemoveEmptyTagsFilter>();
|
x.DocumentFilter<RemoveEmptyTagsFilter>();
|
||||||
if (simApiOptions.EnableSimApiAuth)
|
if (simApiOptions.EnableSimApiAuth)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using Microsoft.OpenApi;
|
||||||
|
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||||
|
|
||||||
|
namespace SimApi.SwaggerFilters;
|
||||||
|
|
||||||
|
public class DictionarySchemaFilter : ISchemaFilter
|
||||||
|
{
|
||||||
|
public void Apply(IOpenApiSchema schema, SchemaFilterContext context)
|
||||||
|
{
|
||||||
|
if (!context.Type.IsGenericType || context.Type.GetGenericTypeDefinition() != typeof(Dictionary<,>))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (schema is not OpenApiSchema concrete) return;
|
||||||
|
|
||||||
|
var valueType = context.Type.GetGenericArguments()[1];
|
||||||
|
concrete.Type = JsonSchemaType.Object;
|
||||||
|
concrete.AdditionalPropertiesAllowed = true;
|
||||||
|
concrete.AdditionalProperties = context.SchemaGenerator.GenerateSchema(valueType, context.SchemaRepository);
|
||||||
|
concrete.Properties?.Clear();
|
||||||
|
concrete.Example = null;
|
||||||
|
concrete.Examples?.Clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user