diff --git a/openapi_core/schema/content/exceptions.py b/openapi_core/schema/content/exceptions.py index 4473ef0..7711ea0 100644 --- a/openapi_core/schema/content/exceptions.py +++ b/openapi_core/schema/content/exceptions.py @@ -1,13 +1,13 @@ -from openapi_core.schema.exceptions import OpenAPIMappingError - import attr +from openapi_core.schema.exceptions import OpenAPIMappingError + class OpenAPIContentError(OpenAPIMappingError): pass -@attr.s +@attr.s(hash=True) class MimeTypeNotFound(OpenAPIContentError): mimetype = attr.ib() availableMimetypes = attr.ib() diff --git a/openapi_core/schema/content/models.py b/openapi_core/schema/content/models.py index 1cabec1..4af6ed8 100644 --- a/openapi_core/schema/content/models.py +++ b/openapi_core/schema/content/models.py @@ -18,4 +18,4 @@ class Content(dict): if fnmatch.fnmatch(mimetype, key): return value - raise MimeTypeNotFound(mimetype, self.keys()) + raise MimeTypeNotFound(mimetype, list(self.keys())) diff --git a/openapi_core/schema/media_types/exceptions.py b/openapi_core/schema/media_types/exceptions.py index 97a0d85..60a0c20 100644 --- a/openapi_core/schema/media_types/exceptions.py +++ b/openapi_core/schema/media_types/exceptions.py @@ -1,19 +1,21 @@ -from openapi_core.schema.exceptions import OpenAPIMappingError - import attr +from openapi_core.schema.exceptions import OpenAPIMappingError + class OpenAPIMediaTypeError(OpenAPIMappingError): pass -@attr.s + +@attr.s(hash=True) class InvalidMediaTypeValue(OpenAPIMediaTypeError): original_exception = attr.ib() def __str__(self): return "Mimetype invalid: {0}".format(self.original_exception) -@attr.s + +@attr.s(hash=True) class InvalidContentType(OpenAPIMediaTypeError): mimetype = attr.ib() diff --git a/openapi_core/schema/operations/exceptions.py b/openapi_core/schema/operations/exceptions.py index 30118b6..e78708a 100644 --- a/openapi_core/schema/operations/exceptions.py +++ b/openapi_core/schema/operations/exceptions.py @@ -1,13 +1,13 @@ -from openapi_core.schema.exceptions import OpenAPIMappingError - import attr +from openapi_core.schema.exceptions import OpenAPIMappingError + class OpenAPIOperationError(OpenAPIMappingError): pass -@attr.s +@attr.s(hash=True) class InvalidOperation(OpenAPIOperationError): path_pattern = attr.ib() http_method = attr.ib() diff --git a/openapi_core/schema/parameters/exceptions.py b/openapi_core/schema/parameters/exceptions.py index 853d067..bcaf13f 100644 --- a/openapi_core/schema/parameters/exceptions.py +++ b/openapi_core/schema/parameters/exceptions.py @@ -1,13 +1,13 @@ -from openapi_core.schema.exceptions import OpenAPIMappingError - import attr +from openapi_core.schema.exceptions import OpenAPIMappingError + class OpenAPIParameterError(OpenAPIMappingError): pass -@attr.s +@attr.s(hash=True) class MissingParameter(OpenAPIParameterError): name = attr.ib() @@ -15,7 +15,7 @@ class MissingParameter(OpenAPIParameterError): return "Missing parameter (without default value): {0}".format(self.name) -@attr.s +@attr.s(hash=True) class MissingRequiredParameter(OpenAPIParameterError): name = attr.ib() @@ -23,7 +23,7 @@ class MissingRequiredParameter(OpenAPIParameterError): return "Missing required parameter: {0}".format(self.name) -@attr.s +@attr.s(hash=True) class EmptyParameterValue(OpenAPIParameterError): name = attr.ib() @@ -31,7 +31,7 @@ class EmptyParameterValue(OpenAPIParameterError): return "Value of parameter cannot be empty: {0}".format(self.name) -@attr.s +@attr.s(hash=True) class InvalidParameterValue(OpenAPIParameterError): name = attr.ib() original_exception = attr.ib() diff --git a/openapi_core/schema/request_bodies/exceptions.py b/openapi_core/schema/request_bodies/exceptions.py index 3b0e618..a84937b 100644 --- a/openapi_core/schema/request_bodies/exceptions.py +++ b/openapi_core/schema/request_bodies/exceptions.py @@ -1,13 +1,13 @@ -from openapi_core.schema.exceptions import OpenAPIMappingError - import attr +from openapi_core.schema.exceptions import OpenAPIMappingError + class OpenAPIRequestBodyError(OpenAPIMappingError): pass -@attr.s +@attr.s(hash=True) class MissingRequestBody(OpenAPIRequestBodyError): request = attr.ib() diff --git a/openapi_core/schema/responses/exceptions.py b/openapi_core/schema/responses/exceptions.py index 5e196e6..9ec50ee 100644 --- a/openapi_core/schema/responses/exceptions.py +++ b/openapi_core/schema/responses/exceptions.py @@ -1,13 +1,13 @@ -from openapi_core.schema.exceptions import OpenAPIMappingError - import attr +from openapi_core.schema.exceptions import OpenAPIMappingError + class OpenAPIResponseError(OpenAPIMappingError): pass -@attr.s +@attr.s(hash=True) class InvalidResponse(OpenAPIResponseError): http_status = attr.ib() responses = attr.ib() @@ -16,7 +16,7 @@ class InvalidResponse(OpenAPIResponseError): return "Unknown response http status: {0}".format(str(self.http_status)) -@attr.s +@attr.s(hash=True) class MissingResponseContent(OpenAPIResponseError): response = attr.ib() diff --git a/openapi_core/schema/schemas/exceptions.py b/openapi_core/schema/schemas/exceptions.py index a370aac..c984578 100644 --- a/openapi_core/schema/schemas/exceptions.py +++ b/openapi_core/schema/schemas/exceptions.py @@ -1,13 +1,13 @@ -from openapi_core.schema.exceptions import OpenAPIMappingError - import attr +from openapi_core.schema.exceptions import OpenAPIMappingError + class OpenAPISchemaError(OpenAPIMappingError): pass -@attr.s +@attr.s(hash=True) class NoValidSchema(OpenAPISchemaError): value = attr.ib() @@ -15,7 +15,7 @@ class NoValidSchema(OpenAPISchemaError): return "No valid schema found for value: {0}".format(self.value) -@attr.s +@attr.s(hash=True) class UndefinedItemsSchema(OpenAPISchemaError): type = attr.ib() @@ -23,7 +23,7 @@ class UndefinedItemsSchema(OpenAPISchemaError): return "Null value for schema type {0}".format(self.type) -@attr.s +@attr.s(hash=True) class InvalidSchemaValue(OpenAPISchemaError): msg = attr.ib() value = attr.ib() @@ -32,7 +32,8 @@ class InvalidSchemaValue(OpenAPISchemaError): def __str__(self): return self.msg.format(value=self.value, type=self.type) -@attr.s + +@attr.s(hash=True) class InvalidCustomFormatSchemaValue(InvalidSchemaValue): original_exception = attr.ib() @@ -40,14 +41,15 @@ class InvalidCustomFormatSchemaValue(InvalidSchemaValue): return self.msg.format(value=self.value, type=self.type, exception=self.original_exception) -@attr.s +@attr.s(hash=True) class UndefinedSchemaProperty(OpenAPISchemaError): extra_props = attr.ib() def __str__(self): return "Extra unexpected properties found in schema: {0}".format(self.extra_props) -@attr.s + +@attr.s(hash=True) class InvalidSchemaProperty(OpenAPISchemaError): property_name = attr.ib() original_exception = attr.ib() @@ -55,7 +57,8 @@ class InvalidSchemaProperty(OpenAPISchemaError): def __str__(self): return "Invalid schema property {0}: {1}".format(self.property_name, self.original_exception) -@attr.s + +@attr.s(hash=True) class MissingSchemaProperty(OpenAPISchemaError): property_name = attr.ib() @@ -63,7 +66,7 @@ class MissingSchemaProperty(OpenAPISchemaError): return "Missing schema property: {0}".format(self.property_name) -@attr.s +@attr.s(hash=True) class NoOneOfSchema(OpenAPISchemaError): type = attr.ib() @@ -71,7 +74,7 @@ class NoOneOfSchema(OpenAPISchemaError): return "Exactly one valid schema type {0} should be valid, None found.".format(self.type) -@attr.s +@attr.s(hash=True) class MultipleOneOfSchema(OpenAPISchemaError): type = attr.ib() @@ -79,11 +82,10 @@ class MultipleOneOfSchema(OpenAPISchemaError): return "Exactly one schema type {0} should be valid, more than one found".format(self.type) -class UnmarshallerError(Exception): +class UnmarshallerError(OpenAPIMappingError): pass -@attr.s class UnmarshallerStrictTypeError(UnmarshallerError): value = attr.ib() types = attr.ib() diff --git a/openapi_core/schema/servers/exceptions.py b/openapi_core/schema/servers/exceptions.py index 1ae0d3a..b8076e9 100644 --- a/openapi_core/schema/servers/exceptions.py +++ b/openapi_core/schema/servers/exceptions.py @@ -1,13 +1,13 @@ -from openapi_core.schema.exceptions import OpenAPIMappingError - import attr +from openapi_core.schema.exceptions import OpenAPIMappingError + class OpenAPIServerError(OpenAPIMappingError): pass -@attr.s +@attr.s(hash=True) class InvalidServer(OpenAPIServerError): full_url_pattern = attr.ib() diff --git a/tests/unit/schema/test_links.py b/tests/unit/schema/test_links.py index df9f17d..346900f 100644 --- a/tests/unit/schema/test_links.py +++ b/tests/unit/schema/test_links.py @@ -40,5 +40,5 @@ class TestLinks(object): @pytest.mark.parametrize("request_body", request_body_list) def test_iteritems(self, link_factory, request_body, server): link = link_factory(request_body, server) - for par_name in link.parameters.keys(): + for par_name in link.parameters: assert link[par_name] == link.parameters[par_name] diff --git a/tests/unit/schema/test_operations.py b/tests/unit/schema/test_operations.py index bca1da4..b84ce75 100644 --- a/tests/unit/schema/test_operations.py +++ b/tests/unit/schema/test_operations.py @@ -15,7 +15,7 @@ class TestSchemas(object): return Operation('get', '/path', {}, parameters=parameters) def test_iteritems(self, operation): - for name in operation.parameters.keys(): + for name in operation.parameters: assert operation[name] == operation.parameters[name] diff --git a/tests/unit/schema/test_paths.py b/tests/unit/schema/test_paths.py index f7de1d5..bd6c83d 100644 --- a/tests/unit/schema/test_paths.py +++ b/tests/unit/schema/test_paths.py @@ -16,6 +16,6 @@ class TestPaths(object): @property def test_iteritems(self, path): - for http_method in path.operations.keys(): + for http_method in path.operations: assert path[http_method] ==\ path.operations[http_method] diff --git a/tests/unit/schema/test_request_bodies.py b/tests/unit/schema/test_request_bodies.py index d47ccd2..cf82eda 100644 --- a/tests/unit/schema/test_request_bodies.py +++ b/tests/unit/schema/test_request_bodies.py @@ -16,6 +16,6 @@ class TestRequestBodies(object): @property def test_iteritems(self, request_body): - for mimetype in request_body.content.keys(): + for mimetype in request_body.content: assert request_body[mimetype] ==\ request_body.content[mimetype] diff --git a/tests/unit/schema/test_schemas.py b/tests/unit/schema/test_schemas.py index 05dc599..0b747aa 100644 --- a/tests/unit/schema/test_schemas.py +++ b/tests/unit/schema/test_schemas.py @@ -27,7 +27,7 @@ class TestSchemaIteritems(object): @property def test_valid(self, schema): - for name in schema.properties.keys(): + for name in schema.properties: assert schema[name] == schema.properties[name] diff --git a/tests/unit/schema/test_specs.py b/tests/unit/schema/test_specs.py index cede1ca..c8a0f0d 100644 --- a/tests/unit/schema/test_specs.py +++ b/tests/unit/schema/test_specs.py @@ -32,7 +32,7 @@ class TestSpecs(object): return Spec(servers, paths) def test_iteritems(self, spec): - for path_name in spec.paths.keys(): + for path_name in spec.paths: assert spec[path_name] ==\ spec.paths[path_name]