Skip to content

Support multiple OpenAPI definitions in one procedure #513

Description

@dcramer

.route is supported to overload a previous called procedure, but what would be really amazing is the ability to define multiple openapi endpoints per-procedure. This simplifies some code reusability, as for a real world example, I have a comments endpoint that I need three different variations of (two for ergonics, and one for administrative "query all" purposes):

export default procedure
  .route({
    method: "GET",
    path: "/comments",
    tags: ["admin"],
  })
  .route({
    method: "GET",
    path: "/tastings/:tasting/comments",
    tags: ["tastings"],
  })
  .route({ method: "GET", path: "/users/:user/comments", tags: ["users"] })
  .input(
    z.object({
      user: z.union([z.literal("me"), z.coerce.number()]).optional(),
      tasting: z.coerce.number().optional(),
      cursor: z.coerce.number().gte(1).default(1),
      limit: z.coerce.number().gte(1).lte(100).default(100),
    }),
  )
  .output(
    z.object({
      results: z.array(CommentSchema),
      rel: CursorSchema,
    }),
  )
  .handler(async function ({ input, context, errors });

I have often built procedures like this, and then you end up exporting them, reimporting them, defining a new duplicate endpoint that only calls e.g. one of the params. oRPC is so close to avoiding any of that boilerplate, and in this case its literally just metadata.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions