Adding variables to generator.
This commit is contained in:
parent
d7b7900d91
commit
b440657a54
|
@ -3,6 +3,9 @@ const { join } = require("path")
|
||||||
const { writeFileSync } = require("fs")
|
const { writeFileSync } = require("fs")
|
||||||
|
|
||||||
const FILE_NAME = "openapi.json"
|
const FILE_NAME = "openapi.json"
|
||||||
|
const VARIABLES = {
|
||||||
|
prefixV1: "api/public/v1",
|
||||||
|
}
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
definition: {
|
definition: {
|
||||||
|
@ -20,13 +23,18 @@ const options = {
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
format: "json",
|
format: "json",
|
||||||
apis: [join(__dirname, "..", "src", "api", "routes", "public*.js")],
|
apis: [join(__dirname, "..", "src", "api", "routes", "public", "*.js")],
|
||||||
}
|
}
|
||||||
|
|
||||||
const output = swaggerJsdoc(options)
|
const output = swaggerJsdoc(options)
|
||||||
try {
|
try {
|
||||||
const path = join(__dirname, FILE_NAME)
|
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}`)
|
console.log(`Wrote spec to ${path}`)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
|
|
|
@ -11,7 +11,18 @@
|
||||||
"description": "Budibase Cloud API"
|
"description": "Budibase Cloud API"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"paths": {},
|
"paths": {
|
||||||
|
"/api/public/v1/row/search": {
|
||||||
|
"post": {
|
||||||
|
"description": "Search for rows.",
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Returns the rows."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"components": {},
|
"components": {},
|
||||||
"tags": []
|
"tags": []
|
||||||
}
|
}
|
|
@ -8,7 +8,7 @@ const {
|
||||||
const currentApp = require("../middleware/currentapp")
|
const currentApp = require("../middleware/currentapp")
|
||||||
const compress = require("koa-compress")
|
const compress = require("koa-compress")
|
||||||
const zlib = require("zlib")
|
const zlib = require("zlib")
|
||||||
const { mainRoutes, staticRoutes } = require("./routes")
|
const { mainRoutes, staticRoutes, publicRoutes } = require("./routes")
|
||||||
const pkg = require("../../package.json")
|
const pkg = require("../../package.json")
|
||||||
const env = require("../environment")
|
const env = require("../environment")
|
||||||
|
|
||||||
|
@ -82,6 +82,9 @@ for (let route of mainRoutes) {
|
||||||
router.use(route.allowedMethods())
|
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
|
// WARNING - static routes will catch everything else after them this must be last
|
||||||
router.use(staticRoutes.routes())
|
router.use(staticRoutes.routes())
|
||||||
router.use(staticRoutes.allowedMethods())
|
router.use(staticRoutes.allowedMethods())
|
||||||
|
|
|
@ -25,6 +25,7 @@ const metadataRoutes = require("./metadata")
|
||||||
const devRoutes = require("./dev")
|
const devRoutes = require("./dev")
|
||||||
const cloudRoutes = require("./cloud")
|
const cloudRoutes = require("./cloud")
|
||||||
const migrationRoutes = require("./migrations")
|
const migrationRoutes = require("./migrations")
|
||||||
|
const publicRoutes = require("./public")
|
||||||
|
|
||||||
exports.mainRoutes = [
|
exports.mainRoutes = [
|
||||||
authRoutes,
|
authRoutes,
|
||||||
|
@ -58,3 +59,4 @@ exports.mainRoutes = [
|
||||||
]
|
]
|
||||||
|
|
||||||
exports.staticRoutes = staticRoutes
|
exports.staticRoutes = staticRoutes
|
||||||
|
exports.publicRoutes = publicRoutes
|
||||||
|
|
Loading…
Reference in New Issue