openapi-codegen
openapi-codegen copied to clipboard
feat: Provide types and hook to set the data of a specific operation safely
Example of what this generates for my project
export type QueryDataTypes = {
galApiControllerGetHello: undefined;
configControllerGetOpenApi: undefined;
workspaceControllerFindAll: WorkspaceControllerFindAllResponse;
workspaceControllerFindOne: Schemas.WorkspaceDto;
assetControllerFindAll: AssetControllerFindAllResponse;
assetControllerFindOne: Schemas.HydratedAssetDto;
eventControllerFindAllByTargetId: undefined;
partControllerFindAll: PartControllerFindAllResponse;
partControllerCountAll: undefined;
partControllerFindOne: Schemas.HydratedPartDto;
...
};
Then in my client code I can do the following
const queryOperationDataSetter = useSetQueryOperationData();
const mutation = usePartControllerUpdate();
const handleSubmit = (body) => {
mutation.mutate(
{
pathParams: { id },
body,
},
{
onSuccess: (data) => {
queryOperationDataSetter(
{
operationId: "partControllerFindOne",
path: "/api/v0/parts/{id}",
variables: { pathParams: { id } },
},
data // data must be compatible with the data type of partControllerFindOne
);
},
}
);
}
Thanks for the contribution but I'm sorry, I didn't get the usecase