forked from loafle/openapi-generator-original
[Python] Improve model equality implementation (#4663)
* [Python] Improve model equality implementation The model equality implementation template blindly tried accessing the `__dict__` attribute of the variable to compare equality against. This attribute does not exist for a lot of Python built-in types (`None`, `str` etc.) and the equality check would simply crash. This adds a simple guard to only continue with equality check if the variable to compare is an instance of the model being compared against. * Remove wrong auto-update of Python requirements
This commit is contained in:
parent
869374125f
commit
3236ade09d
@ -172,6 +172,9 @@ class {{classname}}(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, {{classname}}):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
@ -5,7 +5,7 @@ This Python package is automatically generated by the [Swagger Codegen](https://
|
||||
|
||||
- API version: 1.0.0 */ ' \" =end -- \\r\\n \\n \\r
|
||||
- Package version: 1.0.0
|
||||
- Build package: class io.swagger.codegen.languages.PythonClientCodegen
|
||||
- Build package: io.swagger.codegen.languages.PythonClientCodegen
|
||||
|
||||
## Requirements.
|
||||
|
||||
|
@ -116,7 +116,7 @@ class ApiClient(object):
|
||||
collection_formats)
|
||||
for k, v in path_params:
|
||||
resource_path = resource_path.replace(
|
||||
'{%s}' % k, quote(str(v)))
|
||||
'{%s}' % k, quote(str(v), safe=""))
|
||||
|
||||
# query parameters
|
||||
if query_params:
|
||||
|
@ -116,12 +116,9 @@ class FakeApi(object):
|
||||
form_params.append(('test code inject */ ' " =end -- \r\n \n \r', params['test_code_inject____end____rn_n_r']))
|
||||
|
||||
body_params = None
|
||||
|
||||
# HTTP header `Accept`
|
||||
header_params['Accept'] = self.api_client.\
|
||||
select_header_accept(['application/json', '*/ \" =end -- '])
|
||||
if not header_params['Accept']:
|
||||
del header_params['Accept']
|
||||
|
||||
# HTTP header `Content-Type`
|
||||
header_params['Content-Type'] = self.api_client.\
|
||||
|
@ -105,6 +105,9 @@ class ModelReturn(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, ModelReturn):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
@ -127,6 +127,9 @@ class AdditionalPropertiesClass(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, AdditionalPropertiesClass):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
@ -129,6 +129,9 @@ class Animal(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, Animal):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
@ -81,6 +81,9 @@ class AnimalFarm(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, AnimalFarm):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
@ -151,6 +151,9 @@ class ApiResponse(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, ApiResponse):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
@ -103,6 +103,9 @@ class ArrayOfArrayOfNumberOnly(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, ArrayOfArrayOfNumberOnly):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
@ -103,6 +103,9 @@ class ArrayOfNumberOnly(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, ArrayOfNumberOnly):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
@ -151,6 +151,9 @@ class ArrayTest(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, ArrayTest):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
@ -225,6 +225,9 @@ class Capitalization(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, Capitalization):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
@ -153,6 +153,9 @@ class Cat(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, Cat):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
@ -127,6 +127,9 @@ class Category(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, Category):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
@ -103,6 +103,9 @@ class ClassModel(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, ClassModel):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
@ -103,6 +103,9 @@ class Client(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, Client):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
@ -153,6 +153,9 @@ class Dog(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, Dog):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
@ -140,6 +140,9 @@ class EnumArrays(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, EnumArrays):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
@ -81,6 +81,9 @@ class EnumClass(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, EnumClass):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
@ -193,6 +193,9 @@ class EnumTest(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, EnumTest):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
@ -425,6 +425,9 @@ class FormatTest(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, FormatTest):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
@ -127,6 +127,9 @@ class HasOnlyReadOnly(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, HasOnlyReadOnly):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
@ -103,6 +103,9 @@ class List(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, List):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
@ -134,6 +134,9 @@ class MapTest(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, MapTest):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
@ -151,6 +151,9 @@ class MixedPropertiesAndAdditionalPropertiesClass(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, MixedPropertiesAndAdditionalPropertiesClass):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
@ -127,6 +127,9 @@ class Model200Response(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, Model200Response):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
@ -103,6 +103,9 @@ class ModelReturn(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, ModelReturn):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
@ -177,6 +177,9 @@ class Name(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, Name):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
@ -103,6 +103,9 @@ class NumberOnly(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, NumberOnly):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
@ -231,6 +231,9 @@ class Order(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, Order):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
@ -81,6 +81,9 @@ class OuterEnum(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, OuterEnum):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
@ -235,6 +235,9 @@ class Pet(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, Pet):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
@ -127,6 +127,9 @@ class ReadOnlyFirst(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, ReadOnlyFirst):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
@ -103,6 +103,9 @@ class SpecialModelName(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, SpecialModelName):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
@ -127,6 +127,9 @@ class Tag(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, Tag):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
@ -273,6 +273,9 @@ class User(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, User):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
Loading…
x
Reference in New Issue
Block a user