Open alex-streza opened 6 months ago
Facing the same issue. Any update on this?
Forked and Added support for Next.js 14. https://github.com/Vercjames/package-trpc-swagger
@jlalmes / @alex-streza, i faced the same issue when i'm trying to use this via nest application. the issue lies in procedure.ts:getProcedureType
method. the latest @trpc/server
is emitting procedure definition as below:
[AsyncFunction: procedure] {
_def: {
procedure: true,
inputs: [],
middlewares: [ [AsyncFunction: resolveMiddleware] ],
meta: { openapi: [Object] },
type: 'query',
resolver: [Function (anonymous)]
}
}
currently this is the method implementation:
const getProcedureType = (procedure: OpenApiProcedure): ProcedureType => {
if (procedure._def.query) return 'query';
if (procedure._def.mutation) return 'mutation';
if (procedure._def.subscription) return 'subscription';
throw new Error('Unknown procedure type');
};
changing this to below:
const getProcedureType = (procedure: OpenApiProcedure): ProcedureType => {
if (procedure._def.query) return 'query';
if (procedure._def.mutation) return 'mutation';
if (procedure._def.subscription) return 'subscription';
if (procedure._def.type) return procedure._def.type; // return type if it exists on _def without breaking existing functionality
throw new Error('Unknown procedure type');
};
may solve this issue.
This is the basic stackblitz app to reproduce this.
PS: i'm using @trpc/server@next version.
I'm running a project using create-t3-turbo and wanted to add OpenAPI support to trpc routers but I keep getting this error, any help is much appreciated, kinda counting on getting OpenAPI support this way.
I went in the procedure.js file to debug and saw that
procedure._def
doesn't seem to exist in my trpc: next version (11.0.0-next-alpha.149+11361b82d)I'm not 100% certain if it's because of this but I'm also using trpc in app router and trpc-openapi in pages/api
pages/api/[...trpc].ts
trpc.ts