How to define mutually exclusive query parameters in Swagger (OpenAPI)?

Mutually exclusive parameters are possible (sort of) in OpenAPI 3.x: Define the mutually exclusive parameters as object properties, and use oneOf or maxProperties to limit the object to just 1 property. Use the parameter serialization method style: form and explode: true, so that the object is serialized as ?propName=value. An example using the minProperties and … Read more

How to describe this POST JSON request body in OpenAPI (Swagger)?

I made it work with: post: consumes: – application/json produces: – application/json – text/xml – text/html parameters: – name: body in: body required: true schema: # Body schema with atomic property examples type: object properties: testapi: type: object properties: messageId: type: string example: kkkk8 messageDateTime: type: string example: ‘2014-08-17T14:07:30+0530’ testapiBody: type: object properties: cameraServiceRq: type: … Read more

Why `additionalProperties` is the way to represent Dictionary/Map in Swagger/OpenAPI 2.0

Chen, I think your answer is correct. Some further background that might be helpful: In JavaScript, which was the original context for JSON, an object is like a hash map of strings to values, where some values are data, others are functions. You can think of each name-value pair as a property. But JavaScript doesn’t … Read more

Swagger: map of

Using additionalPropertiesis the proper way to describe hashmap with OpenAPI (fka. Swagger) Specification but Swagger UI do not render them for now. The issue is tracked here https://github.com/swagger-api/swagger-ui/issues/1248 Meanwhile you can use this trick: define a non required property (defaultin the example below) of the same type of the map’s objects and give some hint … Read more

Is it possible to add Authentication to access to NestJS’ Swagger Explorer

Securing access to your Swagger with HTTP Basic Auth using NestJS with Express First run npm i express-basic-auth then add the following to your main.{ts,js}: // add import import * as basicAuth from ‘express-basic-auth’; // … // Sometime after NestFactory add this to add HTTP Basic Auth app.use( [‘/docs’, ‘/docs-json’], basicAuth({ challenge: true, users: { … Read more

Migrating from Springfox Swagger 2 to Springdoc Open API

Migrating from SpringFox Remove springfox and swagger 2 dependencies. Add springdoc-openapi-ui dependency instead. <dependency> <groupId>org.springdoc</groupId> <artifactId>springdoc-openapi-ui</artifactId> <version>@springdoc.version@</version> </dependency> Replace swagger 2 annotations with swagger 3 annotations (it is already included with springdoc-openapi-ui dependency). Package for swagger 3 annotations is io.swagger.v3.oas.annotations. @ApiParam -> @Parameter @ApiOperation -> @Operation @Api -> @Tag @ApiImplicitParams -> @Parameters @ApiImplicitParam -> @Parameter … Read more