dry-rb / dry-schema

Coercion and validation for data structures
https://dry-rb.org/gems/dry-schema
MIT License
415 stars 108 forks source link

Fix json-schema type of maybe array #463

Open tomgi opened 1 year ago

tomgi commented 1 year ago

Make sure to not override an existing type: ["null", "array"] with type: "array" if it's already filled by visit_predicate before visit_set.

For example for the test schema https://github.com/dry-rb/dry-schema/blob/3065a8b97d89befce9379e6f5655783957123744/spec/extensions/json_schema/schema_spec.rb#L142-L146

the result of the fix is:

{
   "$schema": "http://json-schema.org/draft-06/schema#",
   "type": "object",
   "properties": {
     "list": {
-      "type": "array",
+      "type": [
+        "null",
+        "array"
+      ],
       "items": {
         "type": "object",
         "properties": {
           "name": {
             "type": "string"
           }
         },
         "required": [
           "name"
         ]
       }
     }
   },
   "required": [
     "list"
   ]
 }