Skip to content

Commit c3de760

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

File tree

3 files changed

+101
-2
lines changed

3 files changed

+101
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ Schema calculateSchema(Components components, ParameterInfo parameterInfo, Reque
358358
WebConversionServiceProvider webConversionServiceProvider = optionalWebConversionServiceProvider.get();
359359
if (!MethodParameterPojoExtractor.isSwaggerPrimitiveType((Class) type) && methodParameter.getParameterType().getAnnotation(io.swagger.v3.oas.annotations.media.Schema.class) == null) {
360360
Class<?> springConvertedType = webConversionServiceProvider.getSpringConvertedType(methodParameter.getParameterType());
361-
if (!(String.class.equals(springConvertedType) && ((Class<?>) type).isEnum()))
361+
if (!(String.class.equals(springConvertedType) && ((Class<?>) type).isEnum()) && requestBodyInfo==null)
362362
type = springConvertedType;
363363
}
364364
}

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

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,67 @@
2525
import test.org.springdoc.api.v30.AbstractSpringDocV30Test;
2626

2727
import org.springframework.boot.autoconfigure.SpringBootApplication;
28+
import org.springframework.core.convert.converter.Converter;
29+
import org.springframework.stereotype.Component;
30+
import org.springframework.web.bind.annotation.PostMapping;
31+
import org.springframework.web.bind.annotation.RequestBody;
32+
import org.springframework.web.bind.annotation.RestController;
2833

2934
public class SpringDocApp183Test extends AbstractSpringDocV30Test {
3035

3136
@SpringBootApplication
32-
static class SpringDocTestApp {}
37+
static class SpringDocTestApp {
38+
class ObjectA {
39+
private final String aa;
40+
private final String aaa;
41+
42+
public ObjectA(String aa, String aaa) {
43+
this.aa = aa;
44+
this.aaa = aaa;
45+
}
46+
47+
public String getAa() {
48+
return aa;
49+
}
50+
51+
public String getAaa() {
52+
return aaa;
53+
}
54+
}
55+
56+
class ObjectB {
57+
private final Integer bb;
58+
private final Integer bbb;
59+
60+
public ObjectB(Integer bb, Integer bbb) {
61+
this.bb = bb;
62+
this.bbb = bbb;
63+
}
64+
65+
public Integer getBb() {
66+
return bb;
67+
}
68+
69+
public Integer getBbb() {
70+
return bbb;
71+
}
72+
}
73+
74+
75+
@Component
76+
class BToAConvertor implements Converter<ObjectB, ObjectA> {
77+
@Override
78+
public ObjectA convert(ObjectB source) {
79+
return new ObjectA(source.bb+"", source.bbb+"");
80+
}
81+
}
82+
83+
@RestController
84+
class Controller {
85+
@PostMapping("/test")
86+
public String test(@RequestBody ObjectA request) {
87+
return "OK!";
88+
}
89+
}
90+
}
3391
}

springdoc-openapi-webmvc-core/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)