|
| 1 | +/* |
| 2 | + * |
| 3 | + * * |
| 4 | + * * * |
| 5 | + * * * * Copyright 2019-2022 the original author or authors. |
| 6 | + * * * * |
| 7 | + * * * * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | + * * * * you may not use this file except in compliance with the License. |
| 9 | + * * * * You may obtain a copy of the License at |
| 10 | + * * * * |
| 11 | + * * * * https://www.apache.org/licenses/LICENSE-2.0 |
| 12 | + * * * * |
| 13 | + * * * * Unless required by applicable law or agreed to in writing, software |
| 14 | + * * * * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | + * * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | + * * * * See the License for the specific language governing permissions and |
| 17 | + * * * * limitations under the License. |
| 18 | + * * * |
| 19 | + * * |
| 20 | + * |
| 21 | + */ |
| 22 | + |
| 23 | +package test.org.springdoc.api.v30.app192; |
| 24 | + |
| 25 | +import io.swagger.v3.oas.annotations.Operation; |
| 26 | +import io.swagger.v3.oas.annotations.media.Content; |
| 27 | +import io.swagger.v3.oas.annotations.media.Schema; |
| 28 | +import io.swagger.v3.oas.annotations.parameters.RequestBody; |
| 29 | +import io.swagger.v3.oas.annotations.responses.ApiResponse; |
| 30 | +import io.swagger.v3.oas.annotations.responses.ApiResponses; |
| 31 | +import org.springframework.http.HttpStatus; |
| 32 | +import org.springframework.http.MediaType; |
| 33 | +import org.springframework.http.ResponseEntity; |
| 34 | +import org.springframework.web.bind.annotation.GetMapping; |
| 35 | +import org.springframework.web.bind.annotation.PostMapping; |
| 36 | +import org.springframework.web.bind.annotation.ResponseStatus; |
| 37 | +import org.springframework.web.bind.annotation.RestController; |
| 38 | + |
| 39 | +@RestController |
| 40 | +public class HelloController { |
| 41 | + @Operation(description = "Adds 200 as api response, because there are nothing defined to get another response") |
| 42 | + @RequestBody(description = "test value", required = true, content = @Content(schema = @Schema(implementation = String.class))) |
| 43 | + @PostMapping(value = "/postWithoutAnyResponse", produces = MediaType.APPLICATION_JSON_VALUE) |
| 44 | + public void postWithoutAnyResponse(String test) {} |
| 45 | + |
| 46 | + @Operation(description = "Adds 201 as api response, because it defined by @ResponseStatus") |
| 47 | + @PostMapping(value = "/postWithResponseStatusOnly", produces = MediaType.APPLICATION_JSON_VALUE) |
| 48 | + @ResponseStatus(value = HttpStatus.CREATED) |
| 49 | + public ResponseEntity<String> postWithResponseStatusOnly() { |
| 50 | + return ResponseEntity.ok("hello"); |
| 51 | + } |
| 52 | + |
| 53 | + @Operation(description = "Adds 200 as additional api response, because it defined by @ResponseStatus", |
| 54 | + responses = { |
| 55 | + @ApiResponse(responseCode = "422", description = "Test") |
| 56 | + }) |
| 57 | + @ApiResponses({ |
| 58 | + @ApiResponse(responseCode = "409", description = "Test 2") |
| 59 | + }) |
| 60 | + @GetMapping(value = "/withResponseStatus", produces = MediaType.APPLICATION_JSON_VALUE) |
| 61 | + @ResponseStatus(value = HttpStatus.OK) |
| 62 | + public ResponseEntity<String> withResponseStatus() { |
| 63 | + return ResponseEntity.ok("hello"); |
| 64 | + } |
| 65 | + |
| 66 | + @Operation(description = "Adds 200 as api response, because it defined by @ResponseStatus") |
| 67 | + @GetMapping(value = "/withResponseStatusOnly", produces = MediaType.APPLICATION_JSON_VALUE) |
| 68 | + @ResponseStatus(value = HttpStatus.OK) |
| 69 | + public ResponseEntity<String> withResponseStatusOnly() { |
| 70 | + return ResponseEntity.ok("hello"); |
| 71 | + } |
| 72 | + |
| 73 | + @Operation(description = "Doesn't creates the default 200 Response, because there are explicit declared api responses." + |
| 74 | + "This test ensures that the current default handling is not changed, because otherwise very many tests will fail.", |
| 75 | + responses = { |
| 76 | + @ApiResponse(responseCode = "422", description = "Test") |
| 77 | + }) |
| 78 | + @ApiResponses({ |
| 79 | + @ApiResponse(responseCode = "409", description = "Test 2") }) |
| 80 | + @GetMapping(value = "/withoutResponseStatus", produces = MediaType.APPLICATION_JSON_VALUE) |
| 81 | + public ResponseEntity<String> withoutResponseStatus() { |
| 82 | + return ResponseEntity.ok("hello"); |
| 83 | + } |
| 84 | + |
| 85 | + |
| 86 | + @Operation(description = "Results in the default handling like before") |
| 87 | + @GetMapping(value = "/withoutAnyResponseInformation", produces = MediaType.APPLICATION_JSON_VALUE) |
| 88 | + public ResponseEntity<String> withoutAnyResponseInformation() { |
| 89 | + return ResponseEntity.ok("hello"); |
| 90 | + } |
| 91 | + |
| 92 | + @Operation(description = "Overwrites the 200 @ResponseStatus-Information by the explicit declared @ApiResponse", |
| 93 | + responses = { |
| 94 | + @ApiResponse(responseCode = "200", description = "Test2", content = @Content), |
| 95 | + @ApiResponse(responseCode = "422", description = "Test") |
| 96 | + }) |
| 97 | + @ApiResponses({ |
| 98 | + @ApiResponse(responseCode = "409", description = "Test 2") |
| 99 | + }) |
| 100 | + @GetMapping(value = "/overwrite200InOperation", produces = MediaType.APPLICATION_JSON_VALUE) |
| 101 | + @ResponseStatus(value = HttpStatus.OK) |
| 102 | + public ResponseEntity<String> overwrite200InOperation() { |
| 103 | + return ResponseEntity.ok("hello"); |
| 104 | + } |
| 105 | + |
| 106 | + @Operation(description = "Overwrites the 200 @ResponseStatus-Information by the explicit declared @ApiResponse", |
| 107 | + responses = { |
| 108 | + @ApiResponse(responseCode = "422", description = "Test") |
| 109 | + }) |
| 110 | + @ApiResponses({ |
| 111 | + @ApiResponse(responseCode = "200", description = "Test2", content = @Content), |
| 112 | + @ApiResponse(responseCode = "409", description = "Test 2") |
| 113 | + }) |
| 114 | + @GetMapping(value = "/overwrite200InDoc", produces = MediaType.APPLICATION_JSON_VALUE) |
| 115 | + @ResponseStatus(value = HttpStatus.OK) |
| 116 | + public ResponseEntity<String> overwrite200InDoc() { |
| 117 | + return ResponseEntity.ok("hello"); |
| 118 | + } |
| 119 | +} |
0 commit comments