Skip to content

Commit 7f29389

Browse files
author
bnasslahsen
committed
@CookieValue parameter indents request body. Fixes #419
1 parent 49a1a2e commit 7f29389

File tree

5 files changed

+158
-1
lines changed

5 files changed

+158
-1
lines changed

Diff for: springdoc-openapi-common/src/main/java/org/springdoc/core/AbstractRequestBuilder.java

+7
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
import org.springframework.util.CollectionUtils;
6161
import org.springframework.validation.BindingResult;
6262
import org.springframework.validation.Errors;
63+
import org.springframework.web.bind.annotation.CookieValue;
6364
import org.springframework.web.bind.annotation.PathVariable;
6465
import org.springframework.web.bind.annotation.RequestAttribute;
6566
import org.springframework.web.bind.annotation.RequestHeader;
@@ -258,6 +259,8 @@ private Parameter buildParams(ParameterInfo parameterInfo, Components components
258259
RequestParam.class);
259260
PathVariable pathVar = parameterBuilder.getParameterAnnotation(handlerMethod, parameters, index,
260261
PathVariable.class);
262+
CookieValue cookieValue = parameterBuilder.getParameterAnnotation(handlerMethod, parameters, index,
263+
CookieValue.class);
261264

262265
Parameter parameter = null;
263266
RequestInfo requestInfo;
@@ -281,6 +284,10 @@ else if (pathVar != null) {
281284
// check if PATH PARAM
282285
requestInfo = new RequestInfo(ParameterType.PATH_PARAM, pathVar.value(), Boolean.TRUE, null);
283286
parameter = buildParam(parameterInfo, components, requestInfo, jsonView);
287+
} else if (cookieValue != null) {
288+
requestInfo = new RequestInfo(ParameterType.COOKIE, cookieValue.value(), cookieValue.required(),
289+
cookieValue.defaultValue());
290+
parameter = buildParam(parameterInfo, components, requestInfo, jsonView);
284291
}
285292
// By default
286293
if (RequestMethod.GET.equals(requestMethod) || (parameterInfo.getParameterModel() != null && ParameterIn.PATH.toString().equals(parameterInfo.getParameterModel().getIn()))) {

Diff for: springdoc-openapi-common/src/main/java/org/springdoc/core/RequestInfo.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public String type() {
5252
}
5353

5454
public enum ParameterType {
55-
QUERY_PARAM("query"), HEADER_PARAM("header"), PATH_PARAM("path");
55+
QUERY_PARAM("query"), HEADER_PARAM("header"), PATH_PARAM("path"), COOKIE("cookie");
5656

5757
private final String value;
5858

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
*
3+
* * Copyright 2019-2020 the original author or authors.
4+
* *
5+
* * Licensed under the Apache License, Version 2.0 (the "License");
6+
* * you may not use this file except in compliance with the License.
7+
* * You may obtain a copy of the License at
8+
* *
9+
* * https://www.apache.org/licenses/LICENSE-2.0
10+
* *
11+
* * Unless required by applicable law or agreed to in writing, software
12+
* * distributed under the License is distributed on an "AS IS" BASIS,
13+
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* * See the License for the specific language governing permissions and
15+
* * limitations under the License.
16+
*
17+
*/
18+
19+
package test.org.springdoc.api.app87;
20+
21+
import java.util.UUID;
22+
23+
import io.swagger.v3.oas.annotations.Operation;
24+
import io.swagger.v3.oas.annotations.parameters.RequestBody;
25+
26+
import org.springframework.http.ResponseEntity;
27+
import org.springframework.web.bind.annotation.CookieValue;
28+
import org.springframework.web.bind.annotation.PathVariable;
29+
import org.springframework.web.bind.annotation.PutMapping;
30+
import org.springframework.web.bind.annotation.RestController;
31+
32+
33+
@RestController("cookie")
34+
public class HelloController {
35+
36+
@PutMapping("/{itemId}")
37+
@Operation
38+
public ResponseEntity<Item> putItem(
39+
@CookieValue(
40+
name = "cookie"
41+
) String cookie,
42+
@PathVariable UUID itemId,
43+
@RequestBody Item item
44+
) {
45+
return ResponseEntity.ok(item);
46+
}
47+
48+
public static class Item {
49+
}
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
*
3+
* * Copyright 2019-2020 the original author or authors.
4+
* *
5+
* * Licensed under the Apache License, Version 2.0 (the "License");
6+
* * you may not use this file except in compliance with the License.
7+
* * You may obtain a copy of the License at
8+
* *
9+
* * https://www.apache.org/licenses/LICENSE-2.0
10+
* *
11+
* * Unless required by applicable law or agreed to in writing, software
12+
* * distributed under the License is distributed on an "AS IS" BASIS,
13+
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* * See the License for the specific language governing permissions and
15+
* * limitations under the License.
16+
*
17+
*/
18+
19+
package test.org.springdoc.api.app87;
20+
21+
import test.org.springdoc.api.AbstractSpringDocTest;
22+
23+
import org.springframework.boot.autoconfigure.SpringBootApplication;
24+
25+
public class SpringDocApp87Test extends AbstractSpringDocTest {
26+
27+
@SpringBootApplication
28+
static class SpringDocTestApp {}
29+
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"openapi": "3.0.1",
3+
"info": {
4+
"title": "OpenAPI definition",
5+
"version": "v0"
6+
},
7+
"servers": [
8+
{
9+
"url": "http://localhost",
10+
"description": "Generated server url"
11+
}
12+
],
13+
"paths": {
14+
"/{itemId}": {
15+
"put": {
16+
"tags": [
17+
"hello-controller"
18+
],
19+
"operationId": "putItem",
20+
"parameters": [
21+
{
22+
"name": "cookie",
23+
"in": "cookie",
24+
"required": true,
25+
"schema": {
26+
"type": "string"
27+
}
28+
},
29+
{
30+
"name": "itemId",
31+
"in": "path",
32+
"required": true,
33+
"schema": {
34+
"type": "string",
35+
"format": "uuid"
36+
}
37+
}
38+
],
39+
"requestBody": {
40+
"content": {
41+
"application/json": {
42+
"schema": {
43+
"$ref": "#/components/schemas/Item"
44+
}
45+
}
46+
}
47+
},
48+
"responses": {
49+
"200": {
50+
"description": "default response",
51+
"content": {
52+
"*/*": {
53+
"schema": {
54+
"$ref": "#/components/schemas/Item"
55+
}
56+
}
57+
}
58+
}
59+
}
60+
}
61+
}
62+
},
63+
"components": {
64+
"schemas": {
65+
"Item": {
66+
"type": "object"
67+
}
68+
}
69+
}
70+
}

0 commit comments

Comments
 (0)