redux-toolkit
redux-toolkit copied to clipboard
RTKQ Codegen: Multiple API responses (200, 404, etc.)
I'm using rtk-query-codegen-api to generate from an OpenAPI spec. The endpoints have multiple responses (200, 404, etc.) with different values. Here's a simplified example:
/user/city:
post:
operationId: setCity
responses:
'200':
content:
application/json:
schema:
type: string
'404':
content:
application/json:
schema:
type: object
properties:
error:
type: string
friendlyMessage:
type: string
The codegen then produces a single type for the response:
export type EnterBonusCodeApiResponse = /** status 200 OK */ string;
Should it also be producing the 404 response? In the case of an error I'd like to be able to display friendlyMessage, but there are no generated types containing this property. It's contained inside the error object that comes back from the useSetCity() hook, but the types are missing friendlyMessage so I can't get it out safely.
Any suggestions on how to best implement this? I'm hoping for full type safety for multiple response types.
Any update on this?
Also ran into this issue now. The type itself does get generated but does not get linked to the mutation in any way. Is there a way to add this manually using enhanceEndpoints maybe?
Having the same issue. How do you generate error statuses 4xx 5xx ? only 2xx are generated