Swashbuckle.AspNetCore icon indicating copy to clipboard operation
Swashbuckle.AspNetCore copied to clipboard

Values of OneOf assigned within an ISchemaFilter have no output

Open ryno1234 opened this issue 2 years ago • 4 comments

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 avatar Nov 08 '22 14:11 ryno1234

@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.

Screenshot 2022-11-15 at 20 59 24

domaindrivendev avatar Nov 15 '22 21:11 domaindrivendev

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.

github-actions[bot] avatar Apr 15 '24 02:04 github-actions[bot]

Please provide a minimal reproducible example as a GitHub repository that demonstrates the issue you're experiencing so we can look into this further.

martincostello avatar Apr 15 '24 06:04 martincostello

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.

github-actions[bot] avatar Jul 14 '24 01:07 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Jul 29 '24 01:07 github-actions[bot]