Skip to content

Conversation

@josevalim
Copy link
Contributor

This keep backwards compatibility with v1.5.0.

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] = {}
Copy link
Contributor Author

@josevalim josevalim Oct 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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? }
end

generating 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.

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

Successfully merging this pull request may close these issues.

1 participant