-
-
Notifications
You must be signed in to change notification settings - Fork 346
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
fix(zod): treat additionalProperties
keyword
#1443
fix(zod): treat additionalProperties
keyword
#1443
Conversation
Also, couldn't help but fix few typos here and there. |
strict, | ||
), | ||
generateZodValidationSchemaDefinition( | ||
isBoolean(schema.additionalProperties) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actual fix which I'm not sure about: since additionalProperties: true
is just an alias for additionalProperties: {}
, I decided to treat it as latter. Should definition be faithful to original scheme?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it correct to understand that if it is simply true
, it is determined that the additional property does not exist?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I understood from the OpenAPI docs, it's the opposite:
If the dictionary values can be of any type (aka free-form object), use additionalProperties: true:
https://swagger.io/docs/specification/data-models/dictionaries/#free-form
So, additionalProperties: true
is equivalent to additionalProperties: {}
, which means that any type of property values allowed. Basically, it means it's Record<string, any>
. additionalProperties: {}
works fine, btw, it's just additionalProperties: true
that's broken.
UPD. Oops, used work account. Comment is still relevant, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I understood.
90f72ac
to
b4692cc
Compare
@TommoLeedsy can you review this also? Its related to other recent zod changes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ixth
I have asked a simple question, please answer.
strict, | ||
), | ||
generateZodValidationSchemaDefinition( | ||
isBoolean(schema.additionalProperties) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it correct to understand that if it is simply true
, it is determined that the additional property does not exist?
@melloware
|
Awesome thanks for the answers @ixth |
As soon as I might not get the whole picture. What cases am I missing? |
@ixth |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your response. I think it's a good change, but I'd like to wait for some comments by #972, so I'll merge it in a few days.
@soartec-lab i am going to merge as this is the correct solution and @ixth pointed out why the previous PR was actually incorrect. |
Gotcha! |
Status
READY
Description
additionalProperties: true
isn't treated the right way during schema parsing, which results in runtime error during generation. Since #972 is stalled, decided to dig into it myself.Related PRs
Previous attempt to fix this: