jav*_*ase 5 jax-rs resteasy swagger
我已经尝试过使用Swagger JaxRs当前主版本1.0和Swagger 2.0的devel_2.0分支。
@ApiModel(value = "Animal",
subTypes = {Dog.class, Lion.class},
discriminator = "type")
public class Animal {
@ApiModelProperty(value = "the discriminator field.")
private String type;
Run Code Online (Sandbox Code Playgroud)
这是子类之一,
@ApiModel(value = "Lion", parent = Animal.class)
public class Lion {
@ApiModelProperty(value = "the discriminator field.")
private String type;
Run Code Online (Sandbox Code Playgroud)
我没有找到任何期望的例子,但这是我当前的Swagger 2.0项目swagger.json文件中的输出。
"definitions":{
"Animal":{
"properties":{
"type":{
"type":"string",
"description":"the discriminator field."
}
},
"discriminator":"type"
},
Run Code Online (Sandbox Code Playgroud)
定义中没有Dog或Lion对象的迹象。请求对象中没有任何内容。我不确定这是否会奏效,但是如果您知道它应该如何运作,请告诉我。
如果要查看完整的上下文,所有代码都在这里。
https://github.com/javatestcase/RestEasy/tree/RestEasyVersion2
您的示例对我很有帮助,所以我认为我应该为您提供帮助,因为我现在可以正常工作了!
您需要告诉序列化/反序列化如何绑定实现:
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME, // Were binding by providing a name
include = JsonTypeInfo.As.PROPERTY, // The name is provided in a property
property = "type", // Property name is type
visible = true // Retain the value of type after deserialisation
)
@JsonSubTypes({//Below, we define the names and the binding classes.
@JsonSubTypes.Type(value = Lion.class, name = "Lion"),
@JsonSubTypes.Type(value = Dog.class, name = "Dog")
})
@ApiModel(value = "Animal", subTypes = {Dog.class, Lion.class}, discriminator = "type")
public class Animal {
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3346 次 |
| 最近记录: |