Skip to content

Commit

Permalink
Fixed schema generation for lists.
Browse files Browse the repository at this point in the history
  • Loading branch information
beregond committed Nov 2, 2015
1 parent c797667 commit f034b46
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 5 deletions.
2 changes: 1 addition & 1 deletion jsonmodels/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def build_json_schema(value, parent_builder=None):

def build_json_schema_object(cls, parent_builder=None):
builder = ObjectBuilder(cls, parent_builder)
if builder.is_definition:
if builder.count_type(builder.type) > 1:
return builder
for name, field in cls.iterate_over_fields():
if isinstance(field, fields.EmbeddedField):
Expand Down
50 changes: 50 additions & 0 deletions tests/fixtures/schema_circular2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"additionalProperties": false,
"definitions": {
"tests_test_circular_references_directory": {
"additionalProperties": false,
"properties": {
"children": {
"items": {
"oneOf": [
"#/definitions/tests_test_circular_references_directory",
"#/definitions/tests_test_circular_references_file"
]
},
"type": "list"
},
"name": {
"type": "string"
}
},
"type": "object"
},
"tests_test_circular_references_file": {
"additionalProperties": false,
"properties": {
"name": {
"type": "string"
},
"size": {
"type": "float"
}
},
"type": "object"
}
},
"properties": {
"children": {
"items": {
"oneOf": [
"#/definitions/tests_test_circular_references_directory",
"#/definitions/tests_test_circular_references_file"
]
},
"type": "list"
},
"name": {
"type": "string"
}
},
"type": "object"
}
8 changes: 4 additions & 4 deletions tests/test_circular_references.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import pytest

from jsonmodels import models, fields
from jsonmodels.utilities import compare_schemas

Expand Down Expand Up @@ -43,6 +41,8 @@ class Filesystem(models.Base):
children = fields.ListField([Directory, File])


@pytest.mark.xfail
def test_generate_circular_schema2():
Filesystem.to_json_schema()
schema = Filesystem.to_json_schema()

pattern = get_fixture('schema_circular2.json')
assert compare_schemas(pattern, schema) is True

0 comments on commit f034b46

Please sign in to comment.