Reputation: 13
I have a sample object which is referenced by swagger to create a POST endpoint in my documentation.
I then use the documentation to generate a client for testing. However, the API works slightly differently then how the object is directly presented. I want to override the POST body parameter type of the created model in the documentation from a service type to a string (a reference string to the service). I've included the referenced object below.
@Entity
public class ServiceType {
private String id;
private Service service;
private String type;
public Service getService() {
return service;
}
public void setService(Service service) {
this.service = service;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
The body is generate as:
{
"createdDate": "2019-03-12T15:18:22.568Z",
"id": "string",
"service": {
"createdDate": "2019-03-12T15:18:22.568Z",
"id": "string",
"name": "string",
"routingKey": "string",
"updatedBy": "string",
"updatedDate": "2019-03-12T15:18:22.569Z"
},
"type": "string",
"updatedBy": "string",
"updatedDate": "2019-03-12T15:18:22.569Z"
}
But I want it to be in the format:
{
"createdDate": "2019-03-12T15:18:22.568Z",
"id": "string",
"service": "string",
"type": "string",
"updatedBy": "string",
"updatedDate": "2019-03-12T15:18:22.569Z"
}
Not sure if this is possible. Thanks for the help.
Upvotes: 0
Views: 1351
Reputation: 3949
You can use the @ApiModel
and @ApiModelProperty
annotations to override the default data type for a field. Note that the data type must be a fully-qualified type name (such as java.lang.String
). For more information, see Overriding Property Datatypes.
@Entity
@ApiModel
public class ServiceType {
private String id;
@ApiModelProperty(dataType = "java.lang.String")
private Service service;
private String type;
public Service getService() {
return service;
}
public void setService(Service service) {
this.service = service;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
Upvotes: 1