How to ignore swagger resource property for specific http verb(GET,POST,PUT)
Asked Answered
E

2

5

We are implemented spring fox swagger 2 of version 2.6.1, i wanted to display a specific property of a resource for HTTP GET METHOD and not for POST METHOD, i haven't find any approach using swagger 2. Please help thanks.

For example:

Class Employee{

Integer id;
String name;

}

Request URI: GET /api/employee/{id} i should see the swagger request document as

{
  id:"",
  name:""
}

Request URI: POST /api/employee i should see the swagger request sample as

{
    name:""
}
Esther answered 21/2, 2017 at 5:12 Comment(4)
This is currently not possible in springfox 2.6.1Bourgeon
Thank you Dilip for the response , do we have any another approach to achieve this ?Esther
By not possible I mean it's a feature request that hasn't been implemented. The way to get around it is to use separate models for each of the operations.Bourgeon
any updates to this?Diptych
O
3

I upgraded to version 2.8.0 and it is possible with @ApiModelProperty(readOnly = true). This causes the property to be #Returned by GET, not used in POST / PUT / PATCH

Osteoblast answered 1/2, 2018 at 13:4 Comment(1)
This readOnly flag is deprecated, and specifying accessMode=AccessMode.READ_ONLY doesn't do the trick.Ostap
S
2

This was the valid response in older swagger.

@ApiModelProperty(readOnly = true)

In Swagger V3 you need to use AccesMode. Example:

@Schema(accessMode = Schema.AccessMode.READ_ONLY)
private long id;

This will make id visible for all GET requests.

Salutary answered 24/8, 2020 at 1:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.