Giter Site home page Giter Site logo

Comments (3)

mrlubos avatar mrlubos commented on September 22, 2024

Thanks for reporting @PaulStryck, will check

from openapi-ts.

mrlubos avatar mrlubos commented on September 22, 2024

Hey @PaulStryck, mind adding what's the expected result here?

from openapi-ts.

PaulStryck avatar PaulStryck commented on September 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.