-
Notifications
You must be signed in to change notification settings - Fork 153
Expand file tree
/
Copy pathtest_jsonschema.py
More file actions
79 lines (69 loc) · 2.1 KB
/
test_jsonschema.py
File metadata and controls
79 lines (69 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from codegen.jsonschema import (
Property,
Schema,
SchemaType,
_parse_schema,
_unwrap_variable,
get_schemas,
)
def test_get_all_schemas():
schemas = get_schemas()
assert schemas
def test_unwrap_variable():
out = _unwrap_variable(
{
"oneOf": [
{"type": "object"},
{
"type": "string",
"pattern": "\\$\\{(var(\\.[a-zA-Z]+([-_]?[a-zA-Z0-9]+)*(\\[[0-9]+\\])*)+)\\}",
},
]
}
)
assert out == {"type": "object"}
def test_parse_schema():
spec = {
"anyOf": [
{
"type": "object",
"properties": {
"base_parameters": {
"description": "base_parameters description",
"$ref": "#/$defs/map/string",
},
"notebook_path": {"$ref": "#/$defs/string"},
"source": {
"$ref": "#/$defs/github.com/databricks/databricks-sdk-go/service/jobs.Source"
},
"warehouse_id": {"$ref": "#/$defs/string"},
},
"additionalProperties": False,
"required": ["notebook_path"],
},
{
"type": "string",
"pattern": "\\$\\{(var(\\.[a-zA-Z]+([-_]?[a-zA-Z0-9]+)*(\\[[0-9]+\\])*)+)\\}",
},
]
}
expected = Schema(
type=SchemaType.OBJECT,
properties={
"base_parameters": Property(
ref="#/$defs/map/string",
description="base_parameters description",
),
"notebook_path": Property(
ref="#/$defs/string",
),
"source": Property(
ref="#/$defs/github.com/databricks/databricks-sdk-go/service/jobs.Source",
),
"warehouse_id": Property(
ref="#/$defs/string",
),
},
required=["notebook_path"],
)
assert _parse_schema(spec) == expected