Skip to content

Commit

Permalink
Save openapi.json to dist/openapi.json (#286)
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-maj authored Nov 2, 2023
1 parent 5b1fc10 commit d4c2594
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { withExpress } from "./middleware/express";
import { withRequestLogs } from "./middleware/logs";
import { withOpenApi } from "./middleware/open-api";
import { withRoutes } from "./routes";
import { writeOpenApiToFile } from "./utils/openapi";

const __dirname = new URL(".", import.meta.url).pathname;

Expand Down Expand Up @@ -65,10 +66,7 @@ const main = async () => {
},
);

fs.writeFileSync(
"./dist/openapi.json",
JSON.stringify(server.swagger(), undefined, 2),
);
writeOpenApiToFile(server);
};

main();
13 changes: 13 additions & 0 deletions src/server/utils/openapi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { FastifyInstance } from "fastify";
import fs from "fs";

export const writeOpenApiToFile = (server: FastifyInstance) => {
try {
fs.writeFileSync(
"./dist/openapi.json",
JSON.stringify(server.swagger(), undefined, 2),
);
} catch {
// no-op
}
};

0 comments on commit d4c2594

Please sign in to comment.