Fixing up generation of openapi.

This commit is contained in:
mike12345567 2022-02-17 12:40:08 +00:00
parent 4ec9794eb4
commit 5f94ed7fe0
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 { 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)
function writeFile(output, { isJson } = {}) {
try {
const path = join(__dirname, FILE_NAME)
let spec = JSON.stringify(output, null, 2)
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)
}
// 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": [
{
"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",
"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",