From b440657a54a0ea8a04a41f774af71cc18b460485 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Wed, 16 Feb 2022 18:23:38 +0000 Subject: [PATCH] Adding variables to generator. --- packages/server/specs/generate.js | 12 ++++++++++-- packages/server/specs/openapi.json | 13 ++++++++++++- packages/server/src/api/index.js | 5 ++++- packages/server/src/api/routes/index.js | 2 ++ 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/packages/server/specs/generate.js b/packages/server/specs/generate.js index 0d84ed8ac5..7131056f79 100644 --- a/packages/server/specs/generate.js +++ b/packages/server/specs/generate.js @@ -3,6 +3,9 @@ const { join } = require("path") const { writeFileSync } = require("fs") const FILE_NAME = "openapi.json" +const VARIABLES = { + prefixV1: "api/public/v1", +} const options = { definition: { @@ -20,13 +23,18 @@ const options = { ], }, format: "json", - apis: [join(__dirname, "..", "src", "api", "routes", "public*.js")], + apis: [join(__dirname, "..", "src", "api", "routes", "public", "*.js")], } const output = swaggerJsdoc(options) try { const path = join(__dirname, FILE_NAME) - writeFileSync(path, JSON.stringify(output, null, 2)) + let spec = JSON.stringify(output, null, 2) + for (let [key, replacement] of Object.entries(VARIABLES)) { + spec = spec.replace(new RegExp(`{${key}}`, "g"), replacement) + } + // input the static variables + writeFileSync(path, spec) console.log(`Wrote spec to ${path}`) } catch (err) { console.error(err) diff --git a/packages/server/specs/openapi.json b/packages/server/specs/openapi.json index f9f34c985c..b9c0d30d3b 100644 --- a/packages/server/specs/openapi.json +++ b/packages/server/specs/openapi.json @@ -11,7 +11,18 @@ "description": "Budibase Cloud API" } ], - "paths": {}, + "paths": { + "/api/public/v1/row/search": { + "post": { + "description": "Search for rows.", + "responses": { + "200": { + "description": "Returns the rows." + } + } + } + } + }, "components": {}, "tags": [] } \ No newline at end of file diff --git a/packages/server/src/api/index.js b/packages/server/src/api/index.js index 4a94063e31..8b0c091346 100644 --- a/packages/server/src/api/index.js +++ b/packages/server/src/api/index.js @@ -8,7 +8,7 @@ const { const currentApp = require("../middleware/currentapp") const compress = require("koa-compress") const zlib = require("zlib") -const { mainRoutes, staticRoutes } = require("./routes") +const { mainRoutes, staticRoutes, publicRoutes } = require("./routes") const pkg = require("../../package.json") const env = require("../environment") @@ -82,6 +82,9 @@ for (let route of mainRoutes) { router.use(route.allowedMethods()) } +router.use(publicRoutes.routes()) +router.use(publicRoutes.allowedMethods()) + // WARNING - static routes will catch everything else after them this must be last router.use(staticRoutes.routes()) router.use(staticRoutes.allowedMethods()) diff --git a/packages/server/src/api/routes/index.js b/packages/server/src/api/routes/index.js index 8ded7104b0..ddda62e2f5 100644 --- a/packages/server/src/api/routes/index.js +++ b/packages/server/src/api/routes/index.js @@ -25,6 +25,7 @@ const metadataRoutes = require("./metadata") const devRoutes = require("./dev") const cloudRoutes = require("./cloud") const migrationRoutes = require("./migrations") +const publicRoutes = require("./public") exports.mainRoutes = [ authRoutes, @@ -58,3 +59,4 @@ exports.mainRoutes = [ ] exports.staticRoutes = staticRoutes +exports.publicRoutes = publicRoutes