Following helpedhttps://github.com/domaindrivendev/Swashbuckle.WebApi/issues/162
AddSchemaExamples.cs
public class AddSchemaExamples : ISchemaFilter{ public void Apply(Schema schema, SchemaRegistry schemaRegistry, Type type) { if (type == typeof(Product)) { schema.example = new Product { Id = 123, Type = ProductType.Book, Description = "Treasure Island", UnitPrice = 10.0M }; } }}
SwaggerConfig.cs
httpConfig .EnableSwagger(c => { c.SchemaFilter<AddSchemaExamples>() });
My implementation for the Apply since model is dynamic
if (model != null) { schema.Description = model.Description; foreach (var p in schema.Properties) { var mp = model.Data.Properties.SingleOrDefault(x => x.Name == p.Key); if (mp != null) { if (!string.IsNullOrWhiteSpace(mp.Description)) { p.Value.Description = mp.Description; } if(!string.IsNullOrWhiteSpace(mp.Example)) { p.Value.Example = new Microsoft.OpenApi.Any.OpenApiString(mp.Example.ToString()); } } } }