def testDetectInline(self): schema = { 'types': [ { 'id': 'Key', 'items': { '$ref': 'Value' } }, { 'id': 'Value', 'marker': True } ] } expected_schema = { 'types': [ { 'id': 'Key', 'items': { 'marker': True, } } ] } object_store_creator = ObjectStoreCreator(start_empty=False) host_file_system_provider = HostFileSystemProvider(object_store_creator) schema_processor = SchemaProcessor(_FakeReferenceResolver(), _FakeAPIModels(), _FakeFeaturesBundle(), CompiledFileSystem.Factory( object_store_creator), host_file_system_provider.GetMaster(), False) schema_processor._DetectInlineableTypes(schema) schema_processor._InlineDocs(schema) self.assertEqual(expected_schema, schema)
def testInlineDocs(self): schema = { 'namespace': 'storage', 'properties': { 'key2': { 'description': 'second key', '$ref': 'Key' }, 'key1': { 'description': 'first key', '$ref': 'Key' } }, 'types': [ { 'inline_doc': True, 'type': 'string', 'id': 'Key', # Should be inlined into both properties and be removed # from types. 'description': 'This is a key.', # This description should disappear. 'marker': True # This should appear three times in the output. }, { 'items': { '$ref': 'Key' }, 'type': 'array', 'id': 'KeyList', 'description': 'A list of keys' } ] } expected_schema = { 'namespace': 'storage', 'properties': { 'key2': { 'marker': True, 'type': 'string', 'description': 'second key' }, 'key1': { 'marker': True, 'type': 'string', 'description': 'first key' } }, 'types': [ { 'items': { 'marker': True, 'type': 'string' }, 'type': 'array', 'id': 'KeyList', 'description': 'A list of keys' } ] } object_store_creator = ObjectStoreCreator(start_empty=False) host_file_system_provider = HostFileSystemProvider(object_store_creator) schema_processor = SchemaProcessor(_FakeReferenceResolver(), _FakeAPIModels(), _FakeFeaturesBundle(), CompiledFileSystem.Factory( object_store_creator), host_file_system_provider.GetMaster(), False) inlined_schema = deepcopy(schema) schema_processor._InlineDocs(inlined_schema) self.assertEqual(expected_schema, inlined_schema)