How dynamism allows you to disable properties in swagger
We have two versions of the XXX class. In the first version, it includes property x and excludes property y, and in the second version, x is excluded and y is included.
I cannot do this as I cannot pass parameters to the hidden property, it expects a contsant expression.
This is the sample code I am using. Here is the value xx.
@ApiModelProperty(dataType = "Float", required = false, notes = "Item Sequence", position = 5, hidden = this.isOpenMapping)
public Float getQuantity() {
return quantity;
}
this.isOpenMapping is a class attribute to distinguish one or two versions.
How to fix it? If you need more information, please let me know.
source to share
When working on the swagger
closest thing you can work out to solve your question is polymorphism
class. While this is not fully supported in swagger
, it can actually work with a little effort in autogen code. See here for details .
Using polymorphism
, you can dynamically generate different responses based on the requested object type using a common code base.
Nevertheless, consider the possibility of implementing the logic composition
and inheritance
. See here about Swagger inheritance and composition.
source to share