3

We have two versions of Class XXX. In the version one it includes property x and excludes property y and in the second version x is excluded and y is included.

I'm not able to do that as I can not pass parameters to hidden property it expects a contsant expression.

This is the sample code I use, Here quantity is xx.

@ApiModelProperty(dataType = "Float", required = false, notes = "Item Sequence", position = 5, hidden = this.isOpenMapping)
    public Float getQuantity() {
        return quantity;
    }

this.isOpenMapping is class attribute to distinguish whether version one or two.

How to fix this? If you need any more information please let me know.

newday
  • 3,842
  • 10
  • 54
  • 79

1 Answers1

1

When working in swagger the closest thing you can achieve to address your question is polymorphism of a class. Despite of the fact that this is not completely supported in Swagger it actually can work with a bit of effort in the autogen code. See here for more details.

Using polymorphism you can dynamically create different response based on the requested entity type, sharing a common code base.

That said, consider to implement a composition and inheritance logic as well. See here about Swagger Inheritance and Composition.

Community
  • 1
  • 1
loretoparisi
  • 15,724
  • 11
  • 102
  • 146