Skip to content

Commit

Permalink
Replace decorateRequest by onRequest hook
Browse files Browse the repository at this point in the history
  • Loading branch information
andreffvalente authored and satazor committed Aug 6, 2024
1 parent b1b4727 commit b0d6bae
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,17 @@ const plugin = async (fastify, options) => {
route: createRoute(fastify, routes)
});

// Decorate request.
fastify.decorateRequest(DECORATOR_NAME, {
operation: {},
security: {},
securityReport: []
// Avoid decorating the request with reference types.
// Any mutation will impact all requests.
fastify.decorateRequest(DECORATOR_NAME, null);

// Instead, decorate each incoming request.
fastify.addHook('onRequest', async request => {
request[DECORATOR_NAME] = {
operation: {},
security: {},
securityReport: []
};
});
};

Expand Down

0 comments on commit b0d6bae

Please sign in to comment.