Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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);

Expand Down
22 changes: 22 additions & 0 deletions src/routes/docs.mjs
Original file line number Diff line number Diff line change
@@ -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;
31 changes: 29 additions & 2 deletions swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -343,5 +371,4 @@ components:
type: string
timestamp:
type: string