kubb-labs / kubb

The ultimate toolkit for working with APIs.
https://kubb.dev
MIT License
670 stars 54 forks source link

Typescript error on appending data values on FormData #1044

Closed vitorcamachoo closed 3 months ago

vitorcamachoo commented 3 months ago

What version of kubb is running?

"@kubb/cli": "^2.19.6",    
"@kubb/core": "^2.19.6",

What platform is your computer?

MacOS

What version of external packages are you using(@tanstack-query, MSW, React, Vue, ...)

"@kubb/plugin-oas": "2.19.6",     
"@kubb/swagger": "2.19.6",     
"@kubb/swagger-client": "2.19.6",     
"@kubb/swagger-tanstack-query": "2.19.6",     
"@kubb/swagger-ts": "2.19.6",

What steps can reproduce the bug?

When generating the client for an endpoint that supports form data, when appending the values to the FormData, it throws the following Typescript error: Screenshot 2024-06-18 at 16 20 17

Kub configuration:

       pluginTanstackQuery({
            client: { importPath: '../../axios/custom-instance.ts' },
            output: { path: './react-query' },
            framework: 'react',
            infinite: {},
            suspense: {},
            mutate: {
                methods: ['post', 'put', 'patch', 'delete'],
                variablesType: 'mutate'
            }
        }),

How often does this bug happen?

Every time

What is the expected behavior?

It should not throw Typescript errors.

Swagger/OpenAPI file?

  ".../{project_id}/shift_reports/{shift_report_id}/import":
    post:
      summary: Imports data from an XLSX file to a draft shift report
      tags:
      - Shift report imports
      security:
      - bearerAuth: []
      parameters:
      - name: project_id
        in: path
        schema:
          type: string
          format: uuid
        required: true
      - name: shift_report_id
        in: path
        schema:
          type: string
          format: uuid
        required: true
      responses:
        '200':
          description: Shift report updated
          content:
            application/json:
              schema:
                "$ref": "#/components/schemas/ShiftReport"
        '400':
          description: Bad request
        '403':
          description: Not authorised
          content:
            application/json:
              schema:
                "$ref": "#/components/schemas/Error"
        '404':
          description: Not found
        '422':
          description: Update failed
          content:
            application/json:
              schema:
                "$ref": "#/components/schemas/Error"
        '401':
          description: Authentication required
          content:
            application/json:
              schema:
                "$ref": "#/components/schemas/AuthenticationError"
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                sections:
                  type: array
                  items:
                    type: string
                    enum:
                    - contract_forces
                    - down_times
                  description: The shift report sections to import
                xlsx:
                  type: string
                  format: binary
                  description: The XLSX file

Additional information

No response

stijnvanhulle commented 3 months ago

What is the type of data?

vitorcamachoo commented 3 months ago

I am getting FormData as type. Screenshot 2024-06-19 at 15 52 49

stijnvanhulle commented 3 months ago

This feels like a Typescript config issue, see https://dev.to/deciduously/formdata-in-typescript-24cl. Adding the following to your tsconfig.json could help in getting it to understand FormData

"lib": [
  "dom",
  "dom.iterable",
  "esnext"
],
gentrith44belt commented 3 months ago

+1

image

amorinabelt commented 3 months ago

+1