Skip to content

Commit

Permalink
Merge pull request #37 from IgniteUI/dgddimitrov/enums-serialization
Browse files Browse the repository at this point in the history
fix(*): enums to appear as strings in swagger schema
  • Loading branch information
zdrawku authored Oct 11, 2024
2 parents 41a6579 + 8824903 commit 0061d70
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
9 changes: 4 additions & 5 deletions NorthwindCRUD/Filters/EnumSchemaFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ public void Apply(OpenApiSchema schema, SchemaFilterContext context)
{
if (context.Type.IsEnum)
{
var enumValues = Enum.GetValues(context.Type)
.Cast<object>()
.Select(e => new OpenApiString(e.ToString()))
schema.Type = "string";
schema.Enum = context.Type
.GetEnumNames()
.Select(name => new OpenApiString(name))
.ToList<IOpenApiAny>();

schema.Enum = enumValues;
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions NorthwindCRUD/Helpers/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public enum Shipping

[EnumMember(Value = "AirCargo")]
AirCargo,

[EnumMember(Value = "Mail")]
Mail,
}
}
}

0 comments on commit 0061d70

Please sign in to comment.