I needed to add a property to a model and I have implemented what is suggested in the selected answer here and it's working in that it removes the property I have tagged with SwaggerIgnorePropertyAttribute attribute of the model.
My question is , if I have several API versions of my application,how to remove it from the swagger doc/schema for certain versions? I only care not to see the added property in swagger. I only really have 1 version of the model across the application even though I have several version of the app.
I added the version like this:
            services.AddSwaggerGen(
                swaggerOptions =>
                {
                    swaggerOptions.SwaggerDoc(
                        "v1",
                        new Info
                        {
                            Title = "Titlebla1",
                            Description = "bla1",
                            Version = "v1"
                        });
                    swaggerOptions.SwaggerDoc(
                        "v2",
                        new Info
                        {
                            Title = "Titlebla2",
                            Description = "bla2",
                            Version = "v2"
                        });
 etc
I know that I can find the version by using SwaggerDocument and doing something like this: swaggerDoc.Info.Version but how can I get access to SwaggerDocument from the Apply in my SwaggerExcludePropertySchemaFilter  class below ?
private class SwaggerExcludePropertySchemaFilter : ISchemaFilter
        {
            public void Apply(Schema schema, SchemaFilterContext context)
            {
                if (schema?.Properties == null)
                {
                    return;
                }
                var excludedProperties = context.SystemType.GetProperties().Where(t => t.GetCustomAttribute<SwaggerIgnorePropertyAttribute>() != null);
                foreach (var excludedProperty in excludedProperties)
                {
                    var propertyToRemove = schema.Properties.Keys.SingleOrDefault(x => string.Equals(x, excludedProperty.Name, StringComparison.OrdinalIgnoreCase));
                    if (propertyToRemove != null)
                    {
                        schema.Properties.Remove(propertyToRemove);
                    }
                }
            }
        }