Forum Discussion

Aquasylum's avatar
Aquasylum
Regular Visitor
4 years ago

Manually changing model name using SchemaFilter

I have two entities with the name Order but in different projects which are using .Net Core 3.0. They are both being used in my API project and therefore Swagger throws the Error whereby I have conflicting schemaId's (Swagger does not allow entities or models with duplicate names by default and I don't want to change this).

 

I am trying to build a schema filter but it doesn't seem to be changing the SchemaId i.e the model name so I'm not sure whether I am setting the correct property on the OpenApiSchema object. Here is my filter thus far:

 

    public class OrderFilter : ISchemaFilter
{
    public void Apply(OpenApiSchema schema, SchemaFilterContext context)
    {
        var type = context.Type;
        if (type == typeof(Main.Order))
        {
            schema.Title = "MainOrder";
        }

        if (type == typeof(Order))
        {
            schema.Title = "SideOrder";
        }
    }
}

 Any help and guidance will be appreciated.

No RepliesBe the first to reply