Skip to content

Commit bd08fb3

Browse files
committed
Custom Converters are not excluded if not registered for Http Message Converter. Fixes #2165
1 parent c06fcdc commit bd08fb3

File tree

3 files changed

+70
-2
lines changed

3 files changed

+70
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ Schema calculateSchema(Components components, ParameterInfo parameterInfo, Reque
366366
WebConversionServiceProvider webConversionServiceProvider = optionalWebConversionServiceProvider.get();
367367
if (!MethodParameterPojoExtractor.isSwaggerPrimitiveType((Class) type) && methodParameter.getParameterType().getAnnotation(io.swagger.v3.oas.annotations.media.Schema.class) == null) {
368368
Class<?> springConvertedType = webConversionServiceProvider.getSpringConvertedType(methodParameter.getParameterType());
369-
if (!(String.class.equals(springConvertedType) && ((Class<?>) type).isEnum()))
369+
if (!(String.class.equals(springConvertedType) && ((Class<?>) type).isEnum()) && requestBodyInfo==null)
370370
type = springConvertedType;
371371
}
372372
}

springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v30/app183/SpringDocApp183Test.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,36 @@
2727
import test.org.springdoc.api.v30.AbstractSpringDocV30Test;
2828

2929
import org.springframework.boot.autoconfigure.SpringBootApplication;
30+
import org.springframework.core.convert.converter.Converter;
31+
import org.springframework.stereotype.Component;
32+
import org.springframework.web.bind.annotation.PostMapping;
33+
import org.springframework.web.bind.annotation.RequestBody;
34+
import org.springframework.web.bind.annotation.RestController;
3035

3136
public class SpringDocApp183Test extends AbstractSpringDocV30Test {
3237

3338
@SpringBootApplication
34-
static class SpringDocTestApp {}
39+
static class SpringDocTestApp {
40+
41+
record ObjectA(String aa, String aaa) {}
42+
43+
record ObjectB(Integer bb, Integer bbb) {}
44+
45+
@Component
46+
class BToAConvertor implements Converter<ObjectB, ObjectA> {
47+
@Override
48+
public ObjectA convert(ObjectB source) {
49+
return new ObjectA(source.bb+"", source.bbb+"");
50+
}
51+
}
52+
53+
@RestController
54+
class Controller {
55+
@PostMapping("/test")
56+
public String test(@RequestBody ObjectA request) {
57+
return "OK!";
58+
}
59+
}
60+
}
61+
3562
}

springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.0.1/app183.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,36 @@
1717
}
1818
],
1919
"paths": {
20+
"/test": {
21+
"post": {
22+
"tags": [
23+
"controller"
24+
],
25+
"operationId": "test",
26+
"requestBody": {
27+
"content": {
28+
"application/json": {
29+
"schema": {
30+
"$ref": "#/components/schemas/ObjectA"
31+
}
32+
}
33+
},
34+
"required": true
35+
},
36+
"responses": {
37+
"200": {
38+
"description": "OK",
39+
"content": {
40+
"*/*": {
41+
"schema": {
42+
"type": "string"
43+
}
44+
}
45+
}
46+
}
47+
}
48+
}
49+
},
2050
"/{userId}": {
2151
"get": {
2252
"tags": [
@@ -50,6 +80,17 @@
5080
},
5181
"components": {
5282
"schemas": {
83+
"ObjectA": {
84+
"type": "object",
85+
"properties": {
86+
"aa": {
87+
"type": "string"
88+
},
89+
"aaa": {
90+
"type": "string"
91+
}
92+
}
93+
},
5394
"User": {
5495
"type": "object",
5596
"properties": {

0 commit comments

Comments
 (0)