2025-01-13 23:18:10 +02:00
|
|
|
import type { Router } from "express";
|
2024-04-07 18:18:26 +03:00
|
|
|
|
2024-07-18 21:37:45 +03:00
|
|
|
import fs from "fs";
|
|
|
|
import path from "path";
|
2022-01-07 23:06:04 +01:00
|
|
|
|
2024-07-19 00:18:35 +03:00
|
|
|
import { fileURLToPath } from "url";
|
2025-01-09 18:07:02 +02:00
|
|
|
const specPath = path.join(path.dirname(fileURLToPath(import.meta.url)), "etapi.openapi.yaml");
|
2024-04-16 21:10:39 +03:00
|
|
|
let spec: string | null = null;
|
2022-01-07 23:06:04 +01:00
|
|
|
|
2024-04-07 18:18:26 +03:00
|
|
|
function register(router: Router) {
|
2025-01-09 18:07:02 +02:00
|
|
|
router.get("/etapi/etapi.openapi.yaml", (req, res, next) => {
|
2022-01-07 23:06:04 +01:00
|
|
|
if (!spec) {
|
2025-01-09 18:07:02 +02:00
|
|
|
spec = fs.readFileSync(specPath, "utf8");
|
2022-01-07 23:06:04 +01:00
|
|
|
}
|
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
res.header("Content-Type", "text/plain"); // so that it displays in browser
|
2022-01-07 23:06:04 +01:00
|
|
|
res.status(200).send(spec);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-07-18 21:42:44 +03:00
|
|
|
export default {
|
2022-01-07 23:06:04 +01:00
|
|
|
register
|
|
|
|
};
|