Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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:""
}
like image 489
Siva Kumar Avatar asked Feb 21 '17 05:02

Siva Kumar


People also ask

How do I ignore fields in swagger?

Using @JsonIgnore We can use it to specify that a field is to be ignored by Jackson during serialization and deserialization. We can add the annotation to just the field to be ignored, and it'll hide both getters and setters for the specified field.

What is get and post in swagger?

A single path can support multiple operations, for example GET /users to get a list of users and POST /users to add a new user.

How do you mark deprecated in swagger?

There is no special attribute which can mark service endpoint to show it as deprecated in swagger schema, but you can use OperationFilter action when register SwaggerFeature to modify swagger declarations and set Deprecated property to string “true” for obsolete methods.

How do you hide entity in swagger?

To hide the "Models" section, add defaultModelsExpandDepth: -1 to the Swagger UI configuration code in your index.


2 Answers

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

like image 103
Daniel Chaoui Santos Avatar answered Oct 23 '22 10:10

Daniel Chaoui Santos


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.

like image 1
Tk421 Avatar answered Oct 23 '22 11:10

Tk421