From 5be0d2959d630e7447abddd8c166cd9d00ff5b39 Mon Sep 17 00:00:00 2001 From: Skullflow Date: Sun, 28 Jan 2024 12:06:30 +0100 Subject: [PATCH] fix: add application/json as response content type --- .npmignore | 8 ++++++++ src/core/router/router.types.ts | 13 +++++++++---- src/generator/generator.ts | 3 +++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/.npmignore b/.npmignore index 821a900..305fcca 100644 --- a/.npmignore +++ b/.npmignore @@ -2,3 +2,11 @@ src tsconfig.json spec.json jest.config.json +.github +.husky +.idea +.commitlintrc.json +.eslintrc.json +.prettierignore +.prettierrc +.releaserc.json diff --git a/src/core/router/router.types.ts b/src/core/router/router.types.ts index 2c5de53..389c9f3 100644 --- a/src/core/router/router.types.ts +++ b/src/core/router/router.types.ts @@ -1,7 +1,7 @@ import * as z from 'zod'; import * as core from 'express-serve-static-core'; import { ZodType } from '../../zod'; -import { NextFunction, RequestHandler } from 'express'; +import { RequestHandler } from 'express'; import { oas30, oas31 } from 'zod-openapi/lib-types/openapi3-ts/dist'; interface RequestContentType { @@ -24,8 +24,9 @@ type RouteSchemaResponses = { interface RouteSchemaResponse { description: string; applicationJson?: ZodType; - textPlain?: ZodType; - textHtml?: ZodType; + textPlain?: ZodType; + textHtml?: ZodType; + applicationPdf?: ZodType; } export interface RouteSchema @@ -63,7 +64,8 @@ export type ResponseBody = ? S['responses'][keyof S['responses']][ | 'applicationJson' | 'textPlain' - | 'textHtml'] extends ZodType + | 'textHtml' + | 'applicationPdf'] extends ZodType ? z.infer< | (S['responses'][keyof S['responses']]['applicationJson'] extends ZodType ? S['responses'][keyof S['responses']]['applicationJson'] @@ -74,6 +76,9 @@ export type ResponseBody = | (S['responses'][keyof S['responses']]['textHtml'] extends ZodType ? S['responses'][keyof S['responses']]['textHtml'] : typeof zodUndefined) + | (S['responses'][keyof S['responses']]['applicationPdf'] extends ZodType + ? S['responses'][keyof S['responses']]['applicationPdf'] + : typeof zodUndefined) > : unknown : unknown diff --git a/src/generator/generator.ts b/src/generator/generator.ts index a967a95..81def39 100644 --- a/src/generator/generator.ts +++ b/src/generator/generator.ts @@ -50,6 +50,9 @@ function generateResponses( ...(rest.textHtml && { 'text/html': { schema: rest.textHtml }, }), + ...(rest.applicationPdf && { + 'application/pdf': { schema: rest.applicationPdf }, + }), }, }; });