How to use ‘Authorization: Bearer ‘ in a Swagger Spec

Maybe this can help: swagger: ‘2.0’ info: version: 1.0.0 title: Bearer auth example description: > An example for how to use Bearer Auth with OpenAPI / Swagger 2.0. host: basic-auth-server.herokuapp.com schemes: – http – https securityDefinitions: Bearer: type: apiKey name: Authorization in: header description: >- Enter the token with the `Bearer: ` prefix, e.g. “Bearer … Read more

Why HATEOAS starts creating issue for spring-boot version >= 2.2.x during startup with Swagger 2.x?

I had this issue with Swagger + HATEOAS in my spring-boot application. The fix is given below (edit your Swagger configuration class): @Configuration @EnableSwagger2 public class SwaggerConfiguration { @Bean public LinkDiscoverers discoverers() { List<LinkDiscoverer> plugins = new ArrayList<>(); plugins.add(new CollectionJsonLinkDiscoverer()); return new LinkDiscoverers(SimplePluginRegistry.create(plugins)); } }

How to specify a property can be null or a reference with swagger

OpenAPI 3.1 Define the property as anyOf of the $ref and type: ‘null’. YAML version: foo: anyOf: – type: ‘null’ # Note the quotes around ‘null’ – $ref: ‘#/components/schemas/Foo’ JSON version: “foo”: { “anyOf”: [ { “type”: “null” }, { “$ref”: “#/components/schemas/Foo” } ] } Why use anyOf and not oneOf? oneOf will fail validation … 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

Specify an array of strings as body parameter in swagger API

Your description of an array of string is correct, but the parameter definition misses the name property to be valid. Here’s a full working example: swagger: “2.0” info: title: A dummy title version: 1.0.0 paths: /path: post: parameters: – in: body description: xxx required: true name: a name schema: type: array items: type: string responses: … 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