From e9c3f7ee1cb186f68d5c42add0552e4487d8b792 Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Tue, 21 Sep 2021 23:29:17 +0200 Subject: [PATCH] :sparkles: example value in documentation --- api/package.json | 5 ++--- ...ate_openapi_schema.js => generate_openapi.js} | 16 +++++++++++++--- ...enerate_body_schema.js => generate_schema.js} | 0 3 files changed, 15 insertions(+), 6 deletions(-) rename api/scripts/{generate_openapi_schema.js => generate_openapi.js} (93%) rename api/scripts/{generate_body_schema.js => generate_schema.js} (100%) diff --git a/api/package.json b/api/package.json index 53031071..a1d3b5b2 100644 --- a/api/package.json +++ b/api/package.json @@ -15,9 +15,8 @@ "dev": "tsnd --respawn src/start.ts", "patch": "npx patch-package", "postinstall": "npm run patch", - "generate:docs": "ts-node scripts/generate_openapi_schema.ts", - "generate:test": "ts-node scripts/generate_test_schema.ts", - "generate:schema": "ts-node scripts/generate_body_schema.ts" + "generate:docs": "node scripts/generate_openapi.ts", + "generate:schema": "node scripts/generate_schema.ts" }, "repository": { "type": "git", diff --git a/api/scripts/generate_openapi_schema.js b/api/scripts/generate_openapi.js similarity index 93% rename from api/scripts/generate_openapi_schema.js rename to api/scripts/generate_openapi.js index eb979f14..c9de9fa6 100644 --- a/api/scripts/generate_openapi_schema.js +++ b/api/scripts/generate_openapi.js @@ -81,6 +81,18 @@ function apiRoutes() { } 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 @@ -88,9 +100,7 @@ function apiRoutes() { description: obj.responses[status].description || "", content: { "application/json": { - schema: { - $ref: `#/components/schemas/${route.test.response.body}` - } + schema: schema } } } diff --git a/api/scripts/generate_body_schema.js b/api/scripts/generate_schema.js similarity index 100% rename from api/scripts/generate_body_schema.js rename to api/scripts/generate_schema.js