BEST
DEALS
OF THE
YEAR!
SAVE UP TO $3,000
24 NOV
1 DEC
00 Days
00 Hrs
00 Min
00 Sec
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
    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!

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.1.0-preview. Updated on November 20, 2025, 09:12
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.