Hide AutoQuery fields in OpenApiFeature?

I would like to hide the fields automatically added to swagger-ui when using AutoQuery.

For example, for a simple service that reads from a database table, such as

public class ReadPrice : QueryDb<Price>, IGet
{
}

The following fields are shown in the swagger endpoint

Is it possible to configure the OpenApiFeature plugin so the all of the AutoQuery fields are hidden for all services?

I do not want to add additional annotations to each model.

@Keith you can use the SchemaPropertyFilter option on the OpenApiFeature to filter out properties. Example below of filtering out all properties from QueryBase which is the class where those properties are from.

Plugins.Add(new OpenApiFeature
{
    SchemaPropertyFilter = property =>
    {
        if (property.PropertyInfo.DeclaringType?.Name == "QueryBase")
        {
            property.PropertyInfo.AddAttributes(new IgnoreDataMemberAttribute());
        }
    }
});

More info on OpenApi filtering options in our docs.

Hope that helps!

Hello @layoric, as always, brilliant support that worked perfectly. Thank you.

1 Like