From 5f94ed7fe0753b04f4509791e666ec231ddaf993 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 17 Feb 2022 12:40:08 +0000 Subject: [PATCH] Fixing up generation of openapi. --- packages/server/specs/generate.js | 45 +++++++++++++++++++----------- packages/server/specs/openapi.json | 36 ++++++++++++++++-------- 2 files changed, 54 insertions(+), 27 deletions(-) diff --git a/packages/server/specs/generate.js b/packages/server/specs/generate.js index 7131056f79..f70f339a0a 100644 --- a/packages/server/specs/generate.js +++ b/packages/server/specs/generate.js @@ -2,10 +2,7 @@ const swaggerJsdoc = require("swagger-jsdoc") const { join } = require("path") const { writeFileSync } = require("fs") -const FILE_NAME = "openapi.json" -const VARIABLES = { - prefixV1: "api/public/v1", -} +const VARIABLES = {} const options = { definition: { @@ -17,25 +14,41 @@ const options = { }, servers: [ { - url: "http://budibase.app/api", + url: "http://budibase.app/api/public/v1", description: "Budibase Cloud API", }, + { + url: "http://localhost:10000/api/public/v1", + description: "Budibase self hosted API", + }, ], }, format: "json", apis: [join(__dirname, "..", "src", "api", "routes", "public", "*.js")], } -const output = swaggerJsdoc(options) -try { - const path = join(__dirname, FILE_NAME) - let spec = JSON.stringify(output, null, 2) - for (let [key, replacement] of Object.entries(VARIABLES)) { - spec = spec.replace(new RegExp(`{${key}}`, "g"), replacement) +function writeFile(output, { isJson } = {}) { + try { + const filename = isJson ? "openapi.json" : "openapi.yaml" + const path = join(__dirname, filename) + let spec = output + if (isJson) { + spec = JSON.stringify(output, null, 2) + } + // input the static variables + for (let [key, replacement] of Object.entries(VARIABLES)) { + spec = spec.replace(new RegExp(`{${key}}`, "g"), replacement) + } + writeFileSync(path, spec) + console.log(`Wrote spec to ${path}`) + } catch (err) { + console.error(err) } - // input the static variables - writeFileSync(path, spec) - console.log(`Wrote spec to ${path}`) -} catch (err) { - console.error(err) } + +const outputJSON = swaggerJsdoc(options) +options.format = "yaml" +const outputYAML = swaggerJsdoc(options) +console.log(outputYAML) +writeFile(outputJSON) +writeFile(outputYAML) diff --git a/packages/server/specs/openapi.json b/packages/server/specs/openapi.json index 076b1965a5..1c6dfe9d25 100644 --- a/packages/server/specs/openapi.json +++ b/packages/server/specs/openapi.json @@ -7,23 +7,29 @@ }, "servers": [ { - "url": "http://budibase.app/api", + "url": "https://budibase.app/api/public/v1", "description": "Budibase Cloud API" + }, + { + "url": "http://localhost:10000/api/public/v1", + "description": "Budibase self hosted API" } ], "paths": { - "/api/public/v1/row/{tableId}/search": { + "/row/{tableId}/search": { "post": { "summary": "Allows searching for rows within a table.", - "parameters": { - "name": "tableId", - "in": "path", - "required": true, - "description": "The ID of the table which contains the rows which are being searched for.", - "schema": { - "type": "string" + "parameters": [ + { + "in": "path", + "name": "tableId", + "required": true, + "description": "The ID of the table which contains the rows which are being searched for.", + "schema": { + "type": "string" + } } - }, + ], "requestBody": { "required": true, "content": { @@ -33,7 +39,15 @@ "properties": { "string": { "type": "object", - "description": "A map of field name to the string to search for, this will look for rows that have a value starting with the string value. The format of this must be columnName -> \"string\"." + "example": { + "columnName1": "value", + "columnName2": "value" + }, + "description": "A map of field name to the string to search for, this will look for rows that have a value starting with the string value.", + "additionalProperties": { + "type": "string", + "description": "The value to search for in the column." + } }, "fuzzy": { "type": "object",