openapi-core
openapi-core copied to clipboard
[Question]: Is there a way to disable ServerNotFound check
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)
Hi @vamsi245
There is no such configuration. You can use _validate_body for now.
result = validator._validate_body(openapi_request)
_validate_body does not seem to work, it raises on _find_path. It is kinda blocking for local integration tests, unfortunately
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'