Skip to content

Commit bfc57ab

Browse files
committed
buildApiResponses ignores produced ContentType in case of many @operation. Fixes #2477
1 parent cb3b772 commit bfc57ab

File tree

4 files changed

+128
-1
lines changed

4 files changed

+128
-1
lines changed

springdoc-openapi-starter-common/src/main/java/org/springdoc/core/service/GenericResponseService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ private boolean isValidHttpCode(String httpCode, MethodParameter methodParameter
772772
if (isHttpCodePresent(httpCode, responseSet))
773773
result = true;
774774
}
775-
else if (httpCode.equals(evaluateResponseStatus(method, method.getClass(), false)))
775+
if (httpCode.equals(evaluateResponseStatus(method, method.getClass(), false)))
776776
result = true;
777777
}
778778
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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.app216;
24+
25+
26+
27+
import io.swagger.v3.oas.annotations.Operation;
28+
29+
import org.springframework.web.bind.annotation.GetMapping;
30+
import org.springframework.web.bind.annotation.RestController;
31+
32+
33+
@RestController
34+
public class HelloController {
35+
36+
@Operation(description = "a")
37+
@GetMapping(path = "/", produces = "a/a")
38+
public String a() {
39+
return "A";
40+
}
41+
42+
@Operation(description = "b")
43+
@GetMapping(path = "/", produces = "b/b")
44+
public String b() {
45+
return "B";
46+
}
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
*
3+
* * Copyright 2019-2023 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.v30.app216;
20+
21+
import org.springdoc.core.customizers.SpecPropertiesCustomizer;
22+
import test.org.springdoc.api.v30.AbstractSpringDocV30Test;
23+
24+
import org.springframework.boot.autoconfigure.SpringBootApplication;
25+
import org.springframework.boot.test.context.SpringBootTest;
26+
import org.springframework.test.context.ActiveProfiles;
27+
28+
/**
29+
* <p>
30+
* A test for {@link SpecPropertiesCustomizer}
31+
*/
32+
@SpringBootTest
33+
public class SpringDocApp216Test extends AbstractSpringDocV30Test {
34+
35+
@SpringBootApplication
36+
static class SpringDocTestApp {}
37+
38+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
"/": {
15+
"get": {
16+
"tags": [
17+
"hello-controller"
18+
],
19+
"description": "a",
20+
"operationId": "b_1",
21+
"responses": {
22+
"200": {
23+
"description": "OK",
24+
"content": {
25+
"b/b": {
26+
"schema": {
27+
"type": "string"
28+
}
29+
},
30+
"a/a": {
31+
"schema": {
32+
"type": "string"
33+
}
34+
}
35+
}
36+
}
37+
}
38+
}
39+
}
40+
},
41+
"components": {}
42+
}

0 commit comments

Comments
 (0)