Sort API methods in Swagger-UI

Update for Swagger UI 2.1.0+: The sorter parameter has been split into two parameters, as noted in Fix 1040, Fix 1280: apisSorter Apply a sort to the API/tags list. It can be ‘alpha’ (sort by name) or a function (see Array.prototype.sort() to know how sort function works). Default is the order returned by the server … Read more

FastAPI’s RedirectResponse doesn’t work as expected in Swagger UI

To start with, the HTTP OPTIONS, in CORS, is a preflight request that is automatically issued by the browser, before the actual request—is not the one that returns the File response. It requests the permitted communication options for a given server, and the server responds with an Access-Control-Allow-Methods header including a set of permitted methods … Read more

How to hide the Models section in Swagger UI?

To hide the “Models” section, add defaultModelsExpandDepth: -1 to the Swagger UI configuration code in your index.html. Note the option name uses plural Model*s* not Model. // index.html <script> window.onload = function() { // Begin Swagger UI call region const ui = SwaggerUIBundle({ url: “https://petstore.swagger.io/v2/swagger.json”, dom_id: ‘#swagger-ui’, defaultModelsExpandDepth: -1, // <——- Swagger UI also has … Read more

Swagger UI passing authentication token to API call in header

@ApiImplicitParams and @ApiImplicitParam should do the trick: @GET @Produces(“application/json”) @ApiImplicitParams({ @ApiImplicitParam(name = “Authorization”, value = “Authorization token”, required = true, dataType = “string”, paramType = “header”) }) public String getUser(@PathParam(“username”) String userName) { … } From the documentation: You may wish you describe operation parameters manually. This can be for various reasons, for example: Using … Read more

Swagger UI with Multiple Urls

The urls configuration option is supported in Swagger UI 3.0.18 and later. You can use it instead of url like this: window.onload = function() { // Build a system const ui = SwaggerUIBundle({ urls: [ {url: “https://path/to/api1.yaml”, name: “API One”}, {url: “https://path/to/api2.yaml”, name: “API Two”}, ], “urls.primaryName”: “API Two” // default document (if other than … Read more

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

Combining defintions in Swagger docs

Indeed, the example you give here is invalid because $ref can’t co-exist with other properties in the same object. $ref is a JSON Reference, and by definition, will cause the other properties to be ignored. From your question, I assume you’re looking for basic composition (rather than inheritance). This is achievable using the allOf keyword. … Read more

How do I automatically authorize all endpoints with Swagger UI?

If you use Swagger UI v.3.13.0 or later, you can use the following methods to authorize the endpoints automatically: preauthorizeBasic – for Basic auth preauthorizeApiKey – for API keys and OpenAPI 3.x Bearer auth To use these methods, the corresponding security schemes must be defined in your API definition. For example: openapi: 3.0.0 … components: … Read more