cal.pub0.org/pages/api/docs.ts

40 lines
1.1 KiB
TypeScript
Raw Normal View History

import pjson from "@/package.json";
2022-04-30 17:46:04 +00:00
import modifyRes from "modify-response-middleware";
import { use } from "next-api-middleware";
import { withSwagger } from "next-swagger-doc";
2022-04-30 17:46:04 +00:00
import { NextApiRequest, NextApiResponse } from "next/types";
const swaggerHandler = withSwagger({
definition: {
openapi: "3.0.0",
2022-04-26 19:56:59 +00:00
servers: [
{ url: "https://api.cal.com/v1" },
{ url: "https://api.cal.dev/v1" },
{ url: "http://localhost:3002/v1" },
],
externalDocs: {
url: "https://docs.cal.com",
description: "Find more info at our main docs: https://docs.cal.com/",
},
info: {
title: `${pjson.name}: ${pjson.description}`,
version: pjson.version,
},
components: {
securitySchemes: { ApiKeyAuth: { type: "apiKey", in: "query", name: "apiKey" } },
},
security: [{ ApiKeyAuth: [] }],
},
apiFolder: "pages/api",
});
2022-04-30 17:46:04 +00:00
export default use(
modifyRes((content: string, _req: NextApiRequest, _res: NextApiResponse) => {
if (content) {
const parsed = JSON.parse(content);
delete parsed.channels;
return Buffer.from(JSON.stringify(parsed));
}
})
)(swaggerHandler());