Exclude Models or properties from swagger response

后端 未结 2 941
花落未央
花落未央 2020-12-09 20:13

I used swagger in my apache cxf project , used @Api and @ApiOperations and @ApiParam annotations and generated a api doc for the rest services.

But I want to exclude

相关标签:
2条回答
  • 2020-12-09 20:51

    First of all, you should upgrade to the latest swagger-core version, currently 1.3.12 (you're using a really old one).

    You have 3 ways to hide a property:

    1. If you're using JAXB annotations, you can use @XmlTransient.
    2. If you're using Jackson, you can use @JsonIgnore.
    3. If you're not using either, or don't want to affect the general de/serialization of your models, you can use Swagger's @ApiModelProperty's hidden attribute.

    Keep in mind you may need to set these on your getters/setters rather than on the property itself. Play with the definitions to see what works for you.

    With regards to the issue with the User model, the problem is that you do not reference it from the @ApiOperation (you also don't need the httpMethod property). Try changing it as follows:

    @ApiOperation(value = "xxx", notes = "user details", response =  User.class)
    
    0 讨论(0)
  • 2020-12-09 21:00

    You can exclude fields like that :

    @ApiModelProperty(position = 1, required = true, hidden=true, notes = "used to display user name")
    
    0 讨论(0)
提交回复
热议问题