Bearer authentication in Swagger UI, when migrating to Swashbuckle.AspNetCore version 5

Got this working in the end by trial and error. This is the code that works for me: c.AddSecurityDefinition(“Bearer”, new OpenApiSecurityScheme { Description = “JWT Authorization header using the Bearer scheme. \r\n\r\n Enter ‘Bearer’ [space] and then your token in the text input below.\r\n\r\nExample: \”Bearer 12345abcdef\””, Name = “Authorization”, In = ParameterLocation.Header, Type = SecuritySchemeType.ApiKey, … Read more

How to configure Swashbuckle to ignore property on model

If you need to do this but without using JsonIgnore (maybe you still need to serialize/deserialize the property) then just create a custom attribute. [AttributeUsage(AttributeTargets.Property)] public class SwaggerExcludeAttribute : Attribute { } Then a schema filter similar to Johng’s public class SwaggerExcludeFilter : ISchemaFilter { #region ISchemaFilter Members public void Apply(Schema schema, SchemaRegistry schemaRegistry, Type … Read more

Manually set operationId to allow multiple operations with the same verb in Swashbuckle

EDIT This answer relates to Swashbuckle 5.6 and .NET Framework. Please read mwilson’s answer for Swashbuckle and .NET Core You can use the SwaggerOperationAttribute provided by Swashbuckle for that. [SwaggerOperation(“get”)] public IEnumerable<Contact> Get() { …. } [SwaggerOperation(“getById”)] public IEnumerable<Contact> Get(string id) { … } You can use that attribute to add tags and schemes to … Read more

Swagger UI Web Api documentation Present enums as strings?

Enable globally From the docs: httpConfiguration .EnableSwagger(c => { c.SingleApiVersion(“v1”, “A title for your API”); c.DescribeAllEnumsAsStrings(); // this will do the trick }); Enum/string conversion on particular property Also, if you want this behavior only on a particular type and property, use the StringEnumConverter: public class Letter { [Required] public string Content {get; set;} [Required] … Read more