Closed helgee closed 3 years ago
Provide a minimal working example. I can't reproduce:
julia> schema = JSONSchema.Schema(raw"""{
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"address": {
"type": "object",
"properties": {
"street_address": {
"type": "string"
},
"city": {
"type": "string"
},
"state": {
"type": "string"
}
},
"required": [
"street_address",
"city",
"state"
],
"additionalProperties": false
}
},
"type": "object",
"properties": {
"billing_address": {
"$ref": "#/definitions/address"
},
"shipping_address": {
"$ref": "#/definitions/address"
}
},
"required": [
"billing_address",
"shipping_address"
],
"additionalProperties": false
}""")
A JSONSchema
julia> data = JSONSchema.JSON.parse("""{
"billing_address": {
"street_address": "1600 Pennsylvania Avenue NW",
"city": "Washington",
"state": "DC"
},
"shipping_address": {
"street_address": "1st Street SE",
"city": "Washington",
"state": "DC"
}
}""")
Dict{String, Any} with 2 entries:
"shipping_address" => Dict{String, Any}("city"=>"Washington", "street_address"=>"1st Street SE", "state"=>"DC")
"billing_address" => Dict{String, Any}("city"=>"Washington", "street_address"=>"1600 Pennsylvania Avenue NW", "state"=>"DC")
julia> validate(data, schema)
Okay, the problem is that I was using JSON3.jl. The workaround here is to always use JSON3.read(data, Dict)
or JSON3.read(data, Array)
when using JSONSchema.jl in conjunction with JSON3.jl.
Sorry for the noise 😬
The schema and data at the following link produce a spurious validation failure: https://www.jsonschemavalidator.net/s/kGlYqDn1
BTW: I am working on JSONSchemaGenerator.jl which automatically generates JSON Schema from Julia structs with StructTypes.jl annotations.