Skip to content

Commit

Permalink
fix!: jsonify req.body
Browse files Browse the repository at this point in the history
  • Loading branch information
qwelias committed Oct 26, 2023
1 parent a7dd1b9 commit 636b343
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/typed-fastify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ interface Request<
readonly operationPath: Path;
readonly method: ROptions['method'];
// A payload within a GET request message has no defined semantics; sending a payload body on a GET request might cause some existing implementations to reject the request.
readonly body: ROptions['method'] extends 'GET' ? never : Get<Op['request'], 'body'>;
readonly body: ROptions['method'] extends 'GET' ? never : Jsonify<Get<Op['request'], 'body'>>;
readonly routeOptions: Id<Readonly<ROptions>>;
readonly routerMethod: ROptions['method'];
readonly headers: Get<Op['request'], 'headers'>;
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ export const defaultService: Service<TestSchema> = {
},
'POST /jsonify': (req, reply) => {
const { date } = req.body;
return reply.status(200).send({ date: date.toJSON() });
date.charAt; // ok for string, not ok for Date
return reply.status(200).send({ date: new Date(date).toJSON() });
},
'POST /': (req, reply) => {
if (req.operationPath !== 'POST /') {
Expand Down

0 comments on commit 636b343

Please sign in to comment.