mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-18 21:47:04 +00:00
[python-experimental] implement in operator for model classes (#7637)
* implement operator for model classes * refresh samples
This commit is contained in:
@@ -316,6 +316,14 @@ class ModelSimple(OpenApiModel):
|
||||
[name]
|
||||
)
|
||||
|
||||
def __contains__(self, name):
|
||||
"""this allows us to use `in` operator: `'attr' in instance`"""
|
||||
if name in self.required_properties:
|
||||
return name in self.__dict__
|
||||
|
||||
return name in self.__dict__['_data_store']
|
||||
|
||||
|
||||
def to_str(self):
|
||||
"""Returns the string representation of the model"""
|
||||
return str(self.value)
|
||||
@@ -364,6 +372,14 @@ class ModelNormal(OpenApiModel):
|
||||
[name]
|
||||
)
|
||||
|
||||
def __contains__(self, name):
|
||||
"""this allows us to use `in` operator: `'attr' in instance`"""
|
||||
if name in self.required_properties:
|
||||
return name in self.__dict__
|
||||
|
||||
return name in self.__dict__['_data_store']
|
||||
|
||||
|
||||
def to_dict(self):
|
||||
"""Returns the model properties as a dict"""
|
||||
return model_to_dict(self, serialize=False)
|
||||
@@ -488,6 +504,23 @@ class ModelComposed(OpenApiModel):
|
||||
path_to_item
|
||||
)
|
||||
|
||||
def __contains__(self, name):
|
||||
"""this allows us to use `in` operator: `'attr' in instance`"""
|
||||
|
||||
if name in self.required_properties:
|
||||
return name in self.__dict__
|
||||
|
||||
model_instances = self._var_name_to_model_instances.get(
|
||||
name, self._additional_properties_model_instances)
|
||||
|
||||
if model_instances:
|
||||
for model_instance in model_instances:
|
||||
if name in model_instance._data_store:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def to_dict(self):
|
||||
"""Returns the model properties as a dict"""
|
||||
return model_to_dict(self, serialize=False)
|
||||
|
||||
Reference in New Issue
Block a user