Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FormData/RequestBody not handled correctly with the standalone clients #721

Closed
gergan opened this issue Jun 24, 2024 · 0 comments · Fixed by #746
Closed

FormData/RequestBody not handled correctly with the standalone clients #721

gergan opened this issue Jun 24, 2024 · 0 comments · Fixed by #746
Labels
bug 🔥 Something isn't working

Comments

@gergan
Copy link
Contributor

gergan commented Jun 24, 2024

Description

So we have a Post with the following format:

      "post": {
        "operationId": "archiveDocument",
        ...
        "requestBody": {
          "content": {
            "multipart/form-data": {
              "schema": {
                "$ref": "#/components/schemas/DocumentArchiveRequestV1"
              },
              "encoding": {
                "customerIndexes": {
                  "contentType": "application/json"
                }
              }
            }
          },
          "required": true
        },
      }

and

      "DocumentArchiveRequestV1": {
        "properties": {
          "customerIndexes": {
            "$ref": "#/components/schemas/CustomerIndexesV1"
          },
          "file": {
            "format": "binary",
            "type": "string"
          }
        },
        "required": [
          "file"
        ],
        "type": "object"
      },

The created type is missing the body:

export type ArchiveDocumentData = {
  headers: {
    'x-tenant-id': string;
  };
  path: {
    docId: string;
  };
};
export type DocumentArchiveRequestV1 = {
  customerIndexes?: CustomerIndexesV1;
  file: Blob | File;
};

I'm using "@hey-api/client-fetch" and "@hey-api/openapi-ts" built from the main branch.

So the problem seems to be that the standalone-client does not have formData fields anymore and

transforms the requestBody in formData if the requestBody type is either 'application/x-www-form-urlencoded' or 'multipart/form-data'. After that in the getOperationRequestBody-function is used and the requestBody is added to the parameters and the parametersBody property is set on the operation. After that in
const bodyParameter = operation.parameters
the parameters are only filtered on body and as such the formData types are ignored and the body is not set at all.
I have a PullRequest, which will fix the problem, which I have - requestBody transformed in formData and consequently missing from the types, just by using the parametersBody property instead of filtering again the parameters.
This probably will miss real formData parameters, which in this case still will not be handled correctly.

OpenAPI specification (optional)

No response

Configuration

No response

System information (optional)

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🔥 Something isn't working
Projects
None yet
1 participant