import { RedocModule, RedocOptions } from "@juicyllama/nestjs-redoc"; import { INestApplication } from "@nestjs/common"; import { DocumentBuilder, SwaggerModule } from "@nestjs/swagger"; import { addExperiences } from "@/cvdocs/experience"; import { addSkills } from "@/cvdocs/skills"; import { addIntro } from "@/cvdocs/intro"; const apiDocument = ( options: { title: string; description: string; version: `${number}.${number}.${number}${string}` | `${number}.${number}${string}` | `${number}${string}`; contact: { name: string; email: string; }; }, redocOptions: RedocOptions ) => { redocOptions.title = options.title; return new DocumentBuilder() .setTitle(options.title) .setDescription(options.description) .setVersion(options.version) .setContact(options.contact.name, null, options.contact.email) .addServer("http://localhost:3000/"); }; const initDocs = async ({ app, config, redocOptions, swaggerUIPath, redocPath, }: { app: INestApplication; config: DocumentBuilder; redocOptions: RedocOptions; swaggerUIPath?: string; redocPath?: string; }): Promise => { const document = SwaggerModule.createDocument(app, config.build(), { operationIdFactory: (controllerKey: string, methodKey: string) => `${methodKey[0].toUpperCase()}${methodKey.substring(1)}`, }); if (swaggerUIPath) { SwaggerModule.setup(swaggerUIPath, app, document); } if (redocPath) { await RedocModule.setup(redocPath, app, document, redocOptions); } }; export default async (app: INestApplication) => { const redocOptions: RedocOptions = { logo: { url: "https://picsum.photos/256/128", altText: "Thom Werring", }, sortPropsAlphabetically: true, hideDownloadButton: false, tagGroups: [], }; const config = apiDocument( { title: "Thom Werring - CV", description: "Westerstraat 83
1521ZB, Wormerveer
+31 6 37 65 08 49", version: "1.0.0a", contact: { name: "Thom Werring", email: "cv@t-werring.nl", }, }, redocOptions ); addIntro(config, redocOptions); addSkills(config, 5, redocOptions); addExperiences(config, 3, redocOptions); await initDocs({ app, config, redocOptions, swaggerUIPath: "/api", redocPath: "/docs", }); };