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

maxBodySize not working?

Open krisgrm opened this issue 1 year ago • 1 comments

Hey i am trying to use maxBodySize to increase upload limits to 10mb.. but for some reason the property is not working, actually there are 2 issues that I am facing:

when i specify the property for example:

const handler = async (req: NextApiRequest, res: NextApiResponse) => {
  // Setup CORS
  await cors(req, res);

  // Handle incoming OpenAPI requests
  return createOpenApiNextHandler({
    maxBodySize: 100000000000000,
    router: appRouter,
    createContext,
    onError: ({ path, error }) => {
      logger.error(`❌ tRPC failed on ${path} with error: ${error}`);
      logger.error("ℹ️ Cause: ", error.cause);
    },
  })(req, res);
};

I get this typescript error:

TS2345: Argument of type '{ maxBodySize: number; router: CreateRouterInner<RootConfig<{ ctx: Context; meta: OpenApiMeta; errorShape: DefaultErrorShape; transformer: { stringify: (object: any) => string; ... 6 more ...; allowErrorProps: (...props: string[]) => void; }; }>, { ...; }>; createContext: (opts: CreateNextContextOptions) => { ...; }...' is not assignable to parameter of type 'CreateOpenApiNextHandlerOptions<Router<RouterDef<RootConfig<{ ctx: Context; meta: OpenApiMeta; errorShape: DefaultErrorShape; transformer: { stringify: (object: any) => string; parse: <T = unknown>(string: string) => T; ... 5 more ...; allowErrorProps: (...props: string[]) => void; }; }>, { ...; }, { ...; }>> & { .....'.   Object literal may only specify known properties, and 'maxBodySize' does not exist in type 'CreateOpenApiNextHandlerOptions<Router<RouterDef<RootConfig<{ ctx: Context; meta: OpenApiMeta; errorShape: DefaultErrorShape; transformer: { stringify: (object: any) => string; parse: <T = unknown>(string: string) => T; ... 5 more ...; allowErrorProps: (...props: string[]) => void; }; }>, { ...; }, { ...; }>> & { .....'

further more seems like the property is being ignored by the trpc / openapi plugin as well

krisgrm avatar Jul 07 '23 09:07 krisgrm

was problem on my side actually... needed to specify the config object on the handler

export const config = {
  api: {
    bodyParser: {
      sizeLimit: "10mb", // Set desired value here
    },
  },
};

krisgrm avatar Jul 13 '23 08:07 krisgrm