openapi-core icon indicating copy to clipboard operation
openapi-core copied to clipboard

[Question]: Is there a way to disable ServerNotFound check

Open vamsi245 opened this issue 5 years ago • 3 comments

i noticed that if the URL in the request is not one of the listed URLs in the Spec, the validator throws an ServerNotFound exception.

Is there any config that I can pause to the validator to disable this check? We want to use the validator only to validate the request body.

    spec = create_spec(spec_dict)
    openapi_request = FlaskOpenAPIRequest(request)
    validator = RequestValidator(spec)
    result = validator.validate(openapi_request)

vamsi245 avatar Jul 30 '20 20:07 vamsi245

Hi @vamsi245

There is no such configuration. You can use _validate_body for now.

result = validator._validate_body(openapi_request)

p1c2u avatar Jul 31 '20 10:07 p1c2u

_validate_body does not seem to work, it raises on _find_path. It is kinda blocking for local integration tests, unfortunately

upcFrost avatar Jun 04 '21 09:06 upcFrost

I use such middleware in a local environment. It's not very safe, but it works for me.

class SetHostToLocalhost(MiddlewareMixin):
    """
    Sets the remote host to the local host to bypass OpenAPI-core servers validation.
    
    For detaisl, see: https://github.com/python-openapi/openapi-core/issues/264
    """

    def process_request(self, request):
        request.META['HTTP_HOST'] = '127.0.0.1:8080'

mik-laj avatar Apr 24 '24 13:04 mik-laj