Skip to content
Merged
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 @@ -28,6 +28,8 @@

import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedParameterizedType;
import java.lang.reflect.AnnotatedType;
import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
Expand Down Expand Up @@ -385,22 +387,10 @@ Schema calculateSchema(Components components, ParameterInfo parameterInfo, Reque
MethodParameter methodParameter = parameterInfo.getMethodParameter();

if (parameterInfo.getParameterModel() == null || parameterInfo.getParameterModel().getSchema() == null) {
Type type = GenericTypeResolver.resolveType(methodParameter.getGenericParameterType(), methodParameter.getContainingClass());
Annotation[] paramAnnotations = getParameterAnnotations(methodParameter);
Annotation[] typeAnnotations = new Annotation[0];
if (KotlinDetector.isKotlinPresent()
&& KotlinDetector.isKotlinReflectPresent()
&& KotlinDetector.isKotlinType(methodParameter.getContainingClass())
&& type == String.class) {
Class<?> restored = KotlinInlineParameterResolver
.resolveInlineType(methodParameter, type);
if (restored != null) {
type = restored;
typeAnnotations = ((Class<?>) type).getAnnotations();
}
} else {
typeAnnotations = methodParameter.getParameterType().getAnnotations();
}
TypeAndTypeAnnotations resolved = resolveTypeAndTypeAnnotationsForParameter(methodParameter);
Type type = resolved.type();
Annotation[] typeAnnotations = resolved.typeAnnotations();
Annotation[] mergedAnnotations =
Stream.concat(
Arrays.stream(paramAnnotations),
Expand Down Expand Up @@ -437,6 +427,56 @@ Schema calculateSchema(Components components, ParameterInfo parameterInfo, Reque
return schemaN;
}

/**
* Resolves type and type annotations for schema extraction (flattened {@code @ParameterObject} field,
* Kotlin inline {@code String}, or default).
*
* @param methodParameter the method parameter
* @return the resolved type and type annotations
*/
private TypeAndTypeAnnotations resolveTypeAndTypeAnnotationsForParameter(MethodParameter methodParameter) {
if (methodParameter instanceof DelegatingMethodParameter delegatingMethodParameter
&& delegatingMethodParameter.getField() != null) {
AnnotatedType annotated = delegatingMethodParameter.getField().getAnnotatedType();
Type type = GenericTypeResolver.resolveType(annotated.getType(), methodParameter.getContainingClass());
return new TypeAndTypeAnnotations(type, annotationsFromAnnotatedTypeArguments(annotated));
}

Type type = GenericTypeResolver.resolveType(methodParameter.getGenericParameterType(), methodParameter.getContainingClass());
if (KotlinDetector.isKotlinPresent()
&& KotlinDetector.isKotlinReflectPresent()
&& KotlinDetector.isKotlinType(methodParameter.getContainingClass())
&& type == String.class) {
Class<?> restored = KotlinInlineParameterResolver.resolveInlineType(methodParameter, type);
return restored != null
? new TypeAndTypeAnnotations(restored, restored.getAnnotations())
: new TypeAndTypeAnnotations(type, new Annotation[0]);
}

return new TypeAndTypeAnnotations(type, methodParameter.getParameterType().getAnnotations());
}

/**
* Pair of resolved Java type and type annotations merged with parameter annotations for {@code extractSchema}.
*/
private record TypeAndTypeAnnotations(Type type, Annotation[] typeAnnotations) {
}

/**
* Collects annotations declared on each type argument of an {@link AnnotatedParameterizedType}.
*
* @param annotatedType the annotated type
* @return a new array, possibly empty
*/
private static Annotation[] annotationsFromAnnotatedTypeArguments(AnnotatedType annotatedType) {
if (!(annotatedType instanceof AnnotatedParameterizedType apt)) {
return new Annotation[0];
}
return Arrays.stream(apt.getAnnotatedActualTypeArguments())
.flatMap(typeArg -> Arrays.stream(typeArg.getAnnotations()))
.toArray(Annotation[]::new);
}

/**
* Calculate request body schema schema.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2019-2026 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

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

import org.springdoc.core.annotations.ParameterObject;

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

@RestController
public class HelloController {

@GetMapping("/items")
public String list(@ParameterObject PersonQueryFilter criteria) {
return "ok";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2019-2026 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

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

import java.util.List;

import jakarta.validation.constraints.Pattern;

/**
* Sample person search criteria: several {@code List} query parameters; only one uses a type-use
* {@link Pattern} on the element type.
*/
public record PersonQueryFilter(
List<String> firstNames,
List<String> middleNames,
List<@Pattern(regexp = "^\\d+$") String> phoneNumbers) {

public PersonQueryFilter {
firstNames = firstNames != null ? firstNames : List.of();
middleNames = middleNames != null ? middleNames : List.of();
phoneNumbers = phoneNumbers != null ? phoneNumbers : List.of();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2019-2026 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

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

import test.org.springdoc.api.v30.AbstractSpringDocV30Test;

import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
* Regression: {@code @Pattern} on one {@code List} field in a {@code @ParameterObject} must not
* be applied to sibling {@code List} query parameters' item schemas.
*/
public class SpringDocApp249Test extends AbstractSpringDocV30Test {

@SpringBootApplication
static class SpringDocTestApp {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2019-2026 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

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

import org.springdoc.core.annotations.ParameterObject;

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

@RestController
public class HelloController {

@GetMapping("/items")
public String list(@ParameterObject PersonQueryFilter criteria) {
return "ok";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2019-2026 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

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

import java.util.List;

import jakarta.validation.constraints.Pattern;

/**
* Sample person search criteria: several {@code List} query parameters; only one uses a type-use
* {@link Pattern} on the element type.
*/
public record PersonQueryFilter(
List<String> firstNames,
List<String> middleNames,
List<@Pattern(regexp = "^\\d+$") String> phoneNumbers) {

public PersonQueryFilter {
firstNames = firstNames != null ? firstNames : List.of();
middleNames = middleNames != null ? middleNames : List.of();
phoneNumbers = phoneNumbers != null ? phoneNumbers : List.of();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2019-2026 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

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

import test.org.springdoc.api.v31.AbstractSpringDocTest;

import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
* Regression: {@code @Pattern} on one {@code List} field in a {@code @ParameterObject} must not
* be applied to sibling {@code List} query parameters' item schemas.
*/
public class SpringDocApp249Test extends AbstractSpringDocTest {

@SpringBootApplication
static class SpringDocTestApp {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"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"
}
}
},
{
"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"
}
}
}
}
}
}
}
},
"components": {}
}
Loading