-
Notifications
You must be signed in to change notification settings - Fork 41
References are broken for JSON schema (0.4.0) #121
Description
Checklist
- The bug is reproducible against the latest release and/or
master. - There are no similar issues or pull requests to fix it yet.
Describe the bug
Quoting the following change from the changelog for 0.4.0:
Update JSON schema ref according to OAS 3: #/components/schemas/
Currently I'm facing the issue that when a typesystem schema contains a reference, it will not be resolvable in the resulting JSON Schema.
I made an example based on https://github.com/encode/typesystem/blob/master/docs/references.md.
To reproduce
import json
import typesystem
definitions = typesystem.Definitions()
artist_schema = typesystem.Schema(fields={"name": typesystem.String(max_length=100)})
album_schema = typesystem.Schema(
fields={
"title": typesystem.String(max_length=100),
"release_date": typesystem.Date(),
"artist": typesystem.Reference(to="Artist", definitions=definitions),
}
)
definitions["Artist"] = artist_schema
definitions["Album"] = album_schema
document = typesystem.to_json_schema(album_schema)
print(json.dumps(document, indent=4))I'm simply trying to get a JSON Schema out of the defined album_schema.
Expected behavior
Receive a JSON Schema output that contains the correct $ref which makes it resolvable.
Actual behavior
JSON Schema output that contains a definitions key which is not in line with the new syntax (i.e.: "$ref": "#/components/schemas/Artist")
{
"type": "object",
"properties": {
"title": {
"type": "string",
"minLength": 1,
"maxLength": 100
},
"release_date": {
"type": "string",
"minLength": 1,
"format": "date"
},
"artist": {
"$ref": "#/components/schemas/Artist"
}
},
"required": [
"title",
"release_date",
"artist"
],
"definitions": {
"Artist": {
"type": "object",
"properties": {
"name": {
"type": "string",
"minLength": 1,
"maxLength": 100
}
},
"required": [
"name"
]
}
}
}With the newly generated reference syntax ("#/components/schemas/Artist"), shouldn't the document contain the elements "components" as well as "schemas" and respectively "Artist" in this example?
Environment
- OS: macOS
- Python version: 3.9.6
- Typesystem version: 0.4.0