1
0
Fork 0
mirror of synced 2024-07-20 13:45:56 +12:00

Adding variables to generator.

This commit is contained in:
mike12345567 2022-02-16 18:23:38 +00:00
parent 6dc0dde9d7
commit 2bc2669ed7
4 changed files with 28 additions and 4 deletions

View file

@ -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)

View file

@ -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": []
}

View file

@ -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())

View file

@ -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