openapi-zod-client icon indicating copy to clipboard operation
openapi-zod-client copied to clipboard

$ref in response results in z.void()

Open ferenckv opened this issue 1 year ago • 6 comments

Using this operation

post:
  summary: Dummy post
  description: Dummy post
  tags:
    - dummy
  security:
    - bearerAuth: []
  requestBody:
    required: true
    content:
      application/json:
        schema:
          type: object
          properties:
            dummyProperty:
              $ref: "../schemas/DummyProperty.yaml"
          required:
            - dummyProperty
  responses:
    "200":
      $ref: "../responses/GenericSuccess.yaml"
    default:
      $ref: "../responses/UnexpectedError.yaml"

Generates the response as z.void().

This happens because this method does not consider that responseItem can contain a $ref

ferenckv avatar Jul 06 '23 23:07 ferenckv

got it, feel free to send a PR ! 🙏

astahmer avatar Jul 07 '23 08:07 astahmer

Is this released? I got same issue on 1.10.2

terrierscript avatar Aug 10 '23 01:08 terrierscript

yes, was merged here https://github.com/astahmer/openapi-zod-client/pull/188

astahmer avatar Aug 10 '23 01:08 astahmer

Seems to be happening to me as well on v1.16.2, my openapi JSON looks like the following

...
"responses": {
  "200": {
    "description": "OK",
    "content": {
      "*/*": {
        "schema": {
          "$ref": "#/components/schemas/UserInfo"
        }
      }
    }
  }
}
...

is this a supported use case?

ncheungg avatar Mar 11 '24 08:03 ncheungg

it looks like it should be fine, feel free to send a PR to fix it 🙏

astahmer avatar Mar 11 '24 11:03 astahmer

Hi, I've also encountered a similar situation.

My openapi JSON example:

{
  "openapi":"3.0.3",
  "info":{
    "version":"1",
    "title":"Example API"
  },
  "paths":{
    "/":{
      "get":{
        "operationId":"getExample",
        "responses":{
          "200":{
            "description":"Successfully retrieved.",
            "content":{
              "*/*":{
                "schema":{
                  "type":"array",
                  "items":{
                    "$ref":"#/components/schemas/ExampleResponse"
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components":{
    "schemas":{
      "ExampleResponse":{
        "required":[
          "streetName"
        ],
        "description":"example response",
        "type":"object",
        "properties":{
          "streetName":{
            "type":"string",
            "description":"Street name",
            "example":"National Avenue"
          }
        }
      }
    }
  }
}

I tried to run tests against this case, unfortunately I am getting z.void()

image

EDIT:

I think this "bug" happens, when content type is "*/*", then response schema is z.void(). If instead of content type "*/*" I pass "application/json", then I get the correct response schema.

x77t avatar Jul 29 '24 20:07 x77t