def parse_all_of( self, name: str, obj: JsonSchemaObject, path: List[str], ignore_duplicate_model: bool = False, ) -> DataType: fields: List[DataModelFieldBase] = [] base_classes: List[Reference] = [] if len(obj.allOf) == 1 and not obj.properties: single_obj = obj.allOf[0] if single_obj.ref and single_obj.ref_type == JSONReference.LOCAL: if get_model_by_path( self.raw_obj, single_obj.ref[2:].split('/')).get('enum'): return self.get_ref_data_type(single_obj.ref) for all_of_item in obj.allOf: if all_of_item.ref: # $ref base_classes.append( self.model_resolver.add_ref(all_of_item.ref)) else: fields.extend( self.parse_object_fields( all_of_item, path, get_module_name(name, None), )) if obj.properties: fields.extend( self.parse_object_fields(obj, path, get_module_name(name, None))) # ignore an undetected object if ignore_duplicate_model and not fields and len(base_classes) == 1: return self.data_type(reference=base_classes[0]) if self.use_title_as_name and obj.title: name = obj.title reference = self.model_resolver.add(path, name, class_name=True, loaded=True) self.set_additional_properties(reference.name, obj) data_model_type = self.data_model_type( reference=reference, fields=fields, base_classes=base_classes, custom_base_class=self.base_class, custom_template_dir=self.custom_template_dir, extra_template_data=self.extra_template_data, path=self.current_source_path, description=obj.description if self.use_schema_description else None, ) self.results.append(data_model_type) return self.data_type(reference=reference)
def parse_object( self, name: str, obj: JsonSchemaObject, path: List[str], singular_name: bool = False, unique: bool = True, ) -> DataType: if not unique: # pragma: no cover warn( f'{self.__class__.__name__}.parse_object() ignore `unique` argument.' f'An object name must be unique.' f'This argument will be removed in a future version' ) reference = self.model_resolver.add( path, name, class_name=True, singular_name=singular_name, loaded=True, ) class_name = reference.name self.set_title(class_name, obj) self.set_additional_properties(class_name, obj) data_model_type = self.data_model_type( reference=reference, fields=self.parse_object_fields( obj, path, get_module_name(class_name, None) ), custom_base_class=self.base_class, custom_template_dir=self.custom_template_dir, extra_template_data=self.extra_template_data, path=self.current_source_path, description=obj.description if self.use_schema_description else None, ) self.results.append(data_model_type) return self.data_type(reference=reference)