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

RFC: Reduce OpenAPI meta complexity #68

@jlalmes

Description

@jlalmes

Initially proposed by @mshd (#55)
Additionally raised by @theobr (https://youtu.be/YAzzvhaRs6M?t=7086)

RFC: Reduce OpenAPI meta complexity

It has been mentioned a few times that the meta required to enable OpenAPI support on a tRPC procedure could be reduced. This RFC proposes setting some sensible defaults (can be overwritten), such that the minimum required meta will be as follows:

{ openapi: { enabled: true } }

Current requirements

  • meta.openapi.enabled: true
  • meta.openapi.method: GET | POST | PUT | PATCH | DELETE
  • meta.openapi.path: string

Sensible defaults

  • meta.openapi.enabled: defaults to false
  • meta.openapi.method: defaults to GET (query) | POST (mutation)
  • meta.openapi.path: defaults to computed value from tRPC procedure where:
    • nested routers = /
    • path = path.replace(/[A-Z]/g, (m) => "-" + m.toLowerCase())

Example (v10)

const postsRouter = t.router({
  getById: t.procedure
    .meta({ openapi: { enabled: true } }),  // { openapi: { enabled: true, method: 'GET', path: '/posts/get-by-id' } }
    .input(z.object({ id: z.string() })),
    .output(postSchema)
    .query(({ input }) => {
       ...
    })
  ...
})

const appRouter = t.router({
  posts: postsRouter,
  ...
})

Concerns

  • The defaults will likely not follow proper RESTful API design patterns in most cases, examples:
    • /posts/get-by-id should be /posts/{id}.
    • update endpoints should be using PUT or PATCH.
  • It is not clear when you will be introducing a breaking changes to your public OpenAPI, example:
    • If you refactor a procedure name, its path will change.

Not fully sold on this change, any thoughts are welcomed (cc @KATT @sachinraja)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions