Starts in:
1 DAY
23 HRS
14 MIN
15 SEC
Starts in:
1 D
23 H
14 M
15 S
Open Closed

Enum descriptions in swagger #6869


User avatar
0
naeem76 created
  • ABP Framework version: v7.1.0
  • UI Type: MVC
  • Database System: EF Core / MySQL
  • Tiered (for MVC) or Auth Server Separated (for Angular): No
  • Exception message and full stack trace:
  • Steps to reproduce the issue:

Currently trying to describe enum models in Swagger, don't want to change the API parameters, they should still use and return integers, but the description should show which integer means what.

I've tried this

options.SchemaFilter<EnumSchemaFilter>();

public class EnumSchemaFilter : ISchemaFilter
{
    public void Apply(OpenApiSchema schema, SchemaFilterContext context)
    {
        if (context.Type.IsEnum)
        {
            var array = new OpenApiArray();
            array.AddRange(Enum.GetNames(context.Type).Select(n => new OpenApiString(n)));
            // NSwag
            schema.Extensions.Add("x-enumNames", array);
            // Openapi-generator
            schema.Extensions.Add("x-enum-varnames", array);
        }
    }
}

Also tried using the package Unchase.Swashbuckle.AspNetCore.Extensions

options.AddEnumsWithValuesFixFilters();

But results are the same, no change

Enum models are still


2 Answer(s)
  • User Avatar
    1
    liangshiwei created
    Support Team Fullstack Developer

    It works for me:

  • User Avatar
    0
    naeem76 created

    That at least helped me steer in the right direction. Just learned that the order of that function matters, I had it at the end, we have a couple of other settings, but when I put it right after the line options.CustomSchemaIds(type => type.FullName);, it worked.

    Thank you!

Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06