Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cyclic references within definitions #29

Closed
bacebu4 opened this issue Nov 29, 2022 · 4 comments
Closed

Cyclic references within definitions #29

bacebu4 opened this issue Nov 29, 2022 · 4 comments

Comments

@bacebu4
Copy link

bacebu4 commented Nov 29, 2022

Representation example

Given the input

interface User {
  id: string;
  headUser?: User;
}

export const userSchema: z.ZodType<User> = z.lazy(() =>
  z.object({
    id: z.string(),
    headUser: userSchema.optional()
  })
);

Produces the following output

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "type": "object",
    "properties": {
        "user": {
            "$ref": "#/properties/headUser"
        }
    },
    "required": [
        "user"
    ],
    "additionalProperties": false,
    "definitions": {
        "User": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "string"
                },
                "headUser": {
                    "type": "object",
                    "properties": {
                        "id": {
                            "type": "string"
                        },
                        "headUser": {
                            "$ref": "#/properties/headUser"
                        }
                    },
                    "required": [
                        "id"
                    ],
                    "additionalProperties": false
                }
            },
            "required": [
                "id"
            ],
            "additionalProperties": false
        }
    }
}
@StefanTerdell
Copy link
Owner

🤦

@StefanTerdell
Copy link
Owner

I will need to rebuild the reference handling to account for this, which has been a long time coming anyway since it's a bit of a mess. I've marked the feature as experimental in the meantime. I have a ton of stuff to do at work right now so not sure when I'll be able to get to it though.

@bacebu4
Copy link
Author

bacebu4 commented Nov 29, 2022

Got you
I'll have a vacation next week so I might to provide some help as well (if you still won't be able to deliver the feature)

@StefanTerdell
Copy link
Owner

Fixed in 3.20.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants