-
-
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
C# Enums aren't shown as dropdowns in Swagger UI #3645
Comments
Isnt this a problem with Swagger UI? |
I'm not sure whose problem it is. |
This problem also occurs when the enum is nullable |
This doesn't work in all of the different Swagger UIs I've used (Swagger UI and RapiDoc). In looking at the documentation (OpenApi spec and swagger.io about enums), it doesn't appear that any usage of enum uses this format. So I think this would need to be fixed here in NSwag. |
using the test YAML below, only /1 and /6 are displayed incorrectly - telling me that SwaggerUI has an issue with enums in It does seem bizarre to have a oneOf with only one entry, but that's needed for defaults as far as I can tell (probably other stuff too).
|
I've opened an issue with Swagger-UI: swagger-api/swagger-ui#7912. That said, |
It looks like the Swagger-UI issue also affects This also affects body objects that need endpoint-specific config |
If I'm reading back through history correctly, at some point in the past |
thinking on this more - this could be exposed as an option e.g. "ModelPropertyOverrideMethod" with options "allOf" and "oneOf" (leaving "anyOf" out until a consumer that only works with that is identified). Because swagger-ui is used for the hosted docs UI, and still mentioned in the docs by AllowReferencesWithProperties, I'd push for |
i encountered this problem as well, it affect only the openapi3 documentation but not the previus ones |
there is any new insight on how to workaroud this problem? |
an even better solution is to add the following postOperation: conf.PostProcess = (x) =>
{
foreach (var parameter in x.Operations
.SelectMany(x => x.Operation.Parameters)
.Where(x => x.Schema.OneOf.Count == 1 && x.Schema.OneOf.Single().Reference != null && x.Schema.OneOf.Single().Reference.IsEnumeration))
{
parameter.Schema.AllOf.Add(parameter.Schema.OneOf.Single());
parameter.Schema.OneOf.Clear();
}
}; this will mantain the default values in the interface |
Environment
.NET 5, NSwag AspNet.Core 13.13.2, NSwag.MsBuild 13.13.2
Steps
Let's imagine an API endpoint that accepts a model with property of enum type:
It is generated as the following definition in specification:
Expected result
Property of enum type is displayed in Swagger UI as dropdown.
Actual result
Property is displayed as text input field:
Notes
When I move enum to the top level like this, it works as expected and is displayed as a dropdown:
The text was updated successfully, but these errors were encountered: