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?

gregorycallea
  • 1,218
  • 1
  • 9
  • 28
hello_world_infinity
  • 4,760
  • 9
  • 32
  • 32

5 Answers5

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)

SSK
  • 3,444
  • 6
  • 32
  • 59
  • 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. – user1445967 Feb 01 '21 at 19:39
1

You better write a new DTO for this purpose

lazarevsky
  • 83
  • 1
  • 7
0

I think you can try with

@ApiParam(access = "hidden")

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

Omar Einea
  • 2,478
  • 7
  • 23
  • 35
Man
  • 11
  • 2
0

You can also try:

@Schema(accessMode=AccessMode.READ_ONLY)
Nimantha
  • 6,405
  • 6
  • 28
  • 69
Matt
  • 31
  • 1
-2

You can use now

@ApiModelProperty(hidden=true)
acaruci
  • 879
  • 9
  • 14