Skip to content

Commit 2c2e200

Browse files
fix: add so that the type annotation is considered again if kotlin is not present
1 parent 4bf6501 commit 2c2e200

9 files changed

Lines changed: 459 additions & 1 deletion

File tree

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,8 @@ Schema calculateSchema(Components components, ParameterInfo parameterInfo, Reque
385385
type = restored;
386386
typeAnnotations = ((Class<?>) type).getAnnotations();
387387
}
388+
} else {
389+
typeAnnotations = methodParameter.getParameterType().getAnnotations();
388390
}
389391
Annotation[] mergedAnnotations =
390392
Stream.concat(
@@ -394,7 +396,7 @@ Schema calculateSchema(Components components, ParameterInfo parameterInfo, Reque
394396
if (type instanceof Class && !((Class<?>) type).isEnum() && optionalWebConversionServiceProvider.isPresent()) {
395397
WebConversionServiceProvider webConversionServiceProvider = optionalWebConversionServiceProvider.get();
396398
if (!MethodParameterPojoExtractor.isSwaggerPrimitiveType((Class) type) && Arrays.stream(mergedAnnotations)
397-
.noneMatch(a -> a.annotationType() == io.swagger.v3.oas.annotations.media.Schema.class)) {
399+
.noneMatch(a -> a.annotationType() == io.swagger.v3.oas.annotations.media.Schema.class)) {
398400
Class<?> springConvertedType = webConversionServiceProvider.getSpringConvertedType(methodParameter.getParameterType());
399401
if (!(String.class.equals(springConvertedType) && ((Class<?>) type).isEnum()) && requestBodyInfo == null)
400402
type = springConvertedType;
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
*
3+
* *
4+
* * *
5+
* * * *
6+
* * * * *
7+
* * * * * * Copyright 2019-2025 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.v30.app248;
28+
29+
import io.swagger.v3.oas.annotations.media.Schema;
30+
import org.springframework.web.bind.annotation.GetMapping;
31+
import org.springframework.web.bind.annotation.PathVariable;
32+
import org.springframework.web.bind.annotation.RestController;
33+
34+
import java.util.UUID;
35+
36+
@RestController
37+
public class HelloController {
38+
39+
@GetMapping(value = "/class-works/{regularSchema}")
40+
public RegularSchema dataClass1(@PathVariable RegularSchema regularSchema) {
41+
return null;
42+
}
43+
44+
@GetMapping(value = "/class-works2/{pathSchema}")
45+
public String dataClass2(@PathVariable PathSchema pathSchema) {
46+
return null;
47+
}
48+
49+
@GetMapping(value = "/class-works3/{itemId}")
50+
public String dataClass3(@PathVariable ItemId itemId) {
51+
return null;
52+
}
53+
}
54+
55+
@Schema(description = "regularSchema")
56+
record RegularSchema(String name, String value) {
57+
}
58+
59+
@Schema(description = "pathSchema", example = "123")
60+
record PathSchema(UUID value) {
61+
}
62+
63+
@Schema(
64+
type = "uuid",
65+
description = "Unique item identifier",
66+
example = "9d9d46e5-d41c-4774-885d-8e9dbc67735c")
67+
record ItemId(UUID value) {
68+
69+
public static ItemId fromString(String uuid) {
70+
return new ItemId(UUID.fromString(uuid));
71+
}
72+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package test.org.springdoc.api.v30.app248;
2+
3+
import org.springframework.core.convert.converter.Converter;
4+
import org.springframework.stereotype.Component;
5+
6+
@Component
7+
public class ItemIdConverter implements Converter<String, ItemId> {
8+
9+
@Override
10+
public ItemId convert(String source) {
11+
return ItemId.fromString(source);
12+
}
13+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
*
3+
* *
4+
* * *
5+
* * * *
6+
* * * * * Copyright 2025 the original author or authors.
7+
* * * * *
8+
* * * * * Licensed under the Apache License, Version 2.0 (the "License");
9+
* * * * * you may not use this file except in compliance with the License.
10+
* * * * * You may obtain a copy of the License at
11+
* * * * *
12+
* * * * * https://www.apache.org/licenses/LICENSE-2.0
13+
* * * * *
14+
* * * * * Unless required by applicable law or agreed to in writing, software
15+
* * * * * distributed under the License is distributed on an "AS IS" BASIS,
16+
* * * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* * * * * See the License for the specific language governing permissions and
18+
* * * * * limitations under the License.
19+
* * * *
20+
* * *
21+
* *
22+
*
23+
*/
24+
25+
package test.org.springdoc.api.v30.app248;
26+
27+
import org.springframework.boot.autoconfigure.SpringBootApplication;
28+
import test.org.springdoc.api.v30.AbstractSpringDocV30Test;
29+
30+
public class SpringDocApp248Test extends AbstractSpringDocV30Test {
31+
32+
@SpringBootApplication
33+
static class SpringDocTestApp {}
34+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
*
3+
* *
4+
* * *
5+
* * * *
6+
* * * * *
7+
* * * * * * Copyright 2019-2025 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.app248;
28+
29+
import io.swagger.v3.oas.annotations.media.Schema;
30+
import org.springframework.web.bind.annotation.GetMapping;
31+
import org.springframework.web.bind.annotation.PathVariable;
32+
import org.springframework.web.bind.annotation.RestController;
33+
34+
import java.util.UUID;
35+
36+
@RestController
37+
public class HelloController {
38+
39+
@GetMapping(value = "/class-works/{regularSchema}")
40+
public RegularSchema dataClass1(@PathVariable RegularSchema regularSchema) {
41+
return null;
42+
}
43+
44+
@GetMapping(value = "/class-works2/{pathSchema}")
45+
public String dataClass2(@PathVariable PathSchema pathSchema) {
46+
return null;
47+
}
48+
49+
@GetMapping(value = "/class-works3/{itemId}")
50+
public String dataClass3(@PathVariable ItemId itemId) {
51+
return null;
52+
}
53+
}
54+
55+
@Schema(description = "regularSchema")
56+
record RegularSchema(String name, String value) {
57+
}
58+
59+
@Schema(description = "pathSchema", example = "123")
60+
record PathSchema(UUID value) {
61+
}
62+
63+
@Schema(
64+
type = "uuid",
65+
description = "Unique item identifier",
66+
example = "9d9d46e5-d41c-4774-885d-8e9dbc67735c")
67+
record ItemId(UUID value) {
68+
69+
public static ItemId fromString(String uuid) {
70+
return new ItemId(UUID.fromString(uuid));
71+
}
72+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package test.org.springdoc.api.v31.app248;
2+
3+
import org.springframework.core.convert.converter.Converter;
4+
import org.springframework.stereotype.Component;
5+
6+
@Component
7+
public class ItemIdConverter implements Converter<String, ItemId> {
8+
9+
@Override
10+
public ItemId convert(String source) {
11+
return ItemId.fromString(source);
12+
}
13+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package test.org.springdoc.api.v31.app248;
2+
3+
import org.springframework.boot.autoconfigure.SpringBootApplication;
4+
import test.org.springdoc.api.v31.AbstractSpringDocTest;
5+
6+
public class SpringDocApp248Test extends AbstractSpringDocTest {
7+
8+
@SpringBootApplication
9+
static class SpringDocTestApp {}
10+
}
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
{
2+
"openapi" : "3.0.1",
3+
"info" : {
4+
"title" : "OpenAPI definition",
5+
"version" : "v0"
6+
},
7+
"servers" : [ {
8+
"url" : "http://localhost",
9+
"description" : "Generated server url"
10+
} ],
11+
"paths" : {
12+
"/class-works3/{itemId}" : {
13+
"get" : {
14+
"tags" : [ "hello-controller" ],
15+
"operationId" : "dataClass3",
16+
"parameters" : [ {
17+
"name" : "itemId",
18+
"in" : "path",
19+
"required" : true,
20+
"schema" : {
21+
"type" : "string",
22+
"format" : "uuid",
23+
"description" : "Unique item identifier",
24+
"example" : "9d9d46e5-d41c-4774-885d-8e9dbc67735c"
25+
}
26+
} ],
27+
"responses" : {
28+
"200" : {
29+
"description" : "OK",
30+
"content" : {
31+
"*/*" : {
32+
"schema" : {
33+
"type" : "string"
34+
}
35+
}
36+
}
37+
}
38+
}
39+
}
40+
},
41+
"/class-works2/{pathSchema}" : {
42+
"get" : {
43+
"tags" : [ "hello-controller" ],
44+
"operationId" : "dataClass2",
45+
"parameters" : [ {
46+
"name" : "pathSchema",
47+
"in" : "path",
48+
"required" : true,
49+
"schema" : {
50+
"$ref" : "#/components/schemas/PathSchema"
51+
}
52+
} ],
53+
"responses" : {
54+
"200" : {
55+
"description" : "OK",
56+
"content" : {
57+
"*/*" : {
58+
"schema" : {
59+
"type" : "string"
60+
}
61+
}
62+
}
63+
}
64+
}
65+
}
66+
},
67+
"/class-works/{regularSchema}" : {
68+
"get" : {
69+
"tags" : [ "hello-controller" ],
70+
"operationId" : "dataClass1",
71+
"parameters" : [ {
72+
"name" : "regularSchema",
73+
"in" : "path",
74+
"required" : true,
75+
"schema" : {
76+
"$ref" : "#/components/schemas/RegularSchema"
77+
}
78+
} ],
79+
"responses" : {
80+
"200" : {
81+
"description" : "OK",
82+
"content" : {
83+
"*/*" : {
84+
"schema" : {
85+
"$ref" : "#/components/schemas/RegularSchema"
86+
}
87+
}
88+
}
89+
}
90+
}
91+
}
92+
}
93+
},
94+
"components" : {
95+
"schemas" : {
96+
"PathSchema" : {
97+
"type" : "object",
98+
"description" : "pathSchema",
99+
"example" : 123,
100+
"properties" : {
101+
"value" : {
102+
"type" : "string",
103+
"format" : "uuid"
104+
}
105+
}
106+
},
107+
"RegularSchema" : {
108+
"type" : "object",
109+
"description" : "regularSchema",
110+
"properties" : {
111+
"name" : {
112+
"type" : "string"
113+
},
114+
"value" : {
115+
"type" : "string"
116+
}
117+
}
118+
}
119+
}
120+
}
121+
}

0 commit comments

Comments
 (0)