b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | #!/bin/sh |
| 2 | |
| 3 | [ "$1" = python3-referencing ] || exit 0 |
| 4 | |
| 5 | python3 - << 'EOF' |
| 6 | |
| 7 | from referencing import Registry, Resource |
| 8 | import referencing.jsonschema |
| 9 | |
| 10 | schema = Resource.from_contents( # Parse some contents into a 2020-12 JSON Schema |
| 11 | { |
| 12 | "$schema": "https://json-schema.org/draft/2020-12/schema", |
| 13 | "$id": "urn:example:a-202012-schema", |
| 14 | "$defs": { |
| 15 | "nonNegativeInteger": { |
| 16 | "$anchor": "nonNegativeInteger", |
| 17 | "type": "integer", |
| 18 | "minimum": 0, |
| 19 | }, |
| 20 | }, |
| 21 | } |
| 22 | ) |
| 23 | registry = schema @ Registry() # Add the resource to a new registry |
| 24 | |
| 25 | # From here forward, this would usually be done within a library wrapping this one, |
| 26 | # like a JSON Schema implementation |
| 27 | resolver = registry.resolver() |
| 28 | resolved = resolver.lookup("urn:example:a-202012-schema#nonNegativeInteger") |
| 29 | assert resolved.contents == { |
| 30 | "$anchor": "nonNegativeInteger", |
| 31 | "type": "integer", |
| 32 | "minimum": 0, |
| 33 | } |
| 34 | |
| 35 | EOF |