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