This repository was archived by the owner on Nov 19, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 195
This repository was archived by the owner on Nov 19, 2024. It is now read-only.
RFC: Reduce OpenAPI meta
complexity #68
Copy link
Copy link
Closed
Labels
Description
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 tofalse
meta.openapi.method
: defaults toGET
(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())
- nested routers =
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
orPATCH
.
- 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.
- If you refactor a procedure name, its
Not fully sold on this change, any thoughts are welcomed (cc @KATT @sachinraja)