Comments (3)
Thanks for reporting @PaulStryck, will check
from openapi-ts.
Hey @PaulStryck, mind adding what's the expected result here?
from openapi-ts.
Thanks for looking into it.
I would expect to get (Blob | File)
type annotations when using OpenAPI v3 specs.
Currently these type annotations are produced:
export type GetFooResponse = (Blob | File);
export type GetBarResponse = (Blob | File);
when using the following OpenAPI spec:
{
"openapi": "3.1.0",
"info": {
"version": "1.0.0",
"title": "Test",
"license": {
"name": "Apache 2.0",
"identifier": "Apache-2.0"
}
},
"servers": [
{
"url": "http://localhost/"
}
],
"paths": {
"/foo": {
"get": {
"responses": {
200: {
"description": "get foo",
"content": {
"image/png": {
"schema": {
"type": "file"
}
}
}
}
}
}
},
"/bar": {
"get": {
"responses": {
200: {
"description": "get bar",
"content": {
"application/zip": {
"schema": {
"type": "file"
}
}
}
}
}
}
}
}
}
"type": "file"
is only allowed in OpenAPI v2.
The correct OpenAPI v3 spec produces:
export type GetFooResponse = string;
export type GetBarResponse = unknown;
with the following OpenAPI spec:
{
"openapi": "3.1.0",
"info": {
"version": "1.0.0",
"title": "Test",
"license": {
"name": "Apache 2.0",
"identifier": "Apache-2.0"
}
},
"servers": [
{
"url": "http://localhost"
}
],
"paths": {
"/foo": {
"get": {
"responses": {
200: {
"description": "get foo",
"content": {
"image/png": {
"schema": {
- "type": "file
+ "type": "string",
+ "contentMediaType": "image/png",
+ "contentEncoding": "base64"
}
}
}
}
}
}
},
"/bar": {
"get": {
"responses": {
200: {
"description": "get bar",
"content": {
"application/zip": {
- "schema": {
- "type": "file"
- }
}
}
}
}
}
}
}
}
Any response object with an omitted schema object for a "file like" mime type should generate a (Blob|File)
type and set the Blob.type property accordingly, when parsing the response.
Any response with a populated schema object for a "file like" mime type should either generate a string
type, or a (Blob|File)
type and parse the base64 string to a Blob object directly in the request method. The latter is possibly a question of personal taste. I'd prefer parsing to Blob.
from openapi-ts.
Related Issues (20)
- Using wrong client config parameter leads to undefined HttpRequestConstructor HOT 3
- BaseURL not being set when using client.setConfig HOT 1
- Tanstack Query Incorrect onError Types HOT 4
- Improved types for Vue Tanstack Query HOT 1
- Concurrent createClient calls resolve to same input HOT 1
- fetch-api mistakenly serializes FormData as application/json instead of multipart/form-data
- Parameter in path with multiple dollar sign gets replaced to a single dollar sign HOT 3
- Improper handling of array query types HOT 6
- Having trouble setting up client with next js and fetch api HOT 3
- Properties are declared `?` when they're not in the openapi spec HOT 3
- Type of error object changed HOT 2
- Cannot specify responseTransformer when request options include headers HOT 1
- Generating code based on multiple OpenAPI schemas HOT 2
- Automatic addition of the suffix `Schema` to the object names in `schemas.gen.ts` causes conflicts with `types.gen.ts` HOT 3
- Intergrate with `msw` mock service HOT 1
- Improve changelog
- Test bundle-require
- Angular client
- Posibility to add no client HOT 8
- Big int for Format int64 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from openapi-ts.