Ejemplo n.º 1
0
    def _unmarshal_object(self, value):
        if not isinstance(value, (dict, )):
            raise InvalidSchemaValue(
                "Value of {0} not an object".format(value))

        if self.one_of:
            properties = None
            for one_of_schema in self.one_of:
                try:
                    found_props = self._unmarshal_properties(
                        value, one_of_schema)
                except OpenAPISchemaError:
                    pass
                else:
                    if properties is not None:
                        raise MultipleOneOfSchema(
                            "Exactly one schema should be valid,"
                            "multiple found")
                    properties = found_props

            if properties is None:
                raise NoOneOfSchema(
                    "Exactly one valid schema should be valid, None found.")

        else:
            properties = self._unmarshal_properties(value)

        return ModelFactory().create(properties, name=self.model)
Ejemplo n.º 2
0
    def _unmarshal_object(self,
                          value,
                          model_factory=None,
                          custom_formatters=None,
                          strict=True):
        if not isinstance(value, (dict, )):
            raise InvalidSchemaValue("Value {value} is not of type {type}",
                                     value, self.type)

        model_factory = model_factory or ModelFactory()

        if self.one_of:
            properties = None
            for one_of_schema in self.one_of:
                try:
                    unmarshalled = self._unmarshal_properties(
                        value,
                        one_of_schema,
                        custom_formatters=custom_formatters)
                except OpenAPISchemaError:
                    pass
                else:
                    if properties is not None:
                        log.warning("multiple valid oneOf schemas found")
                        continue
                    properties = unmarshalled

            if properties is None:
                log.warning("valid oneOf schema not found")

        else:
            properties = self._unmarshal_properties(
                value, custom_formatters=custom_formatters)

        return model_factory.create(properties, name=self.model)
Ejemplo n.º 3
0
    def _unmarshal_object(self,
                          value,
                          model_factory=None,
                          custom_formatters=None,
                          strict=True):
        if not isinstance(value, (dict, )):
            raise ValueError("Invalid value for object: {0}".format(value))

        model_factory = model_factory or ModelFactory()

        if self.one_of:
            properties = None
            for one_of_schema in self.one_of:
                try:
                    unmarshalled = self._unmarshal_properties(
                        value,
                        one_of_schema,
                        custom_formatters=custom_formatters)
                except (UnmarshalError, ValueError):
                    pass
                else:
                    if properties is not None:
                        log.warning("multiple valid oneOf schemas found")
                        continue
                    properties = unmarshalled

            if properties is None:
                log.warning("valid oneOf schema not found")

        else:
            properties = self._unmarshal_properties(
                value, custom_formatters=custom_formatters)

        return model_factory.create(properties, name=self.model)
Ejemplo n.º 4
0
    def _unmarshal_object(self,
                          value,
                          model_factory=None,
                          custom_formatters=None):
        if not isinstance(value, (dict, )):
            raise InvalidSchemaValue("Value {value} is not of type {type}",
                                     value, self.type)

        model_factory = model_factory or ModelFactory()

        if self.one_of:
            properties = None
            for one_of_schema in self.one_of:
                try:
                    found_props = self._unmarshal_properties(
                        value,
                        one_of_schema,
                        custom_formatters=custom_formatters)
                except OpenAPISchemaError:
                    pass
                else:
                    if properties is not None:
                        raise MultipleOneOfSchema(self.type)
                    properties = found_props

            if properties is None:
                raise NoOneOfSchema(self.type)

        else:
            properties = self._unmarshal_properties(
                value, custom_formatters=custom_formatters)

        return model_factory.create(properties, name=self.model)
Ejemplo n.º 5
0
 def model_factory(self):
     return ModelFactory()