I am currently working in a code base where for every REST API response they use a java class like below
{
Object payload;
List<Error> errors;
String responseStatus;
}
The problem is, when we refer to the swagger documentation of the REST APIs it shows a json structure like below.
{
"payload":{},
"errors": [
{
"errMsg":"",
"errCode": ""
}
],
"responseStatus":""
}
So the response will have payload if response is success, error list in case of errors and response status set to success or failure respectively.
- Is it a good practice to use same json structure for error and success?
- Is there any way to improve swagger documentation, so that I can show what the response payload json will look like for a particular API response.
EDIT: I just want to mention that I cannot change the response payload to any thing else, as it is being used in more than 1000 APIs and is distributed into different services.
Is there any way to improve at least the swagger documentation, without changing the Response Object in java, because that ship has sailed a long time ago.