budibase/packages/server/specs/generate.js

42 lines
1.0 KiB
JavaScript
Raw Normal View History

2022-02-16 17:42:50 +01:00
const swaggerJsdoc = require("swagger-jsdoc")
const { join } = require("path")
const { writeFileSync } = require("fs")
const FILE_NAME = "openapi.json"
2022-02-16 19:23:38 +01:00
const VARIABLES = {
prefixV1: "api/public/v1",
}
2022-02-16 17:42:50 +01:00
const options = {
definition: {
openapi: "3.0.0",
info: {
title: "Budibase API",
description: "The public API for Budibase apps and its services.",
version: "1.0.0",
},
servers: [
{
url: "http://budibase.app/api",
description: "Budibase Cloud API",
},
],
},
format: "json",
2022-02-16 19:23:38 +01:00
apis: [join(__dirname, "..", "src", "api", "routes", "public", "*.js")],
2022-02-16 17:42:50 +01:00
}
const output = swaggerJsdoc(options)
try {
const path = join(__dirname, FILE_NAME)
2022-02-16 19:23:38 +01:00
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)
2022-02-16 17:42:50 +01:00
console.log(`Wrote spec to ${path}`)
} catch (err) {
console.error(err)
}