summary refs log tree commit diff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/openapi.js59
1 files changed, 30 insertions, 29 deletions
diff --git a/scripts/openapi.js b/scripts/openapi.js

index 49d5dfde..86527ada 100644 --- a/scripts/openapi.js +++ b/scripts/openapi.js
@@ -147,36 +147,37 @@ function apiRoutes() { }.merge(obj.requestBody); } - if (route.test?.response) { - const status = route.test.response.status || 200; - let schema = { - allOf: [ - { - $ref: `#/components/schemas/${route.test.response.body}`, - }, - { - example: route.test.body, - }, - ], - }; - if (!route.test.body) schema = schema.allOf[0]; - - obj.responses = { - [status]: { - ...(route.test.response.body - ? { - description: - obj?.responses?.[status]?.description || "", - content: { - "application/json": { - schema: schema, + if (route.responses) { + for (const [k, v] of Object.entries(route.responses)) { + let schema = { + allOf: [ + { + $ref: `#/components/schemas/${v.body}`, + }, + { + example: v.body, + }, + ], + }; + if (!v.body) schema = schema.allOf[0]; + + obj.responses = { + [k]: { + ...(v.body + ? { + description: + obj?.responses?.[k]?.description || "", + content: { + "application/json": { + schema: schema, + }, }, - }, - } - : {}), - }, - }.merge(obj.responses); - delete obj.responses.default; + } + : {}), + }, + }.merge(obj.responses); + delete obj.responses.default; + } } if (p.includes(":")) { obj.parameters = p.match(/:\w+/g)?.map((x) => ({