openapi-codegen icon indicating copy to clipboard operation
openapi-codegen copied to clipboard

feat: Provide types and hook to set the data of a specific operation safely

Open Cellule opened this issue 1 year ago • 1 comments

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 
          );
        },
      }
    );
  }

Cellule avatar Mar 15 '24 19:03 Cellule

Thanks for the contribution but I'm sorry, I didn't get the usecase

fabien0102 avatar Mar 27 '24 10:03 fabien0102