Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,10 @@ public boolean isParameterObject() {
}

/**
* Gets field. If Is parameter object. then The Field should be not null
* Gets field. If it is a parameter object, then The {@code Field} should be not null.
* see {@link DelegatingMethodParameter#isParameterObject()}
*
* @return the field
* @see #isParameterObject #isParameterObject#isParameterObject
*/
@Nullable
public Field getField() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -710,17 +710,16 @@ public void applyBeanValidatorAnnotations(final MethodParameter methodParameter,
parameter.setSchema(schema);
}
SchemaUtils.applyValidationsToSchema(schema, annotations, openapiVersion);
if (schema instanceof ArraySchema && methodParameter instanceof DelegatingMethodParameter mp) {
if (schema instanceof ArraySchema && methodParameter instanceof DelegatingMethodParameter delegatingMethodParameter) {
java.lang.reflect.AnnotatedType annotatedType = null;
if (isParameterObject) {
Field field = mp.getField();
Field field = delegatingMethodParameter.getField();
if (field != null) {
annotatedType = field.getAnnotatedType();
}
}
else {
java.lang.reflect.Parameter param = mp.getParameter();
annotatedType = param.getAnnotatedType();
annotatedType = delegatingMethodParameter.getParameter().getAnnotatedType();
}
if (annotatedType instanceof AnnotatedParameterizedType paramType) {
java.lang.reflect.AnnotatedType[] typeArgs = paramType.getAnnotatedActualTypeArguments();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ Schema calculateSchema(Components components, ParameterInfo parameterInfo, Reque
*/
private TypeAndTypeAnnotations resolveTypeAndTypeAnnotationsForParameter(MethodParameter methodParameter) {
if (methodParameter instanceof DelegatingMethodParameter delegatingMethodParameter
&& delegatingMethodParameter.getField() != null) {
&& delegatingMethodParameter.getField() != null) {
AnnotatedType annotated = delegatingMethodParameter.getField().getAnnotatedType();
Type type = GenericTypeResolver.resolveType(annotated.getType(), methodParameter.getContainingClass());
return new TypeAndTypeAnnotations(type, Arrays.asList(annotationsFromAnnotatedTypeArguments(annotated)));
Expand All @@ -448,7 +448,11 @@ private TypeAndTypeAnnotations resolveTypeAndTypeAnnotationsForParameter(MethodP
: new TypeAndTypeAnnotations(type, new ArrayList<>());
}

return new TypeAndTypeAnnotations(type, Arrays.asList(methodParameter.getParameterType().getAnnotations()));
AnnotatedType annotated = methodParameter.getParameter().getAnnotatedType();
List<Annotation> parameterAnnotations = Stream.concat(
Arrays.stream(annotationsFromAnnotatedTypeArguments(annotated)),
Arrays.stream(methodParameter.getParameterType().getAnnotations())).toList();
return new TypeAndTypeAnnotations(type, parameterAnnotations);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,26 @@

package test.org.springdoc.api.v30.app267;

import jakarta.validation.constraints.Pattern;
import org.springdoc.core.annotations.ParameterObject;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class HelloController {

@GetMapping("/items")
public String list(@ParameterObject PersonQueryFilter criteria) {
return "ok";
}
@GetMapping("/items")
public String list(@ParameterObject PersonQueryFilter criteria) {
return "ok";
}

@GetMapping("/persons")
public String persons(
List<@Pattern(regexp = "^[a-zA-Z]$") String> middleNames,
List<@Pattern(regexp = "^\\d+$") String> phoneNumbers) {
return "ok";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,26 @@

package test.org.springdoc.api.v31.app267;

import jakarta.validation.constraints.Pattern;
import org.springdoc.core.annotations.ParameterObject;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class HelloController {

@GetMapping("/items")
public String list(@ParameterObject PersonQueryFilter criteria) {
return "ok";
}
@GetMapping("/items")
public String list(@ParameterObject PersonQueryFilter criteria) {
return "ok";
}

@GetMapping("/persons")
public String persons(
List<@Pattern(regexp = "^[a-zA-Z]$") String> middleNames,
List<@Pattern(regexp = "^\\d+$") String> phoneNumbers) {
return "ok";
}
}
Original file line number Diff line number Diff line change
@@ -1,65 +1,98 @@
{
"openapi": "3.0.1",
"info": {
"title": "OpenAPI definition",
"version": "v0"
"openapi" : "3.0.1",
"info" : {
"title" : "OpenAPI definition",
"version" : "v0"
},
"servers": [
{
"url": "http://localhost",
"description": "Generated server url"
}
],
"paths": {
"/items": {
"get": {
"tags": [
"hello-controller"
],
"operationId": "list",
"parameters": [
{
"name": "firstNames",
"in": "query",
"required": false,
"schema": {
"type": "array",
"items": {
"type": "string"
}
"servers" : [ {
"url" : "http://localhost",
"description" : "Generated server url"
} ],
"paths" : {
"/persons" : {
"get" : {
"tags" : [ "hello-controller" ],
"operationId" : "persons",
"parameters" : [ {
"name" : "middleNames",
"in" : "query",
"required" : true,
"schema" : {
"type" : "array",
"items" : {
"pattern" : "^[a-zA-Z]$",
"type" : "string"
}
},
{
"name": "middleNames",
"in": "query",
"required": false,
"schema": {
"type": "array",
"items": {
"type": "string"
}
}
}, {
"name" : "phoneNumbers",
"in" : "query",
"required" : true,
"schema" : {
"type" : "array",
"items" : {
"pattern" : "^\\d+$",
"type" : "string"
}
},
{
"name": "phoneNumbers",
"in": "query",
"required": false,
"schema": {
"type": "array",
"items": {
"pattern": "^\\d+$",
"type": "string"
}
} ],
"responses" : {
"200" : {
"description" : "OK",
"content" : {
"*/*" : {
"schema" : {
"type" : "string"
}
}
}
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"*/*": {
"schema": {
"type": "string"
}
}
},
"/items" : {
"get" : {
"tags" : [ "hello-controller" ],
"operationId" : "list",
"parameters" : [ {
"name" : "firstNames",
"in" : "query",
"required" : false,
"schema" : {
"type" : "array",
"items" : {
"type" : "string"
}
}
}, {
"name" : "middleNames",
"in" : "query",
"required" : false,
"schema" : {
"type" : "array",
"items" : {
"type" : "string"
}
}
}, {
"name" : "phoneNumbers",
"in" : "query",
"required" : false,
"schema" : {
"type" : "array",
"items" : {
"pattern" : "^\\d+$",
"type" : "string"
}
}
} ],
"responses" : {
"200" : {
"description" : "OK",
"content" : {
"*/*" : {
"schema" : {
"type" : "string"
}
}
}
Expand All @@ -68,5 +101,5 @@
}
}
},
"components": {}
}
"components" : { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,47 @@
"description" : "Generated server url"
} ],
"paths" : {
"/persons" : {
"get" : {
"tags" : [ "hello-controller" ],
"operationId" : "persons",
"parameters" : [ {
"name" : "middleNames",
"in" : "query",
"required" : true,
"schema" : {
"type" : "array",
"items" : {
"type" : "string",
"pattern" : "^[a-zA-Z]$"
}
}
}, {
"name" : "phoneNumbers",
"in" : "query",
"required" : true,
"schema" : {
"type" : "array",
"items" : {
"type" : "string",
"pattern" : "^\\d+$"
}
}
} ],
"responses" : {
"200" : {
"description" : "OK",
"content" : {
"*/*" : {
"schema" : {
"type" : "string"
}
}
}
}
}
}
},
"/items" : {
"get" : {
"tags" : [ "hello-controller" ],
Expand Down Expand Up @@ -61,4 +102,4 @@
}
},
"components" : { }
}
}
Loading