diff --git a/datamodel_code_generator/parser/base.py b/datamodel_code_generator/parser/base.py index 0e5389758..35a0e01f1 100644 --- a/datamodel_code_generator/parser/base.py +++ b/datamodel_code_generator/parser/base.py @@ -258,15 +258,15 @@ def _find_field_and_base_classes( for field_ in model_.fields: if field_.original_name == original_name: return field_, [] - return None, _find_base_classes(model_) + return None, _find_base_classes(model_) # pragma: no cover for model in models: field, base_models = _find_field_and_base_classes(model) if field: return field - models.extend(base_models) + models.extend(base_models) # pragma: no cover - return None + return None # pragma: no cover def _copy_data_types(data_types: List[DataType]) -> List[DataType]: @@ -829,21 +829,22 @@ def __override_required_field( if isinstance(model, (Enum, self.data_model_root_type)): continue for index, model_field in enumerate(model.fields[:]): + data_type = model_field.data_type if ( not model_field.original_name - or not model_field.required - and ( - model_field.data_type.data_types - or model_field.data_type.reference - or model_field.data_type.type - ) + or data_type.data_types + or data_type.reference + or data_type.type + or data_type.literals + or data_type.dict_key ): continue original_field = _find_field( model_field.original_name, _find_base_classes(model) ) - if not original_field: + if not original_field: # pragma: no cover + model.fields.remove(model_field) continue copied_original_field = original_field.copy() if original_field.data_type.reference: