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

swagger error: Conflicting schemaIds: Duplicate schemaIds detected for types A and B

Every class in the swagger JSON must have a unique schemaId. Swashbuckler tries to just use the class name as a simple schemaId, however if you have two classes in different namespaces with the same name (as you do) this will not work. As the error suggests, you can use the config setting “UseFullTypeNameInSchemaIds*” for … Read more

How to export swagger.json (or yaml)

The URL of the API definiton is displayed in the top bar of Swagger UI – in your example it’s /v2/api-docs?group=full-petstore-api So the full URL appears to be http://localhost:8080/v2/api-docs?group=full-petstore-api In newer versions of Swagger UI, the link to the API definition is often displayed below the API title, so you can right-click the link and … Read more

How to send custom headers with requests in Swagger UI?

You can add a header parameter to your request, and Swagger-UI will show it as an editable text box: swagger: “2.0” info: version: 1.0.0 title: TaxBlaster host: taxblaster.com basePath: /api schemes: – http paths: /taxFilings/{id}: get: parameters: – name: id in: path description: ID of the requested TaxFiling required: true type: string – name: auth … Read more

How to configure Spring Security to allow Swagger URL to be accessed without authentication

Adding this to your WebSecurityConfiguration class should do the trick. @Configuration public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter { @Override public void configure(WebSecurity web) throws Exception { web.ignoring().antMatchers(“/v2/api-docs”, “/configuration/ui”, “/swagger-resources/**”, “/configuration/security”, “/swagger-ui.html”, “/webjars/**”); } }

Setting up Swagger (ASP.NET Core) using the Authorization headers (Bearer)

ApiKeyScheme was deprecated, in version 5 you can use like this: services.AddSwaggerGen(c => { c.SwaggerDoc(“v1”, new Info { Title = “You api title”, Version = “v1” }); 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 … 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