swagger-2.0

Swagger2 > Document a SpringBoot MvcEndpoint

人盡茶涼 提交于 2019-12-05 20:33:24
I'm currently in the process of trying out Swagger2 on my SpringBoot project (it works great), however, it only picks up my @RestController classes. I was wondering: Can it be used to pick up a Spring-Actuator MvcEndpoint ? Can the Swagger2 components (e.g. /swagger-ui.html , /v2/api-docs ) be hosted under the management port (e.g. http://${management.address}:${management.port} ) , instead of server.port ? Application.java @EnableSwagger2 @SpringBootApplication public class Application { @Bean public Docket api() { return new Docket(DocumentationType.SWAGGER_2) .select() .apis

Define array of multiple models in Swagger 2.0

别等时光非礼了梦想. 提交于 2019-12-05 15:57:28
问题 This is my first foray into Swagger so please be gentle. I have the following definitions: definitions: Payload: type: object properties: indicators: type: array items: $ref: '#/definitions/Indicator' Indicator: type: object properties: type: type: string computeOn: type: array items: type: string default: - close parameters: type: object BBANDS: properties: type: type: string default: BBANDS computeOn: type: array items: type: string default: - close parameters: type: object properties:

Swagger; specify two responses with same code based on optional parameter

杀马特。学长 韩版系。学妹 提交于 2019-12-05 12:00:24
问题 This question is not a duplicate of (Swagger - Specify Optional Object Property or Multiple Responses) because that OP was trying to return a 200 or a 400. I have a GET with an optional parameter; e.g., GET /endpoint?selector=foo . I want to return a 200 whose schema is different based on whether the parameter was passed, e.g.,: GET /endpoint -> {200, schema_1} GET /endpoint?selector=blah -> {200, schema_2} In the yaml, I tried having two 200 codes, but the viewer squashes them down as if I

Swagger 2.0 where to declare Basic Auth Schema

早过忘川 提交于 2019-12-05 10:06:48
问题 How do I define basic authentication using Swagger 2.0 annotations and have it display in swagger UI. In the resource I have: @ApiOperation(value = "Return list of categories", response=Category.class, responseContainer="List", httpMethod="GET", authorizations = {@Authorization(value="basicAuth")}) public Response getCategories(); I looked here: https://github.com/swagger-api/swagger-core/wiki/Annotations#authorization-authorizationscope And it says "Once you've declared and configured which

How to change the response status code for successful operation in Swagger?

吃可爱长大的小学妹 提交于 2019-12-05 03:01:29
As shown in the image, it says "Response Class (Status 200)" for the add operation. However, the add operation has been implemented in such a way that it will never return 200. It returns 201 on success. My question is how can I change the (Status 200) to (Status 201)? The code for this part is as follows: @RequestMapping(method = RequestMethod.PUT, value = "/add") @ApiOperation(value = "Creates a new person", code = 201) @ApiResponses(value = { @ApiResponse(code = 201, message = "Record created successfully"), @ApiResponse(code = 409, message = "ID already taken") }) public ResponseEntity

How to define global parameters that will apply to all paths?

北战南征 提交于 2019-12-05 02:53:37
I want to make the account parameter to be applied to all paths, without any exceptions. Is there any way to do this with Swagger 2? I don't want apply the account parameter for every path. { "swagger": "2.0", "info": { "version": "1.0", "title": "Doc" }, "host": "localhost", "schemes": [ "http" ], "produces": [ "application/json" ], "parameters": { "account": { "in": "header", "name": "X-ACCOUNT", "description": "Account id", "type": "string", "required": true } }, "paths": { "/account": { "get": { "summary": "Get account", "operationId": "getAccount", "responses": { "200": { "description":

Require array to contain at least one element in Swagger Schema Object definition

回眸只為那壹抹淺笑 提交于 2019-12-05 01:16:08
I'm having a Schema Object definition like this in my swagger.yaml : User: type: object properties: username: type: string description: the user name colors: type: array items: { type: string, enum: [ "red", "blue", "green" ] } description: user must have one or more colors associated required: - username - colors However, the generated server still happily accepts POST requests using this schema object as required body parameter that do not contain any colors field. Can I configure Swagger in a way that the color field is always required in a User schema object and ideally also must contain

Subpaths in Swagger YAML declaration

前提是你 提交于 2019-12-05 00:30:20
问题 I am trying to create a REST service by describing it in Swagger YAML. The service has three paths: /versions /partners/{partnerId}/users/{userId}/sessions /partners/{partnerId}/books/{bookId}/ My current YAML file to describe these paths looks like this: swagger: '2.0' info: version: '0.0.1' title: Test API host: api.test.com basePath: / schemes: - https consumes: - application/json produces: - application/json paths: /versions: post: responses: '201': description: Returns all versions.

Swagger 2 accept xml instead of json

扶醉桌前 提交于 2019-12-04 11:19:33
I have a project with spring boot and I want to use swagger2 to document my json web services. I have this configuration : @Configuration @EnableSwagger2 public class Swagger2Config { @Bean public Docket welcomeMessageApi() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.any()) .paths(PathSelectors.any()) .build(); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("My API") .description("Lorem Ipsum is simply dummy text of ...") .termsOfServiceUrl("an url") .contact("contact") .license("") .licenseUrl("") .version("2.0

How do I wrap JSON objects?

霸气de小男生 提交于 2019-12-04 06:41:16
问题 I'm currently looking for a way to wrap JSON in the Swagger UI component. In YAML my object declaration is: restException: properties: message: type: string The output generated by Swagger UI is (whic I agree, is correct): { "message": "string" } and what I want is: "restException": { "message": "string" } I've just find a ugly way to do it by explicitely declaring the wrapper in the YAML file. But it's verry bad since it's also generates when I use "Swagger Codegen" to generate client or