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

Commit 39c807f

Browse files
authored
Update json schema ref to OAS 3 (#119)
1 parent ca0c98a commit 39c807f

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

docs/json_schema.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
TypeSystem can convert Schema or Field instances to/from JSON Schema.
22

33
!!! note
4-
TypeSystem only supports `$ref` pointers that use the standard "definitions"
4+
TypeSystem only supports `$ref` pointers that use the standard "components/schemas"
55
namespace to store referenced schemas.
66

7-
All references should be of the style `{"$ref": "#/definitions/..."}`.
7+
All references should be of the style `{"$ref": "#/components/schemas/..."}`.
88

99
Using hyperlinked references, relative references, or references to parts
1010
of the document other than "definitions" is not supported.

tests/jsonschema/draft7/definitionsRef.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
"schema": {
55
"definitions": {
66
"a": {"type": "integer"},
7-
"b": {"$ref": "#/definitions/a"},
8-
"c": {"$ref": "#/definitions/b"}
7+
"b": {"$ref": "#/components/schemas/a"},
8+
"c": {"$ref": "#/components/schemas/b"}
99
},
10-
"$ref": "#/definitions/c"
10+
"$ref": "#/components/schemas/c"
1111
},
1212
"tests": [
1313
{
@@ -32,7 +32,7 @@
3232
},
3333
"properties": {
3434
"foo": {
35-
"$ref": "#/definitions/reffed",
35+
"$ref": "#/components/schemas/reffed",
3636
"maxItems": 2
3737
}
3838
}
@@ -58,7 +58,7 @@
5858
{
5959
"description": "$ref to boolean schema true",
6060
"schema": {
61-
"$ref": "#/definitions/bool",
61+
"$ref": "#/components/schemas/bool",
6262
"definitions": {
6363
"bool": true
6464
}
@@ -74,7 +74,7 @@
7474
{
7575
"description": "$ref to boolean schema false",
7676
"schema": {
77-
"$ref": "#/definitions/bool",
77+
"$ref": "#/components/schemas/bool",
7878
"definitions": {
7979
"bool": false
8080
}

tests/test_schemas.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ def test_nested_schema_to_json_schema():
451451
"properties": {
452452
"title": {"type": "string", "minLength": 1, "maxLength": 100},
453453
"release_date": {"type": "string", "minLength": 1, "format": "date"},
454-
"artist": {"$ref": "#/definitions/Artist"},
454+
"artist": {"$ref": "#/components/schemas/Artist"},
455455
},
456456
"required": ["title", "release_date", "artist"],
457457
"definitions": {
@@ -502,7 +502,7 @@ def test_definitions_to_json_schema():
502502
"minLength": 1,
503503
"format": "date",
504504
},
505-
"artist": {"$ref": "#/definitions/Artist"},
505+
"artist": {"$ref": "#/components/schemas/Artist"},
506506
},
507507
"required": ["title", "release_date", "artist"],
508508
},

typesystem/json_schema.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def from_json_schema(
116116
if definitions is None:
117117
definitions = Definitions()
118118
for key, value in data.get("definitions", {}).items():
119-
ref = f"#/definitions/{key}"
119+
ref = f"#/components/schemas/{key}"
120120
definitions[ref] = from_json_schema(value, definitions=definitions)
121121

122122
if "$ref" in data:
@@ -421,7 +421,7 @@ def to_json_schema(
421421
definitions[key] = to_json_schema(value, _definitions=definitions)
422422

423423
if isinstance(field, Reference):
424-
data["$ref"] = f"#/definitions/{field.to}"
424+
data["$ref"] = f"#/components/schemas/{field.to}"
425425
definitions[field.to] = to_json_schema(field.target, _definitions=definitions)
426426

427427
elif isinstance(field, String):

0 commit comments

Comments
 (0)