Skip to content

Commit

Permalink
fix: add application/json as response content type
Browse files Browse the repository at this point in the history
  • Loading branch information
ootkin committed Jan 28, 2024
1 parent bb34e10 commit 5be0d29
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
8 changes: 8 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,11 @@ src
tsconfig.json
spec.json
jest.config.json
.github
.husky
.idea
.commitlintrc.json
.eslintrc.json
.prettierignore
.prettierrc
.releaserc.json
13 changes: 9 additions & 4 deletions src/core/router/router.types.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -24,8 +24,9 @@ type RouteSchemaResponses = {
interface RouteSchemaResponse {
description: string;
applicationJson?: ZodType;
textPlain?: ZodType<string>;
textHtml?: ZodType<string>;
textPlain?: ZodType;
textHtml?: ZodType;
applicationPdf?: ZodType;
}

export interface RouteSchema
Expand Down Expand Up @@ -63,7 +64,8 @@ export type ResponseBody<S extends RouteSchema> =
? 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']
Expand All @@ -74,6 +76,9 @@ export type ResponseBody<S extends RouteSchema> =
| (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
Expand Down
3 changes: 3 additions & 0 deletions src/generator/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ function generateResponses(
...(rest.textHtml && {
'text/html': { schema: rest.textHtml },
}),
...(rest.applicationPdf && {
'application/pdf': { schema: rest.applicationPdf },
}),
},
};
});
Expand Down

0 comments on commit 5be0d29

Please sign in to comment.