Skip to content

Commit a087eaa

Browse files
author
bnasslahsen
committedFeb 8, 2020
Multiple Parameter Refs throws IllegalStateException (Duplicate key). Fixes #408
1 parent eb865e8 commit a087eaa

File tree

4 files changed

+119
-1
lines changed

4 files changed

+119
-1
lines changed
 

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ else if (!RequestMethod.GET.equals(requestMethod)) {
199199
private LinkedHashMap<String, Parameter> getParameterLinkedHashMap(Components components, MethodAttributes methodAttributes, List<Parameter> operationParameters, Map<String, io.swagger.v3.oas.annotations.Parameter> parametersDocMap) {
200200
LinkedHashMap<String, Parameter> map = operationParameters.stream()
201201
.collect(Collectors.toMap(
202-
Parameter::getName,
202+
parameter -> parameter.getName() !=null ? parameter.getName(): Integer.toString(parameter.hashCode()),
203203
parameter -> parameter,
204204
(u, v) -> {
205205
throw new IllegalStateException(String.format("Duplicate key %s", u));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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.app85;
20+
21+
import io.swagger.v3.oas.annotations.Operation;
22+
import io.swagger.v3.oas.annotations.Parameter;
23+
24+
import org.springframework.web.bind.annotation.GetMapping;
25+
import org.springframework.web.bind.annotation.PathVariable;
26+
import org.springframework.web.bind.annotation.PostMapping;
27+
import org.springframework.web.bind.annotation.RequestMapping;
28+
import org.springframework.web.bind.annotation.RestController;
29+
30+
@RestController
31+
@RequestMapping("/api")
32+
public class HelloController {
33+
34+
@PostMapping("/test/{id}")
35+
@Operation(
36+
parameters = {
37+
@Parameter(ref = "#/components/parameters/paramA"),
38+
@Parameter(ref = "#/components/parameters/paramB")
39+
}
40+
)
41+
public void testme(@PathVariable("id") String id) {
42+
}
43+
}
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.app85;
20+
21+
import test.org.springdoc.api.AbstractSpringDocTest;
22+
23+
import org.springframework.boot.autoconfigure.SpringBootApplication;
24+
25+
public class SpringDocApp85Test extends AbstractSpringDocTest {
26+
27+
@SpringBootApplication
28+
static class SpringDocTestApp {}
29+
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
"/api/test/{id}": {
15+
"post": {
16+
"tags": [
17+
"hello-controller"
18+
],
19+
"operationId": "testme",
20+
"parameters": [
21+
{
22+
"$ref": "#/components/parameters/paramA"
23+
},
24+
{
25+
"$ref": "#/components/parameters/paramB"
26+
},
27+
{
28+
"name": "id",
29+
"in": "path",
30+
"required": true,
31+
"schema": {
32+
"type": "string"
33+
}
34+
}
35+
],
36+
"responses": {
37+
"200": {
38+
"description": "default response"
39+
}
40+
}
41+
}
42+
}
43+
},
44+
"components": {}
45+
}

0 commit comments

Comments
 (0)
Please sign in to comment.