Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Part 4 - EnumerationToEnumSchemaFilter.cs
// Import Swashbuckle.AspNetCore.SwaggerGen
public class EnumerationToEnumSchemaFilter : ISchemaFilter
public void Apply(OpenApiSchema schema, SchemaFilterContext context)
if (!context.Type.IsSubclassOf(typeof(Enumeration)))
var fields = context.Type.GetFields(BindingFlags.Static | BindingFlags.Public);
schema.Enum = fields.Select(field => new OpenApiString(field.Name)).Cast<IOpenApiAny>().ToList();
schema.Type = "string";
schema.Properties = null;
schema.AllOf = null;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.