def merge(self, other, ctx, exclude=[]):
        """ merge properties from other object,
        - for child object, only merge from 'not-default' to 'default'.
        - for others, merge (list, dict, primitives)

        :param BaseObj other: the source object to be merged from.
        :param Context ctx: the parsing context
        """
        def _produce_new_obj(x, ct, v):
            return x(None, None).produce().merge(v, x)

        for name, default in itertools.chain(
                six.iteritems(self.__swagger_fields__),
                six.iteritems(self.__internal_fields__)):
            if name in exclude:
                continue

            v = getattr(other, name)
            if v == default:
                continue

            childs = [(n, ct, cctx) for n, (ct, cctx) in six.iteritems(ctx.__swagger_child__) if n == name]
            if len(childs) == 0:
                # we don't need to make a copy,
                # since everything under App should be
                # readonly.
                if isinstance(v, list):
                    try:
                        self.update_field(name, list(set((getattr(self, name) or []) + v)))
                    except TypeError:
                        self.update_field(name, list((getattr(self, name) or []) + v))
                elif isinstance(v, dict):
                    d = copy.copy(v)
                    d.update(getattr(self, name) or {})
                    self.update_field(name, d)
                elif getattr(self, name) == default:
                    self.update_field(name, v)
                continue
            else:
                # for child, stop when src object has something
                if getattr(self, name) != default:
                    continue

            ct, cctx = childs[0][1], childs[0][2]
            self.update_field(name,
                container_apply(
                    ct, v, 
                    functools.partial(_produce_new_obj, cctx)
            ))

        # make sure parent is correctly assigned.
        self._assign_parent(ctx)

        # allow cascade calling
        return self
def merge ( self , other , ctx , exclude = [ ] ) : def _produce_new_obj ( x , ct , v ) : return x ( None , None ) . produce ( ) . merge ( v , x ) for name , default in itertools . chain ( six . iteritems ( self . __swagger_fields__ ) , six . iteritems ( self . __internal_fields__ ) ) : if name in exclude : continue v = getattr ( other , name ) if v == default : continue childs = [ ( n , ct , cctx ) for n , ( ct , cctx ) in six . iteritems ( ctx . __swagger_child__ ) if n == name ] if len ( childs ) == 0 : if isinstance ( v , list ) : try : self . update_field ( name , list ( set ( ( getattr ( self , name ) or [ ] ) + v ) ) ) except TypeError : self . update_field ( name , list ( ( getattr ( self , name ) or [ ] ) + v ) ) elif isinstance ( v , dict ) : d = copy . copy ( v ) d . update ( getattr ( self , name ) or { } ) self . update_field ( name , d ) elif getattr ( self , name ) == default : self . update_field ( name , v ) continue else : if getattr ( self , name ) != default : continue ct , cctx = childs [ 0 ] [ 1 ] , childs [ 0 ] [ 2 ] self . update_field ( name , container_apply ( ct , v , functools . partial ( _produce_new_obj , cctx ) ) ) self . _assign_parent ( ctx ) return self
merge properties from other object,
        - for child object, only merge from 'not-default' to 'default'.
        - for others, merge (list, dict, primitives)

        :param BaseObj other: the source object to be merged from.
        :param Context ctx: the parsing context