Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

express example problems out of the box #169

Closed
ffpetrovic opened this issue Oct 18, 2022 · 3 comments
Closed

express example problems out of the box #169

ffpetrovic opened this issue Oct 18, 2022 · 3 comments

Comments

@ffpetrovic
Copy link

on compile there are errors about input schemas
TRPCError: [mutation.auth.register] - Input parser expects a Zod validator

also, the line app.use('/api', createOpenApiExpressMiddleware({ router: appRouter, createContext })); produces this error

TS2345: Argument of type '{ router: CreateRouterInner<RootConfig<{ ctx: Context; meta: OpenApiMeta<TRPCMeta>; errorShape: DefaultErrorShape; transformer: DefaultDataTransformer; }>, { ...; }>; createContext: ({ req, res, }: CreateExpressContextOptions) => Promise<...>; }' is not assignable to parameter of type 'CreateOpenApiExpressMiddlewareOptions<Router<TContext, TContext, OpenApiMeta<TMeta>, any, any, any, DefaultErrorShape>>'.   Type '{ router: CreateRouterInner<RootConfig<{ ctx: Context; meta: OpenApiMeta<TRPCMeta>; errorShape: DefaultErrorShape; transformer: DefaultDataTransformer; }>, { ...; }>; createContext: ({ req, res, }: CreateExpressContextOptions) => Promise<...>; }' is missing the following properties from type 'CreateOpenApiExpressMiddlewareOptions<Router<TContext, TContext, OpenApiMeta<TMeta>, any, any, any, DefaultErrorShape>>': responseMeta, onError, teardown, maxBodySize
@jlalmes
Copy link
Contributor

jlalmes commented Oct 19, 2022

Please ensure you have followed the instructions in the README.md.

@jlalmes jlalmes closed this as completed Oct 19, 2022
@ffpetrovic
Copy link
Author

@jlalmes , thanks for the answer. this "monorepo" works fine, but I don't see any instructions on how to get a working trpc-openapi enabled trpc server working. There are a couple of issues with the main README

export const appRouter = t.router({
  sayHello: t.procedure
    .meta({ openapi: { method: 'GET', path: '/say-hello' } }) /* the property enabled is mandatory here */
    .input(z.object({ name: z.string() }))
    .output(z.object({ greeting: z.string() }))
    .query(({ input }) => {
      return { greeting: `Hello ${input.name}!` };
    }); /* semicolon here breaks the code */
});
const server = http.createServer(createOpenApiHttpHandler({ router: appRouter })); /* it seems that properties `createContext, responseMeta, onError, teardown, maxBodySize` are mandatory as well, even thought that's not mentioned in the documentation */
  1. And finally, when running the code using ts-node-dev --respawn --transpile-only --exit-child ./src/index.ts, this error shows up
ts-node-dev ver. 2.0.0 (using ts-node ver. 10.9.1, typescript ver. 4.8.4)
TRPCError: [query.sayHello] - Input parser expects a Zod validator
at getParameterObjects (project/node_modules/trpc-openapi/src/generator/schema.ts:25:11)
at project/node_modules/trpc-openapi/src/generator/paths.ts:77:42
at forEachOpenApiProcedure (project/node_modules/trpc-openapi/src/utils/procedure.ts:42:7)
at getOpenApiPathsObject (project/node_modules/trpc-openapi/src/generator/paths.ts:35:26)
at generateOpenApiDocument (project/node_modules/trpc-openapi/src/generator/index.ts:34:33)

My package.json

{
  "name": "project",
  "version": "1.0.0",
  "private": true,
  "scripts": {
    "dev": "ts-node-dev --respawn --transpile-only --exit-child ./src/index.ts"
  },
  "dependencies": {
    "@trpc/server": "^10.0.0-proxy-beta.18",
    "trpc-openapi": "^0.7.0",
    "zod": "^3.19.1"
  },
  "devDependencies": {
    "ts-node": "^10.9.1",
    "ts-node-dev": "^2.0.0",
    "typescript": "^4.7.4"
  }
}

@jlalmes
Copy link
Contributor

jlalmes commented Oct 22, 2022

You must install trpc-openapi@alpha for tRPC v10 support. (#143)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants