Replies: 2 comments 1 reply
-
I understand that you want a way to customize the OpenAPI spec based on middleware. However, I believe we can achieve this in a simpler way by using middleware references. Here’s a draft implementation: const openAPIGenerator = new OpenAPIGenerator({
a_hook_that_allows_you_to_override_specs: (procedure, oldSpec) => {
if (procedure['~orpc'].middlewares.includes(requireAuthMiddleware)) {
return modifiedSpec;
}
return oldSpec;
}
}); Additionally, I think we should stick with the current meta behavior. Meta is useful when you want to build on top of oRPC or when you need reusable logic, such as: const _base = os.$meta<{ requireAuth?: boolean }>({});
const base = _base.use(({ next, procedure }) => {
if (procedure['~orpc'].meta.requireAuth) {
// Perform authentication check here
}
return next();
}); To define |
Beta Was this translation helpful? Give feedback.
-
I think we find the best way now for customize openapi spec base on middleware or error-map (if you use contract-first) const middlewareOrErrorMapItem = oo.spec(middlewareOrErrorMapItem_, { // or a callback allow you override specs
security: [
{
'api-key': [],
},
],
})
// middlewareOrErrorMapItem can use directly as middleware or error map item |
Beta Was this translation helpful? Give feedback.
-
These are some features for decorated middleware that I feel are missing right now.
$meta
/meta
combining meta objects (similarly to context returned from middleware) instead of replacing it entirely. Alternatively, the ability to pass a function to transform the existing metadata. A key use-case I'd like this for is the ability to make all procedures that.use
a decorated middleware have some metadata related to that middleware (e.g. a permissions-checking middleware that adds metadata that describe the required permissions, which I can then use to modify my OpenAPI document to document permissions automatically)..errors
and.$meta
decorated middleware, before using.concat
, so that I can then.concat
another middleware that uses/adds the new errors/metadata.Code example of what I'm hoping will be possible
Let me know what you think!
Beta Was this translation helpful? Give feedback.
All reactions