Fixing up generation of openapi.
This commit is contained in:
parent
fb43a971e6
commit
d9eabe5404
|
@ -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)
|
||||||
|
let spec = output
|
||||||
|
if (isJson) {
|
||||||
|
spec = JSON.stringify(output, null, 2)
|
||||||
|
}
|
||||||
|
// input the static variables
|
||||||
for (let [key, replacement] of Object.entries(VARIABLES)) {
|
for (let [key, replacement] of Object.entries(VARIABLES)) {
|
||||||
spec = spec.replace(new RegExp(`{${key}}`, "g"), replacement)
|
spec = spec.replace(new RegExp(`{${key}}`, "g"), replacement)
|
||||||
}
|
}
|
||||||
// input the static variables
|
|
||||||
writeFileSync(path, spec)
|
writeFileSync(path, spec)
|
||||||
console.log(`Wrote spec to ${path}`)
|
console.log(`Wrote spec to ${path}`)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const outputJSON = swaggerJsdoc(options)
|
||||||
|
options.format = "yaml"
|
||||||
|
const outputYAML = swaggerJsdoc(options)
|
||||||
|
console.log(outputYAML)
|
||||||
|
writeFile(outputJSON)
|
||||||
|
writeFile(outputYAML)
|
||||||
|
|
|
@ -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",
|
||||||
|
"name": "tableId",
|
||||||
"required": true,
|
"required": true,
|
||||||
"description": "The ID of the table which contains the rows which are being searched for.",
|
"description": "The ID of the table which contains the rows which are being searched for.",
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "string"
|
"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",
|
||||||
|
|
Loading…
Reference in New Issue