-
Notifications
You must be signed in to change notification settings - Fork 10.3k
OpenApi Enums generating no schema #58230
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
Comments
If you're looking to get a textual representation of the enums that you can serialize, you can try using the
I'm not super familiar with this pattern of using
Although,
Are you able to get a minimal repro with this issue? Also, do you happen to recall between which version change it stopped working? |
This is global and absolutely is not what I want for anywhere else. It should just work like Swashbuckle and every other environment and generate the enums list. This is baseline functionality and should (I'd say MUST) be the default behavior to generate this for even OpenAPI 2 support because the current behavior breaks other .NET stuff if you enable it to work as it should, and if you don't, gives you junk with no work around. And right now I can't even intercept enums and do this myself like it should be because they don't even get passed in to IOpenApiSchemaTransformer. Note, that nothing ever gets populated in OpenApiSchema schema in the TransformAsync method either, which it should because an enum is an enum and this should be populated as it is with Nswag and Swashbuckle in their equivalents.
They FINALLY fixed Enums in OpenAPI by using the oneof syntax for enums using OneOf to generate name, value, and description in oneof. This should be very high priority. Obviously if I can get enums into an IOpenApiSchemaTransformer as should be happening, I can add this myself, but this should be default behavior for 10.0 at the very least. (see also generics are now supported in OpenAPI 3.1 and .net should have full support too)
That's fine, however there's no way to manually generate it either because enums don't get passed into the IOpenApiSchemaTransformer interface.
Just add an enum with key/values to an object that is referenced on a minimal api as the output of that api, and then add an IOpenApiSchemaTransformer and register it and put in a breakpoint. It fires for all primatives and even objects, but doens't fire for enums for some reason. I tried going back and couldn't find where it broke. |
Update: I was able to hack around this: The enum does get passed into the IopenApiSchemaTransformer, but the Enums array is empty when it shouldn't be so if you test based on this you won't be able to do anything. This gets the enum properly so that you can fix (most) of what's wrong. This does allow me to generate this:
For anyone that needs this, here's an schema transformer that fixes what's discussed. But there definitely is still a bug that Enum isn't being populated AND it isn't a viable workaround to change your JsonOptions globally just to fix even the basic case. |
@JohnGalt1717 I see what's going on. As long as your transformer is able to access the enum type and modify the schema, it should be good. As mentioned in the other thread, support for OpenAPI v3.1 isn't included at the moment but hopefully will be in the future. |
This issue has been resolved and has not had any activity for 1 day. It will be closed for housekeeping purposes. See our Issue Management Policies for more information. |
Even without OpenAPI 3.1, this should at least produce OpenAPI 2.0 by default, automatically without intervention. That means that the enums list should be populated automatically and independently of any global json settings. Please reopen as the root issue isn't resolved. |
We don't produce OpenApi v2.0 by default, we produce OpenApi v3.0 since that's much newer. You can change the version used via options though. |
The enums list is also part of V3.0 standard and should be populated in that case too. |
This OpenApi implementation is a disaster in comparation of Swashbuckle. Everything related to enums does not work as expected. As a user you cant expect that this needs a lot of workarrounds |
Had to implement OpenAPI generation for the first time. Obviously I jumped straight to the I would really want to rely on an officially supported solution, but it's just not there. |
Agreed! Upgrading from Swashbuckle and it's so inconsistent (also weird it doesn't support EnumMember).... public enum BillingStatus
{
Trialing = 0,
Active = 1
} Previous{
"BillingStatus": {
"enum": [
0,
1
],
"type": "integer",
"description": "\n\n0 = Trialing\n\n1 = Active",
"format": "int32",
"x-enumNames": [
"Trialing",
"Active"
]
}
} New {
"BillingStatus": {
"type": "integer"
}
} |
Is there an existing issue for this?
Describe the bug
(References)
#58195
#57979
Using the following Model which correctly gets created in the OpenApi.json file:
This is the definition it creates:
This creates a definition for the enum but the definition for the enum itself is empty:
Here's the NotificationTypes enum:
Expected Behavior
This should be the base OpenApi 2 version that just has the text representation AND it should have OneOf syntax like OpenApi 3 has with Type, Enum value and Title (name)
Ideally it should also inject x-ms-enum if you want on enums and give key/values since it's so widely supported by OpenAPI client generators.
Steps To Reproduce
Create an endpoint that returns the above object.
Generate the openapi.json file.
You'll see the bogus output.
Exceptions (if any)
No response
.NET Version
9.0.100-rc.1.24452.12
Anything else?
This also happens with the latest nighly 9.0.0-rtm.24477.5
It did work at one point in the beta process but is broken now. I don't know where it broke.
Also, I have the following that I was using to put in the 3.1 and x-ms-enum functionality:
Which also used to work. But it no longer works and if you put a break point in, NotificationTypes is never one of the passed in types (nor is any other enum) yet the output openapi.json does have it listed as if it did process it.
The text was updated successfully, but these errors were encountered: