openapistack / openapi-client-axios

JavaScript client library for consuming OpenAPI-enabled APIs with axios
https://openapistack.co
MIT License
533 stars 67 forks source link

Generate typings for multipart/form-data routes #158

Open khokm opened 1 year ago

khokm commented 1 year ago

Having a schema like this:

openapi: 3.0.3
info:
  title: Swagger Petstore - OpenAPI 3.0
  version: 1.0.11
paths:
  /pet:
    put:
      operationId: updatePet
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                filename:
                  type: array
                  items:
                    type: string
                    format: binary
      responses:
        '200':
          description: Successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  ok:
                    type: boolean

Expected output:

...
export type RequestBody = FormData;
...

Actual output:

export interface RequestBody {
    filename?: string /* binary */[];
}

Suggested solution

Add an CLI option --emitFormData, which will emit export type RequestBody = FormData; when body content type is multipart/form-data.

For environments which aren't support FormData (i.e. Node) it can be fixed by adding --header option, which will insert custom content at the top of generated file (--header='import FormData from "form-data";')

agamm commented 1 month ago

Any update on this?

anttiviljami commented 1 month ago

AFAIK no one is working on this @agamm.

PRs accepted!