dry-schema
dry-schema copied to clipboard
Fix json-schema type of objects nested under arrays. Fixes #400
Fix for https://github.com/dry-rb/dry-schema/issues/400
Objects nested under arrays are not neccesailry arrays themselves - the :member option shouldn't be passed down the AST when generating json-schema.
For example for the test schema https://github.com/dry-rb/dry-schema/blob/5853103d6849490ae8ba94158f73631c1fd121a8/spec/extensions/json_schema/schema_spec.rb#L28-L34
the result of the fix is:
{
"$schema": "http://json-schema.org/draft-06/schema#",
"type": "object",
"properties": {
"email": {
"type": "string"
},
"age": {
"type": "integer"
},
"roles": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string",
"minLength": 12,
"maxLength": 36
},
"metadata": {
- "type": "array",
- "items": {
- "type": "object",
- "properties": {
- "assigned_at": {
- "type": "string",
- "format": "time"
- }
- },
- "required": [
- "assigned_at"
- ]
- }
+ "type": "object",
+ "properties": {
+ "assigned_at": {
+ "format": "time",
+ "type": "string"
+ }
+ },
+ "required": [
+ "assigned_at"
+ ]
}
},
"required": [
"name",
"metadata"
]
}
},
"address": {
"type": "object",
"properties": {
"street": {
"type": "string"
}
},
"required": [
]
},
"id": {
"anyOf": [
{
"type": "string"
},
{
"type": "integer"
}
]
}
},
"required": [
"email",
"roles",
"id"
]
}
Hey @tomgi just asked about this issue on the zulip chat. Tried monkey patching your solution on my project and it seems to be working perfectly.
@solnic is there any plans to merge this PR?
Following up on this -- @solnic would merging it be possible? The bug is still in place and this fix is a good one.
I'm sorry it took so long, I'll push a release, thanks for addressing it
Awesome work. Thanks for dedicating your time to fix this :heart: