Skip to content

Commit

Permalink
Update json schema ref to OAS 3 (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
perdy authored Oct 22, 2021
1 parent ca0c98a commit 39c807f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions docs/json_schema.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
TypeSystem can convert Schema or Field instances to/from JSON Schema.

!!! note
TypeSystem only supports `$ref` pointers that use the standard "definitions"
TypeSystem only supports `$ref` pointers that use the standard "components/schemas"
namespace to store referenced schemas.

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

Using hyperlinked references, relative references, or references to parts
of the document other than "definitions" is not supported.
Expand Down
12 changes: 6 additions & 6 deletions tests/jsonschema/draft7/definitionsRef.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"schema": {
"definitions": {
"a": {"type": "integer"},
"b": {"$ref": "#/definitions/a"},
"c": {"$ref": "#/definitions/b"}
"b": {"$ref": "#/components/schemas/a"},
"c": {"$ref": "#/components/schemas/b"}
},
"$ref": "#/definitions/c"
"$ref": "#/components/schemas/c"
},
"tests": [
{
Expand All @@ -32,7 +32,7 @@
},
"properties": {
"foo": {
"$ref": "#/definitions/reffed",
"$ref": "#/components/schemas/reffed",
"maxItems": 2
}
}
Expand All @@ -58,7 +58,7 @@
{
"description": "$ref to boolean schema true",
"schema": {
"$ref": "#/definitions/bool",
"$ref": "#/components/schemas/bool",
"definitions": {
"bool": true
}
Expand All @@ -74,7 +74,7 @@
{
"description": "$ref to boolean schema false",
"schema": {
"$ref": "#/definitions/bool",
"$ref": "#/components/schemas/bool",
"definitions": {
"bool": false
}
Expand Down
4 changes: 2 additions & 2 deletions tests/test_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ def test_nested_schema_to_json_schema():
"properties": {
"title": {"type": "string", "minLength": 1, "maxLength": 100},
"release_date": {"type": "string", "minLength": 1, "format": "date"},
"artist": {"$ref": "#/definitions/Artist"},
"artist": {"$ref": "#/components/schemas/Artist"},
},
"required": ["title", "release_date", "artist"],
"definitions": {
Expand Down Expand Up @@ -502,7 +502,7 @@ def test_definitions_to_json_schema():
"minLength": 1,
"format": "date",
},
"artist": {"$ref": "#/definitions/Artist"},
"artist": {"$ref": "#/components/schemas/Artist"},
},
"required": ["title", "release_date", "artist"],
},
Expand Down
4 changes: 2 additions & 2 deletions typesystem/json_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def from_json_schema(
if definitions is None:
definitions = Definitions()
for key, value in data.get("definitions", {}).items():
ref = f"#/definitions/{key}"
ref = f"#/components/schemas/{key}"
definitions[ref] = from_json_schema(value, definitions=definitions)

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

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

elif isinstance(field, String):
Expand Down

0 comments on commit 39c807f

Please sign in to comment.