Skip to content

Commit f485ba7

Browse files
fix: pass along type_use annotations to swagger(-core)
1 parent 209d7b5 commit f485ba7

6 files changed

Lines changed: 234 additions & 1 deletion

File tree

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ private TypeAndTypeAnnotations resolveTypeAndTypeAnnotationsForParameter(MethodP
439439
&& delegatingMethodParameter.getField() != null) {
440440
AnnotatedType annotated = delegatingMethodParameter.getField().getAnnotatedType();
441441
Type type = GenericTypeResolver.resolveType(annotated.getType(), methodParameter.getContainingClass());
442-
return new TypeAndTypeAnnotations(type, annotationsFromAnnotatedTypeArguments(annotated));
442+
return new TypeAndTypeAnnotations(type, annotationsFromAnnotatedType(annotated));
443443
}
444444

445445
Type type = GenericTypeResolver.resolveType(methodParameter.getGenericParameterType(), methodParameter.getContainingClass());
@@ -462,6 +462,20 @@ private TypeAndTypeAnnotations resolveTypeAndTypeAnnotationsForParameter(MethodP
462462
private record TypeAndTypeAnnotations(Type type, Annotation[] typeAnnotations) {
463463
}
464464

465+
/**
466+
* Collects annotations declared on the type itself and on each type argument of an
467+
* {@link AnnotatedParameterizedType}.
468+
*
469+
* @param annotatedType the annotated type
470+
* @return a new array, possibly empty
471+
*/
472+
private static Annotation[] annotationsFromAnnotatedType(AnnotatedType annotatedType) {
473+
return Stream.concat(
474+
Arrays.stream(annotatedType.getAnnotations()),
475+
Arrays.stream(annotationsFromAnnotatedTypeArguments(annotatedType)))
476+
.toArray(Annotation[]::new);
477+
}
478+
465479
/**
466480
* Collects annotations declared on each type argument of an {@link AnnotatedParameterizedType}.
467481
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
*
3+
* *
4+
* * *
5+
* * * *
6+
* * * * *
7+
* * * * * * Copyright 2019-2026 the original author or authors.
8+
* * * * * *
9+
* * * * * * Licensed under the Apache License, Version 2.0 (the "License");
10+
* * * * * * you may not use this file except in compliance with the License.
11+
* * * * * * You may obtain a copy of the License at
12+
* * * * *
13+
* * * * * * https://www.apache.org/licenses/LICENSE-2.0
14+
* * * * * *
15+
* * * * * * Unless required by applicable law or agreed to in writing, software
16+
* * * * * * distributed under the License is distributed on an "AS IS" BASIS,
17+
* * * * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* * * * * * See the License for the specific language governing permissions and
19+
* * * * * * limitations under the License.
20+
* * * * *
21+
* * * *
22+
* * *
23+
* *
24+
*
25+
*/
26+
27+
package test.org.springdoc.api.v31.app175;
28+
29+
import org.springdoc.core.annotations.ParameterObject;
30+
31+
import org.springframework.web.bind.annotation.GetMapping;
32+
import org.springframework.web.bind.annotation.RestController;
33+
34+
@RestController
35+
class HelloController {
36+
37+
@GetMapping("/vets")
38+
public void find(@ParameterObject SearchCriteria searchCriteria) {
39+
}
40+
41+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
*
3+
* *
4+
* * *
5+
* * * *
6+
* * * * *
7+
* * * * * * Copyright 2019-2026 the original author or authors.
8+
* * * * * *
9+
* * * * * * Licensed under the Apache License, Version 2.0 (the "License");
10+
* * * * * * you may not use this file except in compliance with the License.
11+
* * * * * * You may obtain a copy of the License at
12+
* * * * * *
13+
* * * * * * https://www.apache.org/licenses/LICENSE-2.0
14+
* * * * * *
15+
* * * * * * Unless required by applicable law or agreed to in writing, software
16+
* * * * * * distributed under the License is distributed on an "AS IS" BASIS,
17+
* * * * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* * * * * * See the License for the specific language governing permissions and
19+
* * * * * * limitations under the License.
20+
* * * * *
21+
* * * *
22+
* * *
23+
* *
24+
*
25+
*/
26+
27+
package test.org.springdoc.api.v31.app175;
28+
29+
import java.lang.annotation.ElementType;
30+
import java.lang.annotation.Retention;
31+
import java.lang.annotation.RetentionPolicy;
32+
import java.lang.annotation.Target;
33+
34+
@Target(ElementType.TYPE_USE)
35+
@Retention(RetentionPolicy.RUNTIME)
36+
@interface Nullable {
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
*
3+
* *
4+
* * *
5+
* * * *
6+
* * * * *
7+
* * * * * * Copyright 2019-2026 the original author or authors.
8+
* * * * * *
9+
* * * * * * Licensed under the Apache License, Version 2.0 (the "License");
10+
* * * * * * you may not use this file except in compliance with the License.
11+
* * * * * * You may obtain a copy of the License at
12+
* * * * * *
13+
* * * * * * https://www.apache.org/licenses/LICENSE-2.0
14+
* * * * * *
15+
* * * * * * Unless required by applicable law or agreed to in writing, software
16+
* * * * * * distributed under the License is distributed on an "AS IS" BASIS,
17+
* * * * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* * * * * * See the License for the specific language governing permissions and
19+
* * * * * * limitations under the License.
20+
* * * * *
21+
* * * *
22+
* * *
23+
* *
24+
*
25+
*/
26+
27+
package test.org.springdoc.api.v31.app175;
28+
29+
import io.swagger.v3.oas.annotations.Parameter;
30+
31+
class SearchCriteria {
32+
33+
@Parameter(description = "Statuses to filter by.")
34+
private Status @Nullable [] status;
35+
36+
public Status[] getStatus() {
37+
return status;
38+
}
39+
40+
public void setStatus(Status[] status) {
41+
this.status = status;
42+
}
43+
44+
enum Status {
45+
46+
ACTIVE,
47+
48+
INACTIVE
49+
50+
}
51+
52+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
*
3+
* *
4+
* * *
5+
* * * *
6+
* * * * *
7+
* * * * * * Copyright 2019-2026 the original author or authors.
8+
* * * * * *
9+
* * * * * * Licensed under the Apache License, Version 2.0 (the "License");
10+
* * * * * * you may not use this file except in compliance with the License.
11+
* * * * * * You may obtain a copy of the License at
12+
* * * * *
13+
* * * * * * https://www.apache.org/licenses/LICENSE-2.0
14+
* * * * * *
15+
* * * * * * Unless required by applicable law or agreed to in writing, software
16+
* * * * * * distributed under the License is distributed on an "AS IS" BASIS,
17+
* * * * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* * * * * * See the License for the specific language governing permissions and
19+
* * * * * * limitations under the License.
20+
* * * * *
21+
* * * *
22+
* * *
23+
* *
24+
*
25+
*/
26+
27+
package test.org.springdoc.api.v31.app175;
28+
29+
import test.org.springdoc.api.v31.AbstractSpringDocTest;
30+
31+
import org.springframework.boot.autoconfigure.SpringBootApplication;
32+
33+
class SpringDocApp175Test extends AbstractSpringDocTest {
34+
35+
@SpringBootApplication
36+
static class SpringDocTestApp {
37+
}
38+
39+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"openapi": "3.1.0",
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+
"/vets": {
15+
"get": {
16+
"tags": [
17+
"hello-controller"
18+
],
19+
"operationId": "find",
20+
"parameters": [
21+
{
22+
"name": "status",
23+
"in": "query",
24+
"description": "Statuses to filter by.",
25+
"required": false,
26+
"schema": {
27+
"type": [
28+
"array",
29+
"null"
30+
],
31+
"items": {
32+
"type": "string",
33+
"enum": [
34+
"ACTIVE",
35+
"INACTIVE"
36+
]
37+
}
38+
}
39+
}
40+
],
41+
"responses": {
42+
"200": {
43+
"description": "OK"
44+
}
45+
}
46+
}
47+
}
48+
},
49+
"components": {}
50+
}

0 commit comments

Comments
 (0)