Skip to content

Commit

Permalink
Update validation.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Jun 29, 2024
1 parent 6191fb6 commit 2c21138
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/validation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -169,34 +169,35 @@ end
function _validate(x, schema, ::Val{:if}, val, path::String)
# ignore if without then or else
if haskey(schema, "then") || haskey(schema, "else")
ret = _if_then_else(x, schema, path)
return ret
return _if_then_else(x, schema, path)
end
return
end

# 9.2.2.2: then
function _validate(x, schema, ::Val{:then}, val, path::String)
# ignore then without if
if haskey(schema, "if")
ret = _if_then_else(x, schema, path)
return ret
return _if_then_else(x, schema, path)
end
return
end

# 9.2.2.3: else
function _validate(x, schema, ::Val{:else}, val, path::String)
# ignore else without if
if haskey(schema, "if")
ret = _if_then_else(x, schema, path)
return ret
return _if_then_else(x, schema, path)
end
return
end

"""
_if_then_else(x, schema, path)
The if, then and else keywords allow the application of a subschema based on the outcome of another schema. Details are in the link and the truth table is as follows:
The if, then and else keywords allow the application of a subschema based on the
outcome of another schema. Details are in the link and the truth table is as
follows:
```
┌─────┬──────┬──────┬────────┐
Expand All @@ -208,8 +209,10 @@ The if, then and else keywords allow the application of a subschema based on the
│ F │ n/a │ F │ F │
│ n/a │ n/a │ n/a │ T │
└─────┴──────┴──────┴────────┘
https://json-schema.org/understanding-json-schema/reference/conditionals#ifthenelse
```
See https://json-schema.org/understanding-json-schema/reference/conditionals#ifthenelse
for details.
"""
function _if_then_else(x, schema, path)
if _validate(x, schema["if"], path) !== nothing
Expand Down

0 comments on commit 2c21138

Please sign in to comment.