hey-api / openapi-ts

✨ Turn your OpenAPI specification into a beautiful TypeScript client
https://heyapi.vercel.app
MIT License
651 stars 47 forks source link

Error types no longer strongly typed #618

Closed bruceharrison1984 closed 1 month ago

bruceharrison1984 commented 1 month ago

Description

After upgrading to the newer @hey-api/client-fetch, the data object is correctly typed, but the error type is now untyped (previously it was correctly typed)

image

Spec


...
"schema":{
      "ErrorPayload": {
        "type": "object",
        "properties": {
          "message": { "type": "string" },
          "detail": { "type": "string" },
          "status": { "type": "number" },
          "stack": { "type": "string" }
        },
        "required": ["message", "status"]
      },
...

"paths": {
    "/resources/users": {
      "get": {
        "tags": ["Users"],
        "security": [{ "Bearer": [] }],
        "parameters": [
          {
            "schema": { "type": "number" },
            "required": true,
            "name": "limit",
            "in": "query"
          },
          {
            "schema": { "type": "number" },
            "required": true,
            "name": "offset",
            "in": "query"
          }
        ],
        "responses": {
          "200": {
            "description": "array of Users",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": { "$ref": "#/components/schemas/UsersResult" }
                }
              }
            }
          },
          "4XX": {
            "description": "common error response",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorPayload" }
              }
            }
          }
        }
      },
...

This is easy enough to work-around by forcibly casting the objects, but I presume this is an oversight.

mrlubos commented 1 month ago

I am actually surprised this worked before the standalone client. Either way, I think it's because of the 4XX status code. I am adding support for such codes in the next release, please let me know if that fixes it for you!

kostia1st commented 1 month ago

I am adding support for such codes in the next release

Just a note, schemas comprised of numbers only also have issues - they don't generate into compilable code

Code_Qz8prvGWAM Code_u2Nu9ZFZE5

mrlubos commented 1 month ago

@kostia1st that sounds like a separate issue no?

kostia1st commented 1 month ago

@mrlubos yep, just created one