def test_flatten(self): input_ = { "type": "object", "title": "x", "properties": { "a": { "type": "object", "title": "y", "properties": {"b": {"type": "integer"}}, }, "b": {"type": "string"}, }, } expected_schema = {"$ref": "#/definitions/x"} expected_definitions = { "x": { "type": "object", "title": "x", "properties": { "a": {"$ref": "#/definitions/y"}, "b": {"type": "string"}, }, }, "y": { "type": "object", "title": "y", "properties": {"b": {"type": "integer"}}, }, } schema, definitions = flatten(input_) self.assertEqual(schema, expected_schema) self.assertEqual(definitions, expected_definitions)
def test_flatten(self): input_ = { 'type': 'object', 'title': 'x', 'properties': { 'a': { 'type': 'object', 'title': 'y', 'properties': { 'b': { 'type': 'integer' } } }, 'b': { 'type': 'string' } } } expected_schema = {'$ref': '#/definitions/x'} expected_definitions = { 'x': { 'type': 'object', 'title': 'x', 'properties': { 'a': { '$ref': '#/definitions/y' }, 'b': { 'type': 'string' } } }, 'y': { 'type': 'object', 'title': 'y', 'properties': { 'b': { 'type': 'integer' } } } } schema, definitions = flatten(input_) self.assertEqual(schema, expected_schema) self.assertEqual(definitions, expected_definitions)
def test_flatten_array(self): input_ = { 'type': 'array', 'title': 'x', 'items': { 'type': 'array', 'title': 'y', 'items': { 'type': 'object', 'title': 'z', 'properties': { 'a': { 'type': 'integer' } } } } } expected_schema = { 'type': 'array', 'title': 'x', 'items': { 'type': 'array', 'title': 'y', 'items': { '$ref': '#/definitions/z' } } } expected_definitions = { 'z': { 'type': 'object', 'title': 'z', 'properties': { 'a': { 'type': 'integer' } } } } schema, definitions = flatten(input_) self.assertEqual(schema, expected_schema) self.assertEqual(definitions, expected_definitions)
def test_flatten_array(self): input_ = { "type": "array", "title": "x", "items": { "type": "array", "title": "y", "items": { "type": "object", "title": "z", "properties": {"a": {"type": "integer"}}, }, }, } expected_schema = { "type": "array", "title": "x", "items": { "type": "array", "title": "y", "items": {"$ref": "#/definitions/z"}, }, } expected_definitions = { "z": { "type": "object", "title": "z", "properties": {"a": {"type": "integer"}}, } } schema, definitions = flatten(input_) self.assertEqual(schema, expected_schema) self.assertEqual(definitions, expected_definitions)