Esempio n. 1
0
    def _unmarshal_collection(self, value, custom_formatters=None):
        if self.items is None:
            raise UndefinedItemsSchema(self.type)

        f = functools.partial(self.items.unmarshal,
                              custom_formatters=custom_formatters)
        return list(map(f, value))
Esempio n. 2
0
    def _validate_collection(self, value, custom_formatters=None):
        if self.items is None:
            raise UndefinedItemsSchema(self.type)

        if self.min_items is not None:
            if self.min_items < 0:
                raise OpenAPISchemaError("Schema for collection invalid:"
                                         " minItems must be non-negative")
            if len(value) < self.min_items:
                raise InvalidSchemaValue(
                    "Value must contain at least {type} item(s),"
                    " {value} found", len(value), self.min_items)
        if self.max_items is not None:
            if self.max_items < 0:
                raise OpenAPISchemaError("Schema for collection invalid:"
                                         " maxItems must be non-negative")
            if len(value) > self.max_items:
                raise InvalidSchemaValue(
                    "Value must contain at most {value} item(s),"
                    " {type} found", len(value), self.max_items)
        if self.unique_items and len(set(value)) != len(value):
            raise OpenAPISchemaError("Value may not contain duplicate items")

        f = functools.partial(self.items.validate,
                              custom_formatters=custom_formatters)
        return list(map(f, value))
Esempio n. 3
0
    def _unmarshal_collection(self, value, custom_formatters=None, strict=True):
        if not isinstance(value, (list, tuple)):
            raise InvalidSchemaValue("Value {value} is not of type {type}", value, self.type)

        if self.items is None:
            raise UndefinedItemsSchema(self.type)

        f = functools.partial(
            self.items.unmarshal,
            custom_formatters=custom_formatters, strict=strict,
        )
        return list(map(f, value))
Esempio n. 4
0
    def _unmarshal_collection(self, value):
        if self.items is None:
            raise UndefinedItemsSchema("Undefined items' schema")

        return list(map(self.items.unmarshal, value))