Skip to content

Commit a7bd107

Browse files
committed
Changes report: #1771
1 parent 0463681 commit a7bd107

File tree

10 files changed

+361
-21
lines changed

10 files changed

+361
-21
lines changed

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

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -131,34 +131,37 @@ private static Stream<MethodParameter> extractFrom(Class<?> clazz, String fieldN
131131
* @return the stream
132132
*/
133133
private static Stream<MethodParameter> fromGetterOfField(Class<?> paramClass, Field field, String fieldNamePrefix) {
134-
if (isSimpleType(field.getType()))
134+
Class<?> type = extractType(paramClass, field);
135+
136+
if (Objects.isNull(type))
137+
return Stream.empty();
138+
139+
if (isSimpleType(type))
135140
return fromSimpleClass(paramClass, field, fieldNamePrefix);
136-
else if (field.getGenericType() instanceof TypeVariable<?>)
137-
return extractTypeParameter(paramClass, (TypeVariable<?>) field.getGenericType(), field, fieldNamePrefix);
138-
else
139-
return extractFrom(field.getType(), fieldNamePrefix + field.getName() + DOT);
141+
else {
142+
String prefix = fieldNamePrefix + field.getName() + DOT;
143+
return extractFrom(type, prefix);
144+
}
140145
}
141146

142147
/**
143-
* Extract type parameter stream.
144-
*
145-
* @param owningClass the owning class
146-
* @param genericType the generic type
147-
* @param field the field
148-
* @param fieldNamePrefix the field name prefix
149-
* @return the stream
148+
* Extract the type
149+
* @param paramClass
150+
* @param field
151+
* @return The revoled type or null if it was not a reifiable type
150152
*/
151-
private static Stream<MethodParameter> extractTypeParameter(
152-
Class<?> owningClass,
153-
TypeVariable<?> genericType,
154-
Field field,
155-
String fieldNamePrefix) {
153+
private static Class<?> extractType(Class<?> paramClass, Field field) {
154+
Class<?> type = field.getType();
155+
if (field.getGenericType() instanceof TypeVariable<?>) {
156+
Type fieldType = ReturnTypeParser.resolveType(field.getGenericType(), paramClass);
156157

157-
Type resolvedType = ReturnTypeParser.resolveType(genericType, owningClass);
158-
if (resolvedType instanceof Class<?> && isSimpleType((Class<?>) resolvedType)) {
159-
return fromSimpleClass(owningClass, field, fieldNamePrefix);
158+
if (fieldType instanceof Class<?>)
159+
type = (Class<?>) fieldType;
160+
else // This is the case for not reifiable types
161+
type = null;
160162
}
161-
return Stream.empty();
163+
164+
return type;
162165
}
163166

164167
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package test.org.springdoc.api.v30.app190;
2+
3+
public class ConcreteSubclassFromGeneric extends SimpleGeneric<MyData> {
4+
private String topName;
5+
6+
public String getTopName() {
7+
return topName;
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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.app190;
24+
25+
26+
27+
import org.springdoc.core.annotations.ParameterObject;
28+
29+
import org.springframework.http.HttpStatus;
30+
import org.springframework.http.ResponseEntity;
31+
import org.springframework.web.bind.annotation.GetMapping;
32+
import org.springframework.web.bind.annotation.RestController;
33+
34+
@RestController
35+
public class HelloController {
36+
@GetMapping("/nested")
37+
public ResponseEntity<String> nested(@ParameterObject final SimpleOuterClass filter) {
38+
return new ResponseEntity<>("{\"Say\": \"Hello\"}", HttpStatus.OK);
39+
}
40+
41+
@GetMapping( "/nestedTypeErasureGeneric")
42+
public ResponseEntity<String> nestedTypeErasureGeneric( @ParameterObject final SimpleGeneric<MyData> filter) {
43+
return new ResponseEntity<>("{\"Say\": \"Hello\"}", HttpStatus.OK);
44+
}
45+
46+
@GetMapping( "/nestedReifiableGeneric")
47+
public ResponseEntity<String> nestedReifiableGeneric( @ParameterObject final ConcreteSubclassFromGeneric filter) {
48+
return new ResponseEntity<>("{\"Say\": \"Hello\"}", HttpStatus.OK);
49+
}
50+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package test.org.springdoc.api.v30.app190;
2+
3+
public class MyData {
4+
private String firstName;
5+
private Integer maxNumber;
6+
7+
public Integer getMaxNumber() {
8+
return maxNumber;
9+
}
10+
11+
public String getFirstName() {
12+
return firstName;
13+
}
14+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package test.org.springdoc.api.v30.app190;
2+
3+
public class SimpleGeneric<T> {
4+
5+
private String name;
6+
private T child;
7+
8+
public T getChild() {
9+
return child;
10+
}
11+
12+
public String getName() {
13+
return name;
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package test.org.springdoc.api.v30.app190;
2+
3+
public class SimpleInnerClass {
4+
5+
private SimpleInnerInnerClass innerInnerClass;
6+
7+
private Boolean name;
8+
private Integer maxNumber;
9+
10+
public Integer getMaxNumber() {
11+
return maxNumber;
12+
}
13+
14+
public Boolean getName() {
15+
return name;
16+
}
17+
18+
public SimpleInnerInnerClass getInnerInnerClass() {
19+
return innerInnerClass;
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package test.org.springdoc.api.v30.app190;
2+
3+
public class SimpleInnerInnerClass {
4+
5+
Boolean name;
6+
private Integer maxNumber;
7+
8+
public Integer getMaxNumber() {
9+
return maxNumber;
10+
}
11+
12+
public Boolean getName() {
13+
return name;
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package test.org.springdoc.api.v30.app190;
2+
3+
public class SimpleOuterClass {
4+
private String name;
5+
private SimpleInnerClass innerClass;
6+
7+
public String getName() {
8+
return name;
9+
}
10+
11+
public SimpleInnerClass getInnerClass() {
12+
return innerClass;
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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.app190;
24+
25+
import test.org.springdoc.api.v30.AbstractSpringDocV30Test;
26+
27+
import org.springframework.boot.autoconfigure.SpringBootApplication;
28+
29+
public class SpringDocApp190Test extends AbstractSpringDocV30Test {
30+
31+
@SpringBootApplication
32+
static class SpringDocTestApp {}
33+
34+
}

0 commit comments

Comments
 (0)