Skip to content

Property defined with default value not assigned default value #127

@jeremyschulman

Description

@jeremyschulman

I have a toplevel object schema-definition that, within the "properties" dict, has a item that is defined as:

   "operation_mode": {
      "default": "fullControl", 
      "x-scope": [
         "https://172.20.20.3"
      ], 
      "$ref": "#/definitions/Type2"
   }

And the Type2 definition is defined as:

{
   "enum": [
      "telemetryOnly", 
      "fullControl"
   ], 
   "type": "string",
}

When I attempt to build the toplevel object schema, the library is attempting to initialize this value to None, per this code. As a result, an exception is raised because this value must be in the enum list, and not None.

Perhaps I have my schema wrong; so if there is something I should correct please do let me know.

I've patched my local copy of this library to change the default setting value to:

    def __init__(self, **props):
        self._extended_properties = dict()
        self._properties = dict(zip(self.__prop_names__.values(),
                                    [None for x in
                                     six.moves.xrange(len(self.__prop_names__))]))

        # To support defaults, we have to actually execute the constructors
        # but only for the ones that have defaults set.
        for name in self.__has_default__:
            if name not in props:
                default_value = self.__propinfo__[name]['default']
                logger.debug(util.lazy_format("Initializing '{0}' to '{1}'", name, default_value))
                setattr(self, name, default_value)

If this is the "proper fix", then I would be happy to make a pull-request with this fix.

Please advise.

Thank you!
-- Jeremy

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions