0
andmattia created
- What is your product version? 9.2
- What is your product type (Angular or MVC)? angular
- What is product framework type (.net framework or .net core)? .NetCore
If issue related with ABP Framework
- What is ABP Framework version? 5.13
I migrate from ABP 4.8.1 -> 5.13 and I found an issue on Swagger
if (WebConsts.SwaggerUiEnabled)
{
//Swagger - Enable this line and the related lines in Configure method to enable swagger UI
services.AddSwaggerGen(options =>
{
options.SwaggerDoc("v1", new OpenApiInfo() { Title = " API", Version = "v1" });
options.DocInclusionPredicate((docName, description) => true);
options.ParameterFilter<SwaggerEnumParameterFilter>();
options.SchemaFilter<SwaggerEnumSchemaFilter>();
options.OperationFilter<SwaggerOperationIdFilter>();
//options.OperationFilter<SwaggerOperationFilter>();
options.CustomDefaultSchemaIdSelector();
options.CustomSchemaIds(o => o.FullName);
options.OrderActionsBy(o => o.RelativePath);
}).AddSwaggerGenNewtonsoftSupport();
}
my DTO class is
public class InputDto: ...
{
public string FilterText { get; set; }
public long? Id { get; set; }
...
public OrderStatus? Status { get; set; }
...
public OrderStatus[] StatusList { get; set; }
...
}
The only way to fix is add a try catch
private static void AddEnumSpec(Type type, ParameterFilterContext context)
{
var schema = context.SchemaRepository.Schemas.GetOrAdd($"#/definitions/{type.Name}", () =>
context.SchemaGenerator.GenerateSchema(type, context.SchemaRepository)
);
if (schema.Reference == null || !type.IsEnum)
{
return;
}
var enumNames = new OpenApiArray();
enumNames.AddRange(Enum.GetNames(type).Select(_ => new OpenApiString(_)));
try
{
schema.Extensions.Add("x-enumNames", enumNames);
}
catch (Exception ex)
{
Console.Write("Ingore this error");
}
}
3 Answer(s)
-
0
Hi,
Have you tried with the latest version of https://github.com/aspnetzero/aspnet-zero-core/blob/dev/aspnet-core/src/MyCompanyName.AbpZeroTemplate.Web.Core/Swagger/SwaggerEnumParameterFilter.cs ?
-
0
Hi
No at the moment I've only test with 10.5 but I've plan to make this test in the next weeks
-
0
Hi @andmattia
Thanks. I think you can just upgrade this class and try it. It should work with your version.