Change Object schema type to be array instead of string.

This is done so that nullable Object field's schema can be given the null or
object type property.

implements bp json-schema-for-versioned-object

Change-Id: I43b04a76cccc9d4f893162535050fed6940bee6c
This commit is contained in:
Julian Sy 2016-12-16 13:39:51 +00:00
parent 055b945f9b
commit 526134585b
3 changed files with 9 additions and 9 deletions

View File

@ -838,7 +838,7 @@ class Object(FieldType):
required_fields = [key for key, field in sorted(cls.fields.items())
if not field.nullable]
schema = {
'type': 'object',
'type': ['object'],
'properties': {
namespace_key: {
'type': 'string'

View File

@ -911,7 +911,7 @@ class TestObject(TestField):
class TestFoo(TestFakeObject, obj_base.ComparableVersionedObject):
fields = {
'name': fields.StringField(),
'bar': fields.ObjectField('TestBar')
'bar': fields.ObjectField('TestBar', nullable=True)
}
bar = TestBar(name='bar')
@ -1041,7 +1041,7 @@ class TestObject(TestField):
'versioned_object.name',
'versioned_object.version',
'versioned_object.data'],
'type': 'object'
'type': ['object']
},
self.field.get_schema())

View File

@ -2076,7 +2076,7 @@ class TestSchemaGeneration(test.TestCase):
class FakeComplexObject(base.VersionedObject):
fields = {
'a_dict': fields.DictOfListOfStringsField(),
'an_obj': fields.ObjectField('FakeObject'),
'an_obj': fields.ObjectField('FakeObject', nullable=True),
'list_of_objs': fields.ListOfObjectsField('FakeObject'),
}
@ -2085,7 +2085,7 @@ class TestSchemaGeneration(test.TestCase):
self.assertEqual({
'$schema': 'http://json-schema.org/draft-04/schema#',
'title': 'FakeObject',
'type': 'object',
'type': ['object'],
'properties': {
'versioned_object.namespace': {
'type': 'string'
@ -2159,7 +2159,7 @@ class TestSchemaGeneration(test.TestCase):
'versioned_object.name',
'versioned_object.version',
'versioned_object.data'],
'type': 'object'},
'type': ['object', 'null']},
'list_of_objs': {
'items': {
'properties': {
@ -2184,10 +2184,10 @@ class TestSchemaGeneration(test.TestCase):
'versioned_object.name',
'versioned_object.version',
'versioned_object.data'],
'type': 'object'},
'type': ['object']},
'readonly': False,
'type': ['array']}},
'required': ['a_dict', 'an_obj', 'list_of_objs'],
'required': ['a_dict', 'list_of_objs'],
'type': 'object'},
'versioned_object.name': {'type': 'string'},
'versioned_object.namespace': {'type': 'string'},
@ -2197,7 +2197,7 @@ class TestSchemaGeneration(test.TestCase):
'versioned_object.version',
'versioned_object.data'],
'title': 'FakeComplexObject',
'type': 'object'}
'type': ['object']}
self.assertEqual(expected_schema, schema)
fake_obj = self.FakeComplexObject(