summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-09-21 23:29:17 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-09-21 23:29:17 +0200
commit5df60344fd2695a24a2626ca8eb8064dc8c3437b (patch)
tree0f2171d615cc627407ccea7768795ebce8b0fc1c
parent:sparkles: unit tests expect event (diff)
downloadserver-5df60344fd2695a24a2626ca8eb8064dc8c3437b.tar.xz
:sparkles: example value in documentation
-rw-r--r--api/package.json5
-rw-r--r--api/scripts/generate_openapi.js (renamed from api/scripts/generate_openapi_schema.js)16
-rw-r--r--api/scripts/generate_schema.js (renamed from api/scripts/generate_body_schema.js)0
3 files changed, 15 insertions, 6 deletions
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
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
index 22d0b02e..22d0b02e 100644
--- a/api/scripts/generate_body_schema.js
+++ b/api/scripts/generate_schema.js