Skip to content
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

Enum is missing from components/schemas section #2629

Open
IannisIP opened this issue Apr 7, 2023 · 2 comments
Open

Enum is missing from components/schemas section #2629

IannisIP opened this issue Apr 7, 2023 · 2 comments
Labels
bug help-wanted A change up for grabs for contributions from the community

Comments

@IannisIP
Copy link

IannisIP commented Apr 7, 2023

I have the following structure
//controller
GetProducts(string id, [FromQuery] Product)

//Product.cs class contains an enum member
Product {EnumA ExampleA}

//startup.cs
services.AddSwaggerGen(c =>
{
c.UseAllOfToExtendReferenceSchemas();
}

When trying to inspect the API for getting products using swagger ui, I get a resolver issue for the EnumA, because the in the generated json file there's not definition in components/schemas for the EnumA even though it is referenced in the paths section of the json. Something like this
//paths section of the json
{
"name": "ExampleA",
"in": "query",
"schema": {
"allOf": [
{
"$ref": "#/components/schemas/EnumA"
}
]
}
}

I tried a few things,

  1. removing c.UseAllOfToExtendReferenceSchemas(); will actually fix this behaviour but, removing this options is not something that suits my needs
  2. changingthe annotation of the parameter from [FromQuery] to -> [FromBody] will also fix this behaviour and have the component/schema for this Enum be generated, but also this options is something that doesn't suit my need
  3. creating a DocumentFilter and trying to manually add this enum for the schema definitions using something like
    swaggerDoc.Components.Schemas.Add("EnumA") .... will throw and error because swashbuckle has this Enum referenced at runtime but somehow it's not outputed in the final json file

Tips? (Swashbuckle 5.6.3)

@Havunen
Copy link

Havunen commented Feb 18, 2024

Have you tested this with DotSwashbuckle does this issue still reproduce there?

@Havunen
Copy link

Havunen commented Feb 25, 2024

I belive this was fixed in DotSwashbuckle 3.0.7 Havunen#7

@martincostello martincostello added bug help-wanted A change up for grabs for contributions from the community labels Apr 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug help-wanted A change up for grabs for contributions from the community
Projects
None yet
Development

No branches or pull requests

3 participants