C
C#5mo ago
SwaggerLife

How to tell SwaggerUI to display `Enum` by the name and not integer value?

I want SwaggerUI to display Enum by the name and not integer value. The only problem is that when triggering an action it's sending the name to the pipline.
public class EnumSchemaFilter : ISchemaFilter
{
public void Apply(OpenApiSchema model, SchemaFilterContext context)
{
if (context.Type.IsEnum)
{
model.Enum.Clear();
Enum.GetNames(context.Type)
.ToList()
.ForEach(name => model.Enum.Add(new OpenApiString($"{Convert.ToInt64(Enum.Parse(context.Type, name))} = {name}")));
}
}
}
public class EnumSchemaFilter : ISchemaFilter
{
public void Apply(OpenApiSchema model, SchemaFilterContext context)
{
if (context.Type.IsEnum)
{
model.Enum.Clear();
Enum.GetNames(context.Type)
.ToList()
.ForEach(name => model.Enum.Add(new OpenApiString($"{Convert.ToInt64(Enum.Parse(context.Type, name))} = {name}")));
}
}
}
Is there a way I can tell swagger to only display the enums as their string name? But it should still handle everything by their integer values?
0 Replies
No replies yetBe the first to reply to this messageJoin