Ensure items are set for array for backwards compatibility#156
Open
josevalim wants to merge 1 commit intoyjacquin:mainfrom
Open
Ensure items are set for array for backwards compatibility#156josevalim wants to merge 1 commit intoyjacquin:mainfrom
josevalim wants to merge 1 commit intoyjacquin:mainfrom
Conversation
josevalim
commented
Oct 4, 2025
| filter_required_properties(property_schema[:required], property_schema[:properties]) | ||
| # Recursively process array items with object properties | ||
| elsif property_schema[:type] == 'array' && !property_schema.key?(:items) | ||
| property_schema[:items] = {} |
Contributor
Author
There was a problem hiding this comment.
To add more context, the following code:
optional(:arguments).array(:str?, :float?)Generates:
{
"type": "array",
"items": {
"type": ["string", "float"]
}
}JSON Schema treats "type": ["string", "float"] as a OR but Dry::Schema considers array(str?, float?) to be an AND.
My attempts to make Dry::Schema generate or clauses have generated verbose anyOf nodes, such as this:
array do
each { str? | float? }
endgenerating this:
{:anyOf=>[{:type=>"string"}, {:type=>"boolean"}]}While a lean "type": ["string", "float"] output would be more convenient for LLM usage. I am not sure if there is an easy to generate OR types in JSON with OR semantics in Dry::Schema.
Another option is to generate this:
Suggested change
| property_schema[:items] = {} | |
| property_schema[:items] = { type: ["array", "boolean", "integer", "number", "null", "object", "string"] } |
But I chose to keep backwards compatibility for now.
This was referenced Oct 4, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This keep backwards compatibility with v1.5.0.