-
-
Notifications
You must be signed in to change notification settings - Fork 497
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom Converters are not excluded if not registered for Http Message Converter #2165
Comments
I think the cause is that BToAConvertor uses @component to create a Bean. example public record User(String id) {}
@Component
public class UserConverter implements Converter<String, User> {
@Override
public User convert(String userId) {
User user = new User(userId);
return user;
}
}
@RestController
@RequestMapping("converter")
public class ConverterController {
@GetMapping("/{userId}")
public User doSomething(@PathVariable("userId") User user) {
return user;
}
} $ curl http://localhost:8080/converter/test
{"id":"test"} |
A shorter workaround is to use @GetMapping(value = "/test")
public String test(@Schema(implementation = ObjectA.class) @RequestBody ObjectA request) {
return "OK!";
} |
@uc4w6c But that is true when we use Tried testing if string data in body can be converted to ObjectA by setting content type as text/plain, and creating String to A converter. Did not work! @Component
class StringToAConvertor implements Converter<String, ObjectA> {
@Override
public ObjectA convert(String source) {
return new ObjectA(source);
}
}
@RestController
class Controller {
@PostMapping(value = "/test", consumes = MediaType.TEXT_PLAIN_VALUE)
public ObjectA test(@RequestBody ObjectA request) {
return request;
}
@ExceptionHandler
public void genericException(Exception e) {
e.printStackTrace();
}
} THROWS |
@RittikeGhosh |
i have added a workaround for it. |
This works now. Tested with the latest version |
Bug Description
Feature to support Custom Spring Converter(#1534), is generating wrong openapi specification. I think all converters are considered as Http Message Converter, which it shouldn't. Hence it is generating the request body schema as the Source Object picked from the converter with target as the actual Object defined in the Request Handler Method in Controller.
This is happening for both WebMvc and WebFlux.
To Reproduce
Using :
3.0.5
org.springdoc:springdoc-openapi-starter-webflux-ui:2.0.4
Code setup:
Output OpenApi Specification:
Generated
ObjectB
instead ofObjectA
as request schemaExpected behavior
I expect the converters to be picked only if it is registered for Http Message Converter. Here I didn't register it for that, it is used for other internal purpose.
Expected OpenApi Specification:
Workaround Code
The text was updated successfully, but these errors were encountered: