Fixing up generation of openapi.

This commit is contained in:
mike12345567 2022-02-17 12:40:08 +00:00
parent fb43a971e6
commit d9eabe5404
2 changed files with 54 additions and 27 deletions

View File

@ -2,10 +2,7 @@ const swaggerJsdoc = require("swagger-jsdoc")
const { join } = require("path") const { join } = require("path")
const { writeFileSync } = require("fs") const { writeFileSync } = require("fs")
const FILE_NAME = "openapi.json" const VARIABLES = {}
const VARIABLES = {
prefixV1: "api/public/v1",
}
const options = { const options = {
definition: { definition: {
@ -17,25 +14,41 @@ const options = {
}, },
servers: [ servers: [
{ {
url: "http://budibase.app/api", url: "http://budibase.app/api/public/v1",
description: "Budibase Cloud API", description: "Budibase Cloud API",
}, },
{
url: "http://localhost:10000/api/public/v1",
description: "Budibase self hosted API",
},
], ],
}, },
format: "json", format: "json",
apis: [join(__dirname, "..", "src", "api", "routes", "public", "*.js")], apis: [join(__dirname, "..", "src", "api", "routes", "public", "*.js")],
} }
const output = swaggerJsdoc(options) function writeFile(output, { isJson } = {}) {
try { try {
const path = join(__dirname, FILE_NAME) const filename = isJson ? "openapi.json" : "openapi.yaml"
let spec = JSON.stringify(output, null, 2) const path = join(__dirname, filename)
for (let [key, replacement] of Object.entries(VARIABLES)) { let spec = output
spec = spec.replace(new RegExp(`{${key}}`, "g"), replacement) 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)

View File

@ -7,23 +7,29 @@
}, },
"servers": [ "servers": [
{ {
"url": "http://budibase.app/api", "url": "https://budibase.app/api/public/v1",
"description": "Budibase Cloud API" "description": "Budibase Cloud API"
},
{
"url": "http://localhost:10000/api/public/v1",
"description": "Budibase self hosted API"
} }
], ],
"paths": { "paths": {
"/api/public/v1/row/{tableId}/search": { "/row/{tableId}/search": {
"post": { "post": {
"summary": "Allows searching for rows within a table.", "summary": "Allows searching for rows within a table.",
"parameters": { "parameters": [
"name": "tableId", {
"in": "path", "in": "path",
"required": true, "name": "tableId",
"description": "The ID of the table which contains the rows which are being searched for.", "required": true,
"schema": { "description": "The ID of the table which contains the rows which are being searched for.",
"type": "string" "schema": {
"type": "string"
}
} }
}, ],
"requestBody": { "requestBody": {
"required": true, "required": true,
"content": { "content": {
@ -33,7 +39,15 @@
"properties": { "properties": {
"string": { "string": {
"type": "object", "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": { "fuzzy": {
"type": "object", "type": "object",