mirror of
https://github.com/correl/openapi-core.git
synced 2024-12-29 11:09:25 +00:00
Merge pull request #180 from p1c2u/fix/flake-check-fixes
Flake8 check fixes
This commit is contained in:
commit
6f9200eada
15 changed files with 65 additions and 39 deletions
|
@ -1,6 +1,4 @@
|
|||
"""OpenAPI core contrib flask responses module"""
|
||||
import re
|
||||
|
||||
from openapi_core.validation.response.datatypes import OpenAPIResponse
|
||||
|
||||
|
||||
|
|
|
@ -13,4 +13,5 @@ class MimeTypeNotFound(OpenAPIContentError):
|
|||
availableMimetypes = attr.ib()
|
||||
|
||||
def __str__(self):
|
||||
return "Mimetype not found: {0}. Valid mimetypes: {1}".format(self.mimetype, self.availableMimetypes)
|
||||
return "Mimetype not found: {0}. Valid mimetypes: {1}".format(
|
||||
self.mimetype, self.availableMimetypes)
|
||||
|
|
|
@ -20,4 +20,5 @@ class InvalidContentType(OpenAPIMediaTypeError):
|
|||
mimetype = attr.ib()
|
||||
|
||||
def __str__(self):
|
||||
return "Content for following mimetype not found: {0}".format(self.mimetype)
|
||||
return "Content for following mimetype not found: {0}".format(
|
||||
self.mimetype)
|
||||
|
|
|
@ -58,6 +58,7 @@ class MediaType(object):
|
|||
raise InvalidMediaTypeValue(exc)
|
||||
|
||||
try:
|
||||
return self.schema.unmarshal(value, custom_formatters=custom_formatters)
|
||||
return self.schema.unmarshal(
|
||||
value, custom_formatters=custom_formatters)
|
||||
except UnmarshalError as exc:
|
||||
raise InvalidMediaTypeValue(exc)
|
||||
|
|
|
@ -17,7 +17,8 @@ class MissingParameter(MissingParameterError):
|
|||
name = attr.ib()
|
||||
|
||||
def __str__(self):
|
||||
return "Missing parameter (without default value): {0}".format(self.name)
|
||||
return "Missing parameter (without default value): {0}".format(
|
||||
self.name)
|
||||
|
||||
|
||||
@attr.s(hash=True)
|
||||
|
@ -42,4 +43,5 @@ class InvalidParameterValue(OpenAPIParameterError):
|
|||
original_exception = attr.ib()
|
||||
|
||||
def __str__(self):
|
||||
return "Invalid parameter value for `{0}`: {1}".format(self.name, self.original_exception)
|
||||
return "Invalid parameter value for `{0}`: {1}".format(
|
||||
self.name, self.original_exception)
|
||||
|
|
|
@ -13,7 +13,8 @@ class InvalidResponse(OpenAPIResponseError):
|
|||
responses = attr.ib()
|
||||
|
||||
def __str__(self):
|
||||
return "Unknown response http status: {0}".format(str(self.http_status))
|
||||
return "Unknown response http status: {0}".format(
|
||||
str(self.http_status))
|
||||
|
||||
|
||||
@attr.s(hash=True)
|
||||
|
|
|
@ -82,10 +82,10 @@ def is_datetime(instance):
|
|||
return False
|
||||
if not isinstance(instance, text_type):
|
||||
return True
|
||||
|
||||
|
||||
if DATETIME_HAS_STRICT_RFC3339:
|
||||
return strict_rfc3339.validate_rfc3339(instance)
|
||||
|
||||
|
||||
if DATETIME_HAS_ISODATE:
|
||||
return isodate.parse_datetime(instance)
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from jsonschema._types import (
|
||||
TypeChecker, is_any, is_array, is_bool, is_integer,
|
||||
TypeChecker, is_array, is_bool, is_integer,
|
||||
is_object, is_number,
|
||||
)
|
||||
from six import text_type, binary_type
|
||||
|
|
|
@ -101,7 +101,7 @@ class FormatterNotFoundError(UnmarshallerError):
|
|||
class UnmarshallerStrictTypeError(UnmarshallerError):
|
||||
value = attr.ib()
|
||||
types = attr.ib()
|
||||
|
||||
|
||||
def __str__(self):
|
||||
types = ', '.join(list(map(str, self.types)))
|
||||
return "Value {value} is not one of types: {types}".format(
|
||||
|
|
|
@ -100,20 +100,38 @@ class SchemaDictFactory(object):
|
|||
Contribution('required', dest_default=[]),
|
||||
Contribution('default'),
|
||||
Contribution('nullable', dest_default=False),
|
||||
Contribution('all_of', dest_prop_name='allOf', is_list=True, dest_default=[]),
|
||||
Contribution('one_of', dest_prop_name='oneOf', is_list=True, dest_default=[]),
|
||||
Contribution('additional_properties', dest_prop_name='additionalProperties', dest_default=True),
|
||||
Contribution(
|
||||
'all_of',
|
||||
dest_prop_name='allOf', is_list=True, dest_default=[],
|
||||
),
|
||||
Contribution(
|
||||
'one_of',
|
||||
dest_prop_name='oneOf', is_list=True, dest_default=[],
|
||||
),
|
||||
Contribution(
|
||||
'additional_properties',
|
||||
dest_prop_name='additionalProperties', dest_default=True,
|
||||
),
|
||||
Contribution('min_items', dest_prop_name='minItems'),
|
||||
Contribution('max_items', dest_prop_name='maxItems'),
|
||||
Contribution('min_length', dest_prop_name='minLength'),
|
||||
Contribution('max_length', dest_prop_name='maxLength'),
|
||||
Contribution('pattern', src_prop_attr='pattern'),
|
||||
Contribution('unique_items', dest_prop_name='uniqueItems', dest_default=False),
|
||||
Contribution(
|
||||
'unique_items',
|
||||
dest_prop_name='uniqueItems', dest_default=False,
|
||||
),
|
||||
Contribution('minimum'),
|
||||
Contribution('maximum'),
|
||||
Contribution('multiple_of', dest_prop_name='multipleOf'),
|
||||
Contribution('exclusive_minimum', dest_prop_name='exclusiveMinimum', dest_default=False),
|
||||
Contribution('exclusive_maximum', dest_prop_name='exclusiveMaximum', dest_default=False),
|
||||
Contribution(
|
||||
'exclusive_minimum',
|
||||
dest_prop_name='exclusiveMinimum', dest_default=False,
|
||||
),
|
||||
Contribution(
|
||||
'exclusive_maximum',
|
||||
dest_prop_name='exclusiveMaximum', dest_default=False,
|
||||
),
|
||||
Contribution('min_properties', dest_prop_name='minProperties'),
|
||||
Contribution('max_properties', dest_prop_name='maxProperties'),
|
||||
)
|
||||
|
|
|
@ -3,25 +3,20 @@ import attr
|
|||
import functools
|
||||
import logging
|
||||
from collections import defaultdict
|
||||
from datetime import date, datetime
|
||||
from uuid import UUID
|
||||
import re
|
||||
import warnings
|
||||
|
||||
from six import iteritems, integer_types, binary_type, text_type
|
||||
from six import iteritems
|
||||
from jsonschema.exceptions import ValidationError
|
||||
|
||||
from openapi_core.extensions.models.factories import ModelFactory
|
||||
from openapi_core.schema.schemas._format import oas30_format_checker
|
||||
from openapi_core.schema.schemas.enums import SchemaFormat, SchemaType
|
||||
from openapi_core.schema.schemas.enums import SchemaType
|
||||
from openapi_core.schema.schemas.exceptions import (
|
||||
CastError, InvalidSchemaValue,
|
||||
UnmarshallerError, UnmarshalValueError, UnmarshalError,
|
||||
)
|
||||
from openapi_core.schema.schemas.util import (
|
||||
forcebool, format_date, format_datetime, format_byte, format_uuid,
|
||||
format_number,
|
||||
UnmarshalValueError, UnmarshalError,
|
||||
)
|
||||
from openapi_core.schema.schemas.util import forcebool
|
||||
from openapi_core.schema.schemas.validators import OAS30Validator
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
@ -172,8 +167,9 @@ class Schema(object):
|
|||
for t, u in primitive_unmarshallers.items()
|
||||
)
|
||||
|
||||
pass_defaults = lambda f: functools.partial(
|
||||
f, custom_formatters=custom_formatters, strict=strict)
|
||||
def pass_defaults(f):
|
||||
return functools.partial(
|
||||
f, custom_formatters=custom_formatters, strict=strict)
|
||||
mapping = self.DEFAULT_UNMARSHAL_CALLABLE_GETTER.copy()
|
||||
mapping.update(primitive_unmarshallers_partial)
|
||||
mapping.update({
|
||||
|
@ -186,7 +182,9 @@ class Schema(object):
|
|||
|
||||
def get_validator(self, resolver=None):
|
||||
return OAS30Validator(
|
||||
self.__dict__, resolver=resolver, format_checker=oas30_format_checker)
|
||||
self.__dict__,
|
||||
resolver=resolver, format_checker=oas30_format_checker,
|
||||
)
|
||||
|
||||
def validate(self, value, resolver=None):
|
||||
validator = self.get_validator(resolver=resolver)
|
||||
|
@ -254,7 +252,8 @@ class Schema(object):
|
|||
result = None
|
||||
for subschema in self.one_of:
|
||||
try:
|
||||
unmarshalled = subschema.unmarshal(value, custom_formatters)
|
||||
unmarshalled = subschema.unmarshal(
|
||||
value, custom_formatters)
|
||||
except UnmarshalError:
|
||||
continue
|
||||
else:
|
||||
|
@ -278,9 +277,11 @@ class Schema(object):
|
|||
log.warning("failed to unmarshal any type")
|
||||
return value
|
||||
|
||||
def _unmarshal_collection(self, value, custom_formatters=None, strict=True):
|
||||
def _unmarshal_collection(
|
||||
self, value, custom_formatters=None, strict=True):
|
||||
if not isinstance(value, (list, tuple)):
|
||||
raise ValueError("Invalid value for collection: {0}".format(value))
|
||||
raise ValueError(
|
||||
"Invalid value for collection: {0}".format(value))
|
||||
|
||||
f = functools.partial(
|
||||
self.items.unmarshal,
|
||||
|
@ -300,7 +301,9 @@ class Schema(object):
|
|||
for one_of_schema in self.one_of:
|
||||
try:
|
||||
unmarshalled = self._unmarshal_properties(
|
||||
value, one_of_schema, custom_formatters=custom_formatters)
|
||||
value, one_of_schema,
|
||||
custom_formatters=custom_formatters,
|
||||
)
|
||||
except (UnmarshalError, ValueError):
|
||||
pass
|
||||
else:
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from six import text_type, binary_type, integer_types
|
||||
|
||||
from openapi_core.schema.schemas.enums import SchemaFormat, SchemaType
|
||||
from openapi_core.schema.schemas.enums import SchemaFormat
|
||||
from openapi_core.schema.schemas.exceptions import (
|
||||
InvalidCustomFormatSchemaValue,
|
||||
UnmarshallerStrictTypeError,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from jsonschema import _legacy_validators, _format, _types, _utils, _validators
|
||||
from jsonschema import _legacy_validators, _utils, _validators
|
||||
from jsonschema.validators import create
|
||||
|
||||
from openapi_core.schema.schemas import _types as oas_types
|
||||
|
@ -56,7 +56,7 @@ class OAS30Validator(BaseOAS30Validator):
|
|||
|
||||
def iter_errors(self, instance, _schema=None):
|
||||
if _schema is None:
|
||||
_schema = self.schema
|
||||
_schema = self.schema
|
||||
|
||||
# append defaults to trigger validator (i.e. nullable)
|
||||
if 'nullable' not in _schema:
|
||||
|
|
|
@ -14,7 +14,8 @@ log = logging.getLogger(__name__)
|
|||
class Spec(object):
|
||||
"""Represents an OpenAPI Specification for a service."""
|
||||
|
||||
def __init__(self, info, paths, servers=None, components=None, _resolver=None):
|
||||
def __init__(
|
||||
self, info, paths, servers=None, components=None, _resolver=None):
|
||||
self.info = info
|
||||
self.paths = paths and dict(paths)
|
||||
self.servers = servers or []
|
||||
|
|
|
@ -48,4 +48,4 @@ django = django>=2.2; python_version>="3.0"
|
|||
flask = werkzeug
|
||||
|
||||
[tool:pytest]
|
||||
addopts = -sv --flake8 --junitxml reports/junit.xml --cov openapi_core --cov-report term-missing --cov-report xml:reports/coverage.xml tests
|
||||
addopts = -sv --flake8 --junitxml reports/junit.xml --cov openapi_core --cov-report term-missing --cov-report xml:reports/coverage.xml
|
||||
|
|
Loading…
Reference in a new issue