Skip to content

Commit

Permalink
Test compiling schemas with $ref
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Cruz Viotti <[email protected]>
  • Loading branch information
jviotti committed Aug 13, 2024
1 parent c6172d9 commit 7cdcaaa
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
3 changes: 2 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ add_jsonschema_test_unix(frame/fail_schema_invalid_json)
add_jsonschema_test_unix(frame/fail_unknown_metaschema)

# Compile
add_jsonschema_test_unix(compile/pass)
add_jsonschema_test_unix(compile/pass_1)
add_jsonschema_test_unix(compile/pass_2)
add_jsonschema_test_unix(compile/fail_no_schema)
add_jsonschema_test_unix(compile/fail_schema_invalid_json)
add_jsonschema_test_unix(compile/fail_unknown_metaschema)
Expand Down
File renamed without changes.
54 changes: 54 additions & 0 deletions test/compile/pass_2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/sh

set -o errexit
set -o nounset

TMP="$(mktemp -d)"
clean() { rm -rf "$TMP"; }
trap clean EXIT

cat << 'EOF' > "$TMP/schema.json"
{
"$schema": "http://json-schema.org/draft-04/schema#",
"allOf": [ {"$ref": "#/definitions/job" } ],
"definitions": { "job": {} }
}
EOF

"$1" compile "$TMP/schema.json" > "$TMP/result.json"

cat << 'EOF' > "$TMP/expected.json"
[
{
"category": "logical",
"type": "and",
"value": null,
"schemaResource": "",
"absoluteKeywordLocation": "#/allOf",
"relativeSchemaLocation": "/allOf",
"relativeInstanceLocation": "",
"target": {
"category": "target",
"type": "instance",
"location": ""
},
"dynamic": false,
"condition": [],
"children": [
{
"category": "control",
"type": "label",
"schemaResource": "",
"absoluteKeywordLocation": "#/allOf/0/$ref",
"relativeSchemaLocation": "/0/$ref",
"relativeInstanceLocation": "",
"id": 6805500211157121261,
"dynamic": false,
"children": []
}
]
}
]
EOF

diff "$TMP/result.json" "$TMP/expected.json"

0 comments on commit 7cdcaaa

Please sign in to comment.