Skip to content

Commit 2904334

Browse files
fix(*): enums to appear as strings in swagger schema
1 parent 093fb69 commit 2904334

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

NorthwindCRUD/Filters/EnumSchemaFilter.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ public void Apply(OpenApiSchema schema, SchemaFilterContext context)
1010
{
1111
if (context.Type.IsEnum)
1212
{
13-
var enumValues = Enum.GetValues(context.Type)
14-
.Cast<object>()
15-
.Select(e => new OpenApiString(e.ToString()))
13+
schema.Type = "string";
14+
schema.Enum = context.Type
15+
.GetEnumNames()
16+
.Select(name => new OpenApiString(name))
1617
.ToList<IOpenApiAny>();
17-
18-
schema.Enum = enumValues;
1918
}
2019
}
2120
}

NorthwindCRUD/Helpers/Enums.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ public enum Shipping
1414

1515
[EnumMember(Value = "AirCargo")]
1616
AirCargo,
17+
18+
[EnumMember(Value = "Mail")]
19+
Mail,
1720
}
1821
}
1922
}

0 commit comments

Comments
 (0)