Reputation: 13
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,
c.UseAllOfToExtendReferenceSchemas();
will actually fix
this behaviour but, removing this options is not something that
suits my needsswaggerDoc.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 fileTips? (Swashbuckle 5.6.3)
Upvotes: 0
Views: 888
Reputation: 509
If you're using Newtonsoft, you also need this package:
Swashbuckle.AspNetCore.Newtonsoft
And in startup:
services.AddSwaggerGenNewtonsoftSupport(); // needs to be placed after AddSwaggerGen()
You may follow instructions below: https://github.com/domaindrivendev/Swashbuckle.AspNetCore#systemtextjson-stj-vs-newtonsoft
Upvotes: 0