Skip to content

Commit

Permalink
fix: include schema option in route declaration (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
abahernest authored Mar 7, 2024
1 parent 8c904e0 commit 81dd230
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/typed-fastify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ const addSchema = <
/* c8 ignore stop */
const handler = opts.service[path];

const fastifySchema = opts.jsonSchema.fastify;
const routeSchema = fastifySchema[path];
const schema = {
/* c8 ignore start */
...routeSchema?.request?.properties,
response: routeSchema?.response ?? {},
/* c8 ignore stop */
};

switch (typeof handler) {
case 'object':
fastify.route({
Expand All @@ -112,6 +121,7 @@ const addSchema = <
handler: handler.handler,
method: httpMethod,
url: route.join(' '),
schema,
});
break;
case 'function':
Expand All @@ -120,6 +130,7 @@ const addSchema = <
// @ts-ignore
handler: handler,
url: route.join(' '),
schema,
});
break;
/* c8 ignore start */
Expand Down

0 comments on commit 81dd230

Please sign in to comment.