trpc-openapi icon indicating copy to clipboard operation
trpc-openapi copied to clipboard

Support For t3-app Next js 14 with app router

Open mude-albij opened this issue 1 year ago • 5 comments

Greeting, I am using t3-app with next js 14 and app router. i've setup the trpc-openapi for OpenAPI but can't get the adapters working and is not clarified in the docs.

mude-albij avatar Mar 11 '24 05:03 mude-albij

Forked and Added support for Next.js 14. https://github.com/Vercjames/package-trpc-swagger

Vercjames avatar Mar 25 '24 01:03 Vercjames

I made https://www.npmjs.com/package/next-trpc-openapi

kdy1 avatar Apr 14 '24 15:04 kdy1

Screenshot from 2024-05-01 09-06-44 I don't know why i am getting this error. i am using t3-app with next js 14 and app router.

sutarrohit avatar May 01 '24 03:05 sutarrohit

@sutarrohit pretty sure that error happens because you're using tRPC v11. Either downgrade back to v10 (recommended if you really need the library) or you can do something like this (where you define your router):

const appRouter = router({
  test: testRouter,
  auth: authRouter,
});

const procedures = appRouter._def.procedures;
Object.keys(procedures).forEach((key) => {
  const def = (procedures[key as keyof typeof procedures] as unknown as AnyProcedure)?._def;
  // @ts-expect-error: internal API
  if (def?.meta?.openapi) {
    switch (def.type) {
      case "query":
        // @ts-expect-error: unstable support for tRPC v11
        def.query = true;
        break;
      case "mutation":
        // @ts-expect-error: unstable support for tRPC v11
        def.mutation = true;
        break;
      case "subscription":
        // @ts-expect-error: unstable support for tRPC v11
        def.subscription = true;
        break;
    }
  }
});

export { appRouter };

This is something I've been doing and it seems to work but it is in no way stable and I would not recommend running it in production.

Pridestalkerr avatar May 21 '24 04:05 Pridestalkerr

@Pridestalkerr thanks definitely check for your solution

mude-albij avatar May 21 '24 09:05 mude-albij