openapi-client-axios
openapi-client-axios copied to clipboard
Generate typings for multipart/form-data routes
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";')