Skip to content
This repository was archived by the owner on Aug 19, 2025. It is now read-only.

Commit 23dccba

Browse files
authored
Fix broken references in OAS3 (#122)
1 parent 2e9dc56 commit 23dccba

File tree

8 files changed

+363
-167
lines changed

8 files changed

+363
-167
lines changed

docs/json_schema.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ TypeSystem can convert Schema or Field instances to/from JSON Schema.
77
All references should be of the style `{"$ref": "#/components/schemas/..."}`.
88

99
Using hyperlinked references, relative references, or references to parts
10-
of the document other than "definitions" is not supported.
10+
of the document other than "components/schemas" is not supported.
1111

1212
Let's define a schema, and dump it out into a JSON schema document:
1313

docs/references.md

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -53,42 +53,44 @@ definitions["Album"] = album_schema
5353
document = typesystem.to_json_schema(definitions)
5454
print(json.dumps(document, indent=4))
5555
# {
56-
# "definitions": {
57-
# "Artist": {
58-
# "type": "object",
59-
# "properties": {
60-
# "name": {
61-
# "type": "string",
62-
# "minLength": 1,
63-
# "maxLength": 100
64-
# }
65-
# },
66-
# "required": [
67-
# "name"
68-
# ]
69-
# },
70-
# "Album": {
71-
# "type": "object",
72-
# "properties": {
73-
# "title": {
74-
# "type": "string",
75-
# "minLength": 1,
76-
# "maxLength": 100
77-
# },
78-
# "release_date": {
79-
# "type": "string",
80-
# "minLength": 1,
81-
# "format": "date"
56+
# "components":{
57+
# "schemas":{
58+
# "Artist":{
59+
# "type":"object",
60+
# "properties":{
61+
# "name":{
62+
# "type":"string",
63+
# "minLength":1,
64+
# "maxLength":100
65+
# }
8266
# },
83-
# "artist": {
84-
# "$ref": "#/definitions/Artist"
85-
# }
67+
# "required":[
68+
# "name"
69+
# ]
8670
# },
87-
# "required": [
88-
# "title",
89-
# "release_date",
90-
# "artist"
91-
# ]
71+
# "Album":{
72+
# "type":"object",
73+
# "properties":{
74+
# "title":{
75+
# "type":"string",
76+
# "minLength":1,
77+
# "maxLength":100
78+
# },
79+
# "release_date":{
80+
# "type":"string",
81+
# "minLength":1,
82+
# "format":"date"
83+
# },
84+
# "artist":{
85+
# "$ref":"#/components/schemas/Artist"
86+
# }
87+
# },
88+
# "required":[
89+
# "title",
90+
# "release_date",
91+
# "artist"
92+
# ]
93+
# }
9294
# }
9395
# }
9496
# }
Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
[
22
{
33
"description": "valid definition",
4-
"schema": {"$ref": "http://json-schema.org/draft-07/schema#"},
4+
"schema": {
5+
"$ref": "http://json-schema.org/draft-07/schema#"
6+
},
57
"tests": [
68
{
79
"description": "valid definition schema",
810
"data": {
9-
"definitions": {
10-
"foo": {"type": "integer"}
11+
"components": {
12+
"schemas": {
13+
"foo": {
14+
"type": "integer"
15+
}
16+
}
1117
}
1218
},
1319
"valid": true
@@ -16,17 +22,23 @@
1622
},
1723
{
1824
"description": "invalid definition",
19-
"schema": {"$ref": "http://json-schema.org/draft-07/schema#"},
25+
"schema": {
26+
"$ref": "http://json-schema.org/draft-07/schema#"
27+
},
2028
"tests": [
2129
{
2230
"description": "invalid definition schema",
2331
"data": {
24-
"definitions": {
25-
"foo": {"type": 1}
32+
"components": {
33+
"schemas": {
34+
"foo": {
35+
"type": 1
36+
}
37+
}
2638
}
2739
},
2840
"valid": false
2941
}
3042
]
3143
}
32-
]
44+
]

tests/jsonschema/draft7/definitionsRef.json

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,18 @@
22
{
33
"description": "nested refs",
44
"schema": {
5-
"definitions": {
6-
"a": {"type": "integer"},
7-
"b": {"$ref": "#/components/schemas/a"},
8-
"c": {"$ref": "#/components/schemas/b"}
5+
"components": {
6+
"schemas": {
7+
"a": {
8+
"type": "integer"
9+
},
10+
"b": {
11+
"$ref": "#/components/schemas/a"
12+
},
13+
"c": {
14+
"$ref": "#/components/schemas/b"
15+
}
16+
}
917
},
1018
"$ref": "#/components/schemas/c"
1119
},
@@ -25,9 +33,11 @@
2533
{
2634
"description": "ref overrides any sibling keywords",
2735
"schema": {
28-
"definitions": {
29-
"reffed": {
30-
"type": "array"
36+
"components": {
37+
"schemas": {
38+
"reffed": {
39+
"type": "array"
40+
}
3141
}
3242
},
3343
"properties": {
@@ -40,17 +50,27 @@
4050
"tests": [
4151
{
4252
"description": "ref valid",
43-
"data": { "foo": [] },
53+
"data": {
54+
"foo": []
55+
},
4456
"valid": true
4557
},
4658
{
4759
"description": "ref valid, maxItems ignored",
48-
"data": { "foo": [ 1, 2, 3] },
60+
"data": {
61+
"foo": [
62+
1,
63+
2,
64+
3
65+
]
66+
},
4967
"valid": true
5068
},
5169
{
5270
"description": "ref invalid",
53-
"data": { "foo": "string" },
71+
"data": {
72+
"foo": "string"
73+
},
5474
"valid": false
5575
}
5676
]
@@ -59,8 +79,10 @@
5979
"description": "$ref to boolean schema true",
6080
"schema": {
6181
"$ref": "#/components/schemas/bool",
62-
"definitions": {
63-
"bool": true
82+
"components": {
83+
"schemas": {
84+
"bool": true
85+
}
6486
}
6587
},
6688
"tests": [
@@ -75,8 +97,10 @@
7597
"description": "$ref to boolean schema false",
7698
"schema": {
7799
"$ref": "#/components/schemas/bool",
78-
"definitions": {
79-
"bool": false
100+
"components": {
101+
"schemas": {
102+
"bool": false
103+
}
80104
}
81105
},
82106
"tests": [
@@ -87,4 +111,4 @@
87111
}
88112
]
89113
}
90-
]
114+
]

0 commit comments

Comments
 (0)