-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proper generation of c# enums using the the OpenAPI 3.x spec #1387
Comments
I see there is a solution to this problem using Swashbuckle.AspNetCore.Filters so I'm closing. |
Can you provide solution? |
@RouR I use the following (would require a little tweaking to yield the original ask above):
The filter itself:
And in your Startup, register the filter with:
The resulting enum will be described using the values within the EnumMember attribute values instead of their indices. |
I wish there was a better way to do this, but using WhitWaldo solution I came up with this. I like it a bit more because it uses the Description attribute. And in your Startup, register the filter with:
It produces this:
|
Thanks for contributing to Swashbuckle.AspNetCore! As per the contributing guidelines, please adhere to the following rules of thumb before submitting your issue:
I'm using Swashbuckle.AspNetCore -Version 5.0.0-rc4
In my case I have the following issue:
I have a C# enum defined like so:
public enum ObjectState
{
Unchanged = 0,
Add = 1,
Update = 2,
Delete = 3
}
This get represented in the OpenAPI 3.x doc as
"components": {
"schemas": {
"ObjectState": {
"enum": [
0,
1,
2,
3
],
"type": "integer",
"format": "int32"
},
When I run the NSwag client generator all it has as a reference is the OpenAPI spec which of course is missing the name portion of the enum. NSwag generates the following object for the client which is basically unusable:
Would it be possible to use oneOf from the OpenAPI spec instead to properly represent a C# enum
See the discussion here:
OAI/OpenAPI-Specification#681
According to handrews the spec is not going to be changed regarding this issue and suggested using something like the following from the OpenAPI spec to represent the enum.
oneOf:
title: Sunny
description: Blue sky
title: Cloudy
description: Slightly overcast
title: Rainy
description: Take an umbrella with you
Thoughts? Work arounds???
Much appreciated
Kevin
The text was updated successfully, but these errors were encountered: