Answer the question
In order to leave comments, you need to log in
How to describe a single REST API response format for everyone in Swagger OpenAPI3?
There are many controllers, all of them return a response in the same format:
{
"response": true, # true/false
"error": {
"code": 0, # 0 или код ошибки
"message": "" # текст ошибки
},
"data": null # null или данные ответа
}
paths:
/system/banner/{position}:
get:
# ...
parameters:
- name: position
# ...
responses:
200:
description: OK
headers:
# ...
content:
application/json:
schema:
allOf:
- $ref: '#/components/responses/CommonResponse' # <-- Единый формат ответа
- properties: <-- # Он должен быть дополнен данными
data:
$ref: '#/components/schemas/BannerList'
400:
# ...
{
"data": [
{
"id": 0,
"title": "string",
"content": "string",
"date_created": "2019-08-07T10:54:38.215Z",
"date_edited": "2019-08-07T10:54:38.215Z"
}
]
}
{
"response": true,
"error": {
"code": 0,
"message": ""
},
"data": [
{
"id": 0,
"title": "string",
"content": "string",
"date_created": "2019-08-07T10:54:38.215Z",
"date_edited": "2019-08-07T10:54:38.215Z"
}
]
}
Answer the question
In order to leave comments, you need to log in
properties should be on the same level as allOf, like this:
allOf:
- $ref: '#/components/responses/CommonResponse' # <-- Единый формат ответа
properties: <-- # Он должен быть дополнен данными
data:
$ref: '#/components/schemas/BannerList'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question