Skip to content

Commit df22b1a

Browse files
authored
Merge pull request #1491 from mshima/patch-2
Set containingClass at MethodParameter
2 parents d46b735 + e6e5f4f commit df22b1a

File tree

6 files changed

+179
-2
lines changed

6 files changed

+179
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ private static Stream<MethodParameter> fromSimpleClass(Class<?> paramClass, Fiel
174174
.filter(d -> d.getName().equals(field.getName()))
175175
.map(PropertyDescriptor::getReadMethod)
176176
.filter(Objects::nonNull)
177-
.map(method -> new MethodParameter(method, -1))
177+
.map(method -> new MethodParameter(method, -1).withContainingClass(paramClass))
178178
.map(param -> new DelegatingMethodParameter(param, fieldNamePrefix + field.getName(), finalFieldAnnotations, true, isNotRequired));
179179
}
180180
catch (IntrospectionException e) {
@@ -246,4 +246,4 @@ static void removeSimpleTypes(Class<?>... classes) {
246246
SIMPLE_TYPES.removeAll(Arrays.asList(classes));
247247
}
248248

249-
}
249+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package test.org.springdoc.api.app181;
2+
3+
import io.swagger.v3.oas.annotations.Parameter;
4+
import io.swagger.v3.oas.annotations.media.Schema;
5+
6+
public class AbstractParameterObject<T> {
7+
8+
int primitiveBaseField;
9+
10+
T genericField;
11+
12+
public int getPrimitiveBaseField() {
13+
return primitiveBaseField;
14+
}
15+
16+
public void setPrimitiveBaseField(int primitiveBaseField) {
17+
this.primitiveBaseField = primitiveBaseField;
18+
}
19+
20+
public T getGenericField() {
21+
return genericField;
22+
}
23+
24+
public void setGenericField(T genericField) {
25+
this.genericField = genericField;
26+
}
27+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package test.org.springdoc.api.app181;
2+
3+
public class ConcreteParameterObject extends AbstractParameterObject<String> {
4+
5+
int primitiveConcreteField;
6+
7+
public int getPrimitiveConcreteField() {
8+
return primitiveConcreteField;
9+
}
10+
11+
public void setPrimitiveConcreteField(int primitiveConcreteField) {
12+
this.primitiveConcreteField = primitiveConcreteField;
13+
}
14+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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.app181;
20+
21+
import org.springdoc.api.annotations.ParameterObject;
22+
23+
import org.springframework.http.HttpStatus;
24+
import org.springframework.http.ResponseEntity;
25+
import org.springframework.web.bind.annotation.GetMapping;
26+
import org.springframework.web.bind.annotation.RestController;
27+
28+
@RestController
29+
public class HelloController {
30+
31+
@GetMapping( "/test1")
32+
public ResponseEntity<String> sayHello( @ParameterObject final ConcreteParameterObject test) {
33+
System.out.println("Field B = " + test);
34+
return new ResponseEntity<String>("{\"Say\": \"Hello\"}", HttpStatus.OK);
35+
}
36+
37+
38+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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.app181;
20+
21+
22+
import test.org.springdoc.api.AbstractSpringDocTest;
23+
24+
import org.springframework.boot.autoconfigure.SpringBootApplication;
25+
26+
/**
27+
* Tests Spring meta-annotations as method parameters
28+
*/
29+
public class SpringDocApp181Test extends AbstractSpringDocTest {
30+
31+
@SpringBootApplication
32+
static class SpringDocTestApp {}
33+
34+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
"/test1": {
15+
"get": {
16+
"tags": [
17+
"hello-controller"
18+
],
19+
"operationId": "sayHello",
20+
"parameters": [
21+
{
22+
"name": "primitiveConcreteField",
23+
"in": "query",
24+
"required": false,
25+
"schema": {
26+
"type": "integer",
27+
"format": "int32"
28+
}
29+
},
30+
{
31+
"name": "primitiveBaseField",
32+
"in": "query",
33+
"required": false,
34+
"schema": {
35+
"type": "integer",
36+
"format": "int32"
37+
}
38+
},
39+
{
40+
"name": "genericField",
41+
"in": "query",
42+
"required": false,
43+
"schema": {
44+
"type": "string"
45+
}
46+
}
47+
],
48+
"responses": {
49+
"200": {
50+
"description": "OK",
51+
"content": {
52+
"*/*": {
53+
"schema": {
54+
"type": "string"
55+
}
56+
}
57+
}
58+
}
59+
}
60+
}
61+
}
62+
},
63+
"components": {}
64+
}

0 commit comments

Comments
 (0)