Swagger ApiModelProperty access
Asked Answered
P

5

26

I'm using the same Object both for my Request and Response on a REST endpoint. Is it possible to annotate a property with ApiModelProperty(access = "response") and then annotate the rest endpoint method with @ApiImplicitParam(access = "response") so that the property only shows up in the swagger doc for the response object and not the request one?

Publishing answered 9/9, 2015 at 16:39 Comment(0)
I
3

You can achieve the same using @ApiModelProperty(readOnly = true). Allows a model property to be designated as read only. It will hide property from request and shows for a response only.

@ApiModelProperty(readOnly = true)

Industrious answered 18/6, 2020 at 8:57 Comment(1)
Unfortunately this did not work on swagger 1.6, the property shows up for both request and response when this annotation is applied to a java field.Vagarious
C
1

You better write a new DTO for this purpose

Caputto answered 18/6, 2020 at 21:41 Comment(0)
A
0

I think you can try with

@ApiParam(access = "hidden")

Reference:
Spring Rest API with Swagger – Fine-tuning exposed documentation

Aerography answered 19/2, 2018 at 10:30 Comment(0)
R
0

You can also try:

@Schema(accessMode=AccessMode.READ_ONLY)
Remorse answered 20/2, 2020 at 17:56 Comment(0)
G
-2

You can use now

@ApiModelProperty(hidden=true)
Goldcrest answered 5/12, 2018 at 12:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.