-
Notifications
You must be signed in to change notification settings - Fork 5
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
feat: manage map types with additionalProperties
#98
Conversation
The schema in question can be found at: https://github.com/axone-protocol/axone-contract-schema/blob/refactor/go-codegen/schema/axone-cognitarium.json. Please note that this schema has not been added to the test data due to the presence of another issue that is unrelated to |
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 so much for the contribution once again. Looks pretty good, I've left some comments, let's address them and get this merged.
Co-authored-by: srdtrk <[email protected]>
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.
Lgtm, left one suggestion, will merge once that's resolved.
This Pull Request introduces improvements to the JSON schema generation process, specifically for
Map
types. These improvements are in line with the JSON schema draft documentation and the output from the schemars tool.When a
Map
is defined, it generates a JSON schema definition whereadditionalProperties
is set to accept the type required by the map value type.Consider the following Rust code:
This code generates the following JSON schemas:
In Go, this should generate a
foo
property of typemap[string]string
for the first schema andmap[string]Value
for the second one.This PR includes modifications to the handling of the
additionalProperties
field, allowing it to accept either a boolean or aJSONSchema
, in line with the JSON schema specification.Furthermore, when
additionalProperties
is set totrue
(which is the default value in JSON Schema), it implies that the object can accept any property with any value. While this does not adhere strictly to the JSON schema specification (because we can set bothproperties
andaddionalProperties
), it provides a more flexible approach to handlingadditionalProperties
.