python-openapi / openapi-spec-validator

OpenAPI Spec Validator is a CLI, pre-commit hook and python package that validates OpenAPI Specs against the OpenAPI 2.0 (aka Swagger), OpenAPI 3.0 and OpenAPI 3.1 specification.
Apache License 2.0
337 stars 62 forks source link

Test failure with openapi-schema-validator 0.4.2 #189

Closed musicinmybrain closed 1 year ago

musicinmybrain commented 1 year ago
==================================================== FAILURES ====================================================
___________________ TestSpecValidatorIterErrors.test_parameter_custom_format_checker_not_found ___________________

self = <test_exceptions.TestSpecValidatorIterErrors object at 0x7f950b421d90>
validator_v30 = <Proxy at 0x7f950b6cf540 wrapping <openapi_spec_validator.validation.validators.SpecValidator object at 0x7f950bbdd190...bHandler object at 0x7f950bae7910>, 'file': <jsonschema_spec.handlers.urllib.UrllibHandler object at 0x7f950bae7890>})>

    def test_parameter_custom_format_checker_not_found(self, validator_v30):
        spec = {
            "openapi": "3.0.0",
            "info": {
                "title": "Test Api",
                "version": "0.0.1",
            },  
            "paths": {
                "/test/": {
                    "get": {
                        "responses": {
                            "default": {
                                "description": "default response",
                            },  
                        },  
                        "parameters": [
                            {
                                "name": "param1",
                                "in": "query",
                                "schema": {
                                    "type": "string",
                                    "format": "custom",
                                    "default": "customvalue",
                                },
                            },
                        ],
                    },
                },
            },
        }

        errors = validator_v30.iter_errors(spec)

        errors_list = list(errors)
>       assert len(errors_list) == 1
E       assert 0 == 1
E        +  where 0 = len([])

errors     = <generator object SpecValidator.iter_errors at 0x7f950b52b040>
errors_list = []
self       = <test_exceptions.TestSpecValidatorIterErrors object at 0x7f950b421d90>
spec       = {'info': {'title': 'Test Api', 'version': '0.0.1'}, 'openapi': '3.0.0', 'paths': {'/test/': {'get': {'parameters': [{'in': 'query', 'name': 'param1', 'schema': {...}}], 'responses': {'default': {'description': 'default response'}}}}}}
validator_v30 = <Proxy at 0x7f950b6cf540 wrapping <openapi_spec_validator.validation.validators.SpecValidator object at 0x7f950bbdd190...bHandler object at 0x7f950bae7910>, 'file': <jsonschema_spec.handlers.urllib.UrllibHandler object at 0x7f950bae7890>})>

tests/integration/validation/test_exceptions.py:457: AssertionError
p1c2u commented 1 year ago

Hi @musicinmybrain

Thank you for reporting the problem. The test was reproducing the issue that FormatError was raised when there was no format checker for such format. Test test should be fixed now.