diff --git a/src/app.mjs b/src/app.mjs index 8b60a2f..fc3a8c6 100644 --- a/src/app.mjs +++ b/src/app.mjs @@ -14,6 +14,7 @@ import bakeRouter from "./routes/bake.mjs"; import magicRouter from "./routes/magic.mjs"; import healthRouter from "./routes/health.mjs"; import batchBakeRouter from "./routes/batchBake.mjs"; +import docsRouter from "./routes/docs.mjs"; const isProduction = process.env.NODE_ENV === "production"; @@ -48,6 +49,7 @@ const swaggerFile = fs.readFileSync("./swagger.yml", "utf8"); app.use("/health", healthRouter); app.use("/bake", bakeRouter); app.use("/magic", magicRouter); +app.use("/docs", docsRouter); // Batch routes app.use("/batch/bake", batchBakeRouter); diff --git a/src/routes/docs.mjs b/src/routes/docs.mjs new file mode 100644 index 0000000..2d7e429 --- /dev/null +++ b/src/routes/docs.mjs @@ -0,0 +1,22 @@ +import { Router } from "express"; +const router = Router(); +import { help } from "cyberchef"; + +/** + * docsPost - Returns documentation for a specified operation + */ +router.post("/", async function docsPost(req, res, next) { + try { + const { operation } = req.body; + const docs = help(operation); + if (!docs) { + res.send(`{No documentation for ${operation} found`); + throw new Error(`No documentation found for operation: ${operation}`); + } + res.send(docs); + } catch (error) { + next(error); + } +}); + +export default router; diff --git a/swagger.yml b/swagger.yml index fb8e871..5e0c9f7 100644 --- a/swagger.yml +++ b/swagger.yml @@ -128,6 +128,34 @@ paths: - 123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz - false useful: false + /docs: + post: + summary: Gets documentation for a specified operation + tags: + - Documentation + description: > + Given the name of an operation, returns a markdown-formatted string containing the operation's documentation. + The endpoint does not return documentation for any operations that may be called by the specified operation (for example, operations called by a "Magic" operation). + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + operation: + type: string + required: + - operation + responses: + '200': + description: Successful response + content: + text/plain: + schema: + type: string + '400': + description: Bad request /batch/bake: post: summary: Bakes a batch of data with a recipe @@ -343,5 +371,4 @@ components: type: string timestamp: type: string - - \ No newline at end of file +