openapi-zod-client
openapi-zod-client copied to clipboard
$ref in response results in z.void()
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
got it, feel free to send a PR ! 🙏
Is this released? I got same issue on 1.10.2
yes, was merged here https://github.com/astahmer/openapi-zod-client/pull/188
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?
it looks like it should be fine, feel free to send a PR to fix it 🙏
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()
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.