Skip to content

Commit 1ab40b2

Browse files
author
bnasslahsen
committed
Multiple paths in controller and DeleteMapping generates incorrect Request Body - Fixes #334
1 parent 60a1ae7 commit 1ab40b2

File tree

5 files changed

+194
-2
lines changed

5 files changed

+194
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.fasterxml.jackson.annotation.JsonView;
44
import io.swagger.v3.oas.annotations.Hidden;
5+
import io.swagger.v3.oas.annotations.enums.ParameterIn;
56
import io.swagger.v3.oas.models.Components;
67
import io.swagger.v3.oas.models.Operation;
78
import io.swagger.v3.oas.models.media.Schema;
@@ -224,9 +225,8 @@ private Parameter buildParams(ParameterInfo parameterInfo, Components components
224225
requestInfo = new RequestInfo(ParameterType.PATH_PARAM, pathVar.value(), Boolean.TRUE, null);
225226
parameter = buildParam(parameterInfo, components, requestInfo, jsonView);
226227
}
227-
228228
// By default
229-
if (RequestMethod.GET.equals(requestMethod)) {
229+
if (RequestMethod.GET.equals(requestMethod) || (parameterInfo.getParameterModel() != null && ParameterIn.PATH.toString().equals(parameterInfo.getParameterModel().getIn()))) {
230230
parameter = this.buildParam(QUERY_PARAM, components, parameterInfo, Boolean.TRUE, null, jsonView);
231231
}
232232

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package test.org.springdoc.api.app73;
2+
3+
import io.swagger.v3.oas.annotations.Parameter;
4+
import io.swagger.v3.oas.annotations.enums.ParameterIn;
5+
import org.springframework.http.HttpStatus;
6+
import org.springframework.web.bind.annotation.*;
7+
import test.org.springdoc.api.app71.Dog;
8+
9+
10+
@RestController
11+
@RequestMapping({"/{country_code}/persons/", "/persons"})
12+
public class HelloController {
13+
14+
@DeleteMapping("/{id}")
15+
@ResponseStatus(HttpStatus.NO_CONTENT)
16+
public void delete(@Parameter(name = "country_code", in = ParameterIn.PATH) String countryCode, @PathVariable("id") String id) {
17+
18+
}
19+
20+
@GetMapping("/{id}")
21+
public String get(@Parameter(name = "country_code", in = ParameterIn.PATH) String countryCode, @PathVariable("id") String id) {
22+
return null;
23+
}
24+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package test.org.springdoc.api.app73;
2+
3+
import test.org.springdoc.api.AbstractSpringDocTest;
4+
5+
public class SpringDocApp73Test extends AbstractSpringDocTest {
6+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package test.org.springdoc.api.app73;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class SpringDocTestApp {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(SpringDocTestApp.class, args);
11+
}
12+
}
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
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+
"/{country_code}/persons/{id}": {
15+
"get": {
16+
"tags": [
17+
"hello-controller"
18+
],
19+
"operationId": "get",
20+
"parameters": [
21+
{
22+
"name": "country_code",
23+
"in": "path",
24+
"required": true,
25+
"schema": {
26+
"type": "string"
27+
}
28+
},
29+
{
30+
"name": "id",
31+
"in": "path",
32+
"required": true,
33+
"schema": {
34+
"type": "string"
35+
}
36+
}
37+
],
38+
"responses": {
39+
"200": {
40+
"description": "default response",
41+
"content": {
42+
"*/*": {
43+
"schema": {
44+
"type": "string"
45+
}
46+
}
47+
}
48+
}
49+
}
50+
},
51+
"delete": {
52+
"tags": [
53+
"hello-controller"
54+
],
55+
"operationId": "delete",
56+
"parameters": [
57+
{
58+
"name": "country_code",
59+
"in": "path",
60+
"required": true,
61+
"schema": {
62+
"type": "string"
63+
}
64+
},
65+
{
66+
"name": "id",
67+
"in": "path",
68+
"required": true,
69+
"schema": {
70+
"type": "string"
71+
}
72+
}
73+
],
74+
"responses": {
75+
"204": {
76+
"description": "default response"
77+
}
78+
}
79+
}
80+
},
81+
"/persons/{id}": {
82+
"get": {
83+
"tags": [
84+
"hello-controller"
85+
],
86+
"operationId": "get_1",
87+
"parameters": [
88+
{
89+
"name": "country_code",
90+
"in": "path",
91+
"required": true,
92+
"schema": {
93+
"type": "string"
94+
}
95+
},
96+
{
97+
"name": "id",
98+
"in": "path",
99+
"required": true,
100+
"schema": {
101+
"type": "string"
102+
}
103+
}
104+
],
105+
"responses": {
106+
"200": {
107+
"description": "default response",
108+
"content": {
109+
"*/*": {
110+
"schema": {
111+
"type": "string"
112+
}
113+
}
114+
}
115+
}
116+
}
117+
},
118+
"delete": {
119+
"tags": [
120+
"hello-controller"
121+
],
122+
"operationId": "delete_1",
123+
"parameters": [
124+
{
125+
"name": "country_code",
126+
"in": "path",
127+
"required": true,
128+
"schema": {
129+
"type": "string"
130+
}
131+
},
132+
{
133+
"name": "id",
134+
"in": "path",
135+
"required": true,
136+
"schema": {
137+
"type": "string"
138+
}
139+
}
140+
],
141+
"responses": {
142+
"204": {
143+
"description": "default response"
144+
}
145+
}
146+
}
147+
}
148+
},
149+
"components": {}
150+
}

0 commit comments

Comments
 (0)