Skip to content

Commit

Permalink
Custom Converters are not excluded if not registered for Http Message…
Browse files Browse the repository at this point in the history
… Converter. Fixes #2165
  • Loading branch information
bnasslahsen committed Apr 1, 2023
1 parent 50b06ad commit c3de760
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ Schema calculateSchema(Components components, ParameterInfo parameterInfo, Reque
WebConversionServiceProvider webConversionServiceProvider = optionalWebConversionServiceProvider.get();
if (!MethodParameterPojoExtractor.isSwaggerPrimitiveType((Class) type) && methodParameter.getParameterType().getAnnotation(io.swagger.v3.oas.annotations.media.Schema.class) == null) {
Class<?> springConvertedType = webConversionServiceProvider.getSpringConvertedType(methodParameter.getParameterType());
if (!(String.class.equals(springConvertedType) && ((Class<?>) type).isEnum()))
if (!(String.class.equals(springConvertedType) && ((Class<?>) type).isEnum()) && requestBodyInfo==null)
type = springConvertedType;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,67 @@
import test.org.springdoc.api.v30.AbstractSpringDocV30Test;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

public class SpringDocApp183Test extends AbstractSpringDocV30Test {

@SpringBootApplication
static class SpringDocTestApp {}
static class SpringDocTestApp {
class ObjectA {
private final String aa;
private final String aaa;

public ObjectA(String aa, String aaa) {
this.aa = aa;
this.aaa = aaa;
}

public String getAa() {
return aa;
}

public String getAaa() {
return aaa;
}
}

class ObjectB {
private final Integer bb;
private final Integer bbb;

public ObjectB(Integer bb, Integer bbb) {
this.bb = bb;
this.bbb = bbb;
}

public Integer getBb() {
return bb;
}

public Integer getBbb() {
return bbb;
}
}


@Component
class BToAConvertor implements Converter<ObjectB, ObjectA> {
@Override
public ObjectA convert(ObjectB source) {
return new ObjectA(source.bb+"", source.bbb+"");
}
}

@RestController
class Controller {
@PostMapping("/test")
public String test(@RequestBody ObjectA request) {
return "OK!";
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,36 @@
}
],
"paths": {
"/test": {
"post": {
"tags": [
"controller"
],
"operationId": "test",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ObjectA"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "OK",
"content": {
"*/*": {
"schema": {
"type": "string"
}
}
}
}
}
}
},
"/{userId}": {
"get": {
"tags": [
Expand Down Expand Up @@ -50,6 +80,17 @@
},
"components": {
"schemas": {
"ObjectA": {
"type": "object",
"properties": {
"aa": {
"type": "string"
},
"aaa": {
"type": "string"
}
}
},
"User": {
"type": "object",
"properties": {
Expand Down

0 comments on commit c3de760

Please sign in to comment.