We have a GET endpoint, which does not always return data, and the idea is to define two 2xx responses:
- If we have some data, then we return a 200 code with the response body.
- If we don't have any data, then we return a 204 code and no response body.
"paths": {
"/my-endpoint/": {
"get": {
"operationId": "myOperation",
"responses:": {
"200": {
"description": "OK with body",
"content": {
"application/json": {
"schema":{
"$ref": "#/components/schemas/MyResponse"
}
}
}
},
"204": {
"description": "OK"
}
}
....
Is this possible / allowed, and what is the best practice for such a use case?