Skip to content

Commit a23005b

Browse files
committed
Merge branch 'mymx2-feat/type-use'
2 parents 9f05020 + 290162f commit a23005b

File tree

3 files changed

+141
-3
lines changed

3 files changed

+141
-3
lines changed

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -618,9 +618,18 @@ public void applyBeanValidatorAnnotations(final MethodParameter methodParameter,
618618
if (annotations != null) {
619619
Schema<?> schema = parameter.getSchema();
620620
SchemaUtils.applyValidationsToSchema(schema, annotations, openapiVersion);
621-
if (schema instanceof ArraySchema && isParameterObject && methodParameter instanceof DelegatingMethodParameter mp) {
622-
Field field = mp.getField();
623-
if (field != null && field.getAnnotatedType() instanceof AnnotatedParameterizedType paramType) {
621+
if (schema instanceof ArraySchema && methodParameter instanceof DelegatingMethodParameter mp) {
622+
java.lang.reflect.AnnotatedType annotatedType = null;
623+
if (isParameterObject) {
624+
Field field = mp.getField();
625+
if (field != null) {
626+
annotatedType = field.getAnnotatedType();
627+
}
628+
} else {
629+
java.lang.reflect.Parameter param = mp.getParameter();
630+
annotatedType = param.getAnnotatedType();
631+
}
632+
if (annotatedType instanceof AnnotatedParameterizedType paramType) {
624633
java.lang.reflect.AnnotatedType[] typeArgs = paramType.getAnnotatedActualTypeArguments();
625634
for (java.lang.reflect.AnnotatedType typeArg : typeArgs) {
626635
List<Annotation> genericAnnotations = Arrays.stream(typeArg.getAnnotations()).toList();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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.v31.app19
20+
21+
import io.swagger.v3.oas.annotations.Parameter
22+
import jakarta.validation.constraints.Max
23+
import jakarta.validation.constraints.Min
24+
import jakarta.validation.constraints.Size
25+
import org.springframework.boot.autoconfigure.SpringBootApplication
26+
import org.springframework.http.ResponseEntity
27+
import org.springframework.web.bind.annotation.PostMapping
28+
import org.springframework.web.bind.annotation.RequestMapping
29+
import org.springframework.web.bind.annotation.RequestParam
30+
import org.springframework.web.bind.annotation.RestController
31+
import test.org.springdoc.api.v31.AbstractKotlinSpringDocMVCTest
32+
33+
34+
class SpringDocApp19Test : AbstractKotlinSpringDocMVCTest() {
35+
@SpringBootApplication
36+
class DemoApplication
37+
}
38+
39+
@RestController
40+
@RequestMapping
41+
class HelloController {
42+
43+
@PostMapping("euroMillions")
44+
fun euroMillions(
45+
@Parameter(description = "the numbers")
46+
@RequestParam
47+
@Size(min = 5, max = 5)
48+
numbers: List<@Max(50) @Min(1) Int>,
49+
50+
@Parameter(description = "the stars")
51+
@RequestParam
52+
@Size(min = 2, max = 2)
53+
stars: List<@Max(12) @Min(1) Int>
54+
): ResponseEntity<String> {
55+
return ResponseEntity.ok("ok")
56+
}
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
"/euroMillions": {
15+
"post": {
16+
"tags": [
17+
"hello-controller"
18+
],
19+
"operationId": "euroMillions",
20+
"parameters": [
21+
{
22+
"name": "numbers",
23+
"in": "query",
24+
"description": "the numbers",
25+
"required": true,
26+
"schema": {
27+
"type": "array",
28+
"items": {
29+
"type": "integer",
30+
"format": "int32",
31+
"maximum": 50,
32+
"minimum": 1
33+
},
34+
"maxItems": 5,
35+
"minItems": 5
36+
}
37+
},
38+
{
39+
"name": "stars",
40+
"in": "query",
41+
"description": "the stars",
42+
"required": true,
43+
"schema": {
44+
"type": "array",
45+
"items": {
46+
"type": "integer",
47+
"format": "int32",
48+
"maximum": 12,
49+
"minimum": 1
50+
},
51+
"maxItems": 2,
52+
"minItems": 2
53+
}
54+
}
55+
],
56+
"responses": {
57+
"200": {
58+
"description": "OK",
59+
"content": {
60+
"*/*": {
61+
"schema": {
62+
"type": "string"
63+
}
64+
}
65+
}
66+
}
67+
}
68+
}
69+
}
70+
},
71+
"components": {}
72+
}

0 commit comments

Comments
 (0)