Skip to content

Schema is already registered #377

Answered by samchungy
RonB asked this question in Q&A
Discussion options

You must be logged in to vote

When you use the .openapi() method, it returns a new instance of your schema. This library will store that specific instance and when it runs into it, it will generate a reference instead.

eg.

const AString = z.string();

const ARegisteredString = AString().openapi({ ref: 'registered' });

// If you were to try and register AString again:

const BRegisteredString = AString().openapi({ ref: 'registered' });

ARegisteredString === BRegisteredString // false;

// Instead, you want to try and pass around `ARegisteredString`

const OtherSchema = z.object( { a: ARegisteredString });

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@RonB
Comment options

Answer selected by RonB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants