-
-
Notifications
You must be signed in to change notification settings - Fork 139
OpenAPI Compatible Parameter Serialization / Notation #1517
Description
Describe the feature
Good day!
My usecase for orpc is to port an existing API and use it for end2end type safety and documentation. One of the biggest painpoints so far is that the bracket notation is not compatible with my current API and there is not really any alternative way of notating my path or query string which is compatible with the inputSchema.
OpenAPI offers many styles in which a string in a path or query can be serialized / deserialized.
One idea would be to introduce an additional inputNotation or inputStyle parameter in the Route interface:
oc.route({ method: 'GET', path: '/planets', inputNotation: 'pipeDelimited' })
.input(
z.object({
query: z.object({
ids: z.array(z.coerce.number())
}),
}),
)With the contract above an url like /planets?ids=1|2|3 would be valid. This could be done with all of the possible styles the openapi spec offers. The new inputNotation parameter could also be a complex object like inputNotation: { style: 'pipeDelimited', explode: false }.
In theory every query parameter could use its own notation, so it would also be desireable to make the notation configruable for each query parameter or path parameter separately. A possible API could look like:
oc.route({ method: 'GET', path: '/planets/{names}' })
.input(
z.object({
params: z.object({
names: z.array(z.string())
}),
query: z.object({
moons: z.array(z.string())
}),
}),
// new parameter object which defines notations / styles
{
params: {
names: { style: 'label' },
},
query: {
moons: { style: 'matrix', explode: true },
}
}
)Here the shape of the second parameter of the .input() function could be inferred from the passed standardSchema and the each field could be a inputNotation object which decides how string are interpreted.
Those are just thoughts of how to achieve the desired goal. oRPC could obviously also add its own notation here to make the whole thing backwards compatible, but I would suggest this feature to be someting for v2.
Additional information
- Would you be willing to help implement this feature?