Swashbuckle.AspNetCore
Swashbuckle.AspNetCore copied to clipboard
Values of OneOf assigned within an ISchemaFilter have no output
I have an ISchemaFilter where I manually generate some addition schemas from some types and then add those returned schemas to the OneOf
property. This generated .json output does not contain any reference to oneOf
. I would think I would see my generated schemas listed there.
Note: I realize Swashbuckle comes with support for Polymorphic models out of the box, try not to get hung up on my example below. :)
Version: 6.4.0
public class SwaggerPolymorphicSchemaFilter : ISchemaFilter
{
public void Apply(OpenApiSchema schema, SchemaFilterContext context)
{
// Setup this model as having a discriminator
schema.Discriminator = new OpenApiDiscriminator()
{
PropertyName = "AnimalType";
};
OpenApiSchema dogSchema = context.SchemaGenerator.GenerateSchema(typeof(MyNamespace.DogModel), context.SchemaRepository);
OpenApiSchema catSchema = context.SchemaGenerator.GenerateSchema(typeof(MyNamespace.CatModel), context.SchemaRepository);
schema.OneOf.Add(dogSchema);
schema.OneOf.Add(catSchema);
}
}
@ryno1234 I just applied your filter above in a test project and can confirm it's working as expected (see screenshot below). Please create a sample project that repro's your issue and post to github so I can pull down and troubleshoot.

This issue is stale because it has been open for 60 days with no activity. It will be automatically closed in 14 days if no further updates are made.
Please provide a minimal reproducible example as a GitHub repository that demonstrates the issue you're experiencing so we can look into this further.
This issue is stale because it has been open for 60 days with no activity. It will be automatically closed in 14 days if no further updates are made.
This issue was closed because it has been inactive for 14 days since being marked as stale.