def test_get_class_metadata(self): class NoDoc: pass self.assertEqual(get_class_metadata(NoDoc), (None, None)) class EmptyDoc1: "" self.assertEqual(get_class_metadata(EmptyDoc1), (None, None)) class EmptyDoc2: """ """ self.assertEqual(get_class_metadata(EmptyDoc2), (None, None)) class EmptyBoth: """ """ self.assertEqual(get_class_metadata(EmptyBoth), (None, None)) class TitleOnly1: """title only""" self.assertEqual(get_class_metadata(TitleOnly1), ("title only", None)) class TitleOnly2: """title only """ self.assertEqual(get_class_metadata(TitleOnly2), ("title only", None)) class TitleOnly3: """ title only """ self.assertEqual(get_class_metadata(TitleOnly3), ("title only", None)) class AllOfThem1: """title description""" self.assertEqual(get_class_metadata(AllOfThem1), ("title", "description")) class AllOfThem2: """ title description""" self.assertEqual(get_class_metadata(AllOfThem2), ("title", "description")) class AllOfThem3: """ title description """ self.assertEqual(get_class_metadata(AllOfThem3), ("title", "description"))
def _generate_json_schema(self): json_schema = { 'type': 'object', 'properties': {}, 'required': [], 'additionalProperties': False } title, desc = get_class_metadata(self) if title: json_schema['title'] = title if desc: json_schema['description'] = desc for name, prop in self._untt_properties.items(): json_schema['properties'][name] = prop.json_schema if prop.default is Ellipsis: json_schema['required'].append(name) if not json_schema['required']: del json_schema['required'] return json_schema
def _define_root_schema(self, ptype): class_title, class_desc = get_class_metadata(ptype) self._untt_root_def = { 'type': 'string', 'enum': [e.name for e in ptype], } if class_title: self._untt_root_def['title'] = class_title if class_desc: self._untt_root_def['description'] = class_desc add_root_definition(ptype.__name__, self._untt_root_def)