blob: 0517ba16877607f4973a0bc666b15196d3e4d594 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001#!/bin/sh
2
3[ "$1" = python3-referencing ] || exit 0
4
5python3 - << 'EOF'
6
7from referencing import Registry, Resource
8import referencing.jsonschema
9
10schema = 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)
23registry = 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
27resolver = registry.resolver()
28resolved = resolver.lookup("urn:example:a-202012-schema#nonNegativeInteger")
29assert resolved.contents == {
30 "$anchor": "nonNegativeInteger",
31 "type": "integer",
32 "minimum": 0,
33}
34
35EOF