openapi-typescript
Advanced tools
Comparing version 6.2.8 to 6.2.9
{ | ||
"name": "openapi-typescript", | ||
"description": "Generate TypeScript types from Swagger OpenAPI specs", | ||
"version": "6.2.8", | ||
"version": "6.2.9", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Drew Powers", |
@@ -258,2 +258,35 @@ <img src="../../docs/public/assets/openapi-ts.svg" alt="openapi-typescript" width="200" height="40" /> | ||
Another common transformation is for file uploads, where the `body` of a request is a `multipart/form-data` with some `Blob` fields. Here's an example schema: | ||
```yaml | ||
Body_file_upload: | ||
type: object; | ||
properties: | ||
file: | ||
type: string; | ||
format: binary; | ||
} | ||
} | ||
} | ||
``` | ||
Use the same pattern to transform the types: | ||
```ts | ||
const types = openapiTS(mySchema, { | ||
transform(schemaObject, metadata): string { | ||
if ("format" in schemaObject && schemaObject.format === "binary") { | ||
return schemaObject.nullable ? "Blob | null" : "Blob"; | ||
} | ||
}, | ||
}); | ||
``` | ||
Resultant diff with correctly-typed `file` property: | ||
```diff | ||
- file?: string; | ||
+ file?: Blob; | ||
``` | ||
Any [Schema Object](https://spec.openapis.org/oas/latest.html#schema-object) present in your schema will be run through this formatter (even remote ones!). Also be sure to check the `metadata` parameter for additional context that may be helpful. | ||
@@ -260,0 +293,0 @@ |
295671
307