[英]Failed to convert property value of type 'java.lang.String' to required type in Open API 3
I have a @RestController with such method我有一个带有这种方法的@RestController
@RestController
public MyController {
@Operation(summary = "Some text", description = "Some text again"
@GetMapping("/route")
public MyClassResponse getSomething(
@Parameter(name = "My request", description = "My request") MyRequest request
) {
// to do smth
return response
}
where MyRequest is MyRequest 在哪里
public class MyRequest {
private int param1;
private String param2;
private MyClass param3;
}
and MyClass looks like MyClass 看起来像
public class MyClass {
private int clazzParam1;
private int clazzParam2;
}
First of all, Swagger shows parameter MyRequest like body首先,Swagger 显示参数 MyRequest like body
{
"param1" : 0;
"param2" : "string",
"param3" : {
"clazzParam1" : 0,
"clazzParam2" : 0
}
}
but I would like to see every parameter like this但我想看到这样的每个参数
Second when I try make request, I get this curl其次,当我尝试提出请求时,我得到了这个 curl
http://localhost:8080/route?param1=0¶m2=string¶m3=clazzParam1,0,clazzParam2,0 http://localhost:8080/route?param1=0¶m2=string¶m3=clazzParam1,0,clazzParam2,0
instead反而
http://localhost:8080/route?param1=0¶m2=string¶m3.clazzParam1=0¶m3.clazzParam2=0 http://localhost:8080/route?param1=0¶m2=string¶m3.clazzParam1=0¶m3.clazzParam2=0
Therefore response contain next failure Failed to convert property value of type 'java.lang.String' to required type 'MyClass' for property 'param3'.因此响应包含下一个失败无法将类型“java.lang.String”的属性值转换为属性“param3”所需的类型“MyClass”。
How should I use annotations to get what I want?我应该如何使用注释来获得我想要的东西? For various reasons I can't use.yaml description.
由于各种原因我无法使用。yaml 描述。 Thank you.
谢谢你。
@ParameterObject is answer. @ParameterObject 是答案。 It unpacking object to parameters in Swagger UI
它将 object 解包到 Swagger UI 中的参数
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.