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

Werkzeug validate_request: 'request' argument is not type of Request

Open htmhmeer opened this issue 11 months ago • 4 comments

Actual Behavior

openapi_request = WerkzeugOpenAPIRequest(request) type of openapi_request: openapi_core.contrib.werkzeug.requests.WerkzeugOpenAPIRequest

openapi.validate_request(openapi_request)

│ File "/home/odoo/.local/lib/python3.8/site-packages/openapi_core/app.py", line 347, in validate_request
│ self.validate_apicall_request(request)
│ File "/home/odoo/.local/lib/python3.8/site-packages/openapi_core/app.py", line 359, in validate_apicall_request
│ raise TypeError("'request' argument is not type of Request")

Expected Behavior

that it works like documentated here: https://openapi-core.readthedocs.io/en/latest/integrations/werkzeug.html

Steps to Reproduce

see above

OpenAPI Core Version

Version: 0.19.0

OpenAPI Core Integration

Werkzeug

Affected Area(s)

No response

References

No response

Anything else we need to know?

am I missing something?

Would you like to implement a fix?

None

htmhmeer avatar Mar 08 '24 10:03 htmhmeer

Hi @htmhmeer

can you provide working example. Your code doesn't show what type of request object did you use.

p1c2u avatar Mar 10 '24 09:03 p1c2u

from werkzeug.wrappers import Request
 
environ = request.httprequest._HTTPRequest__wrapped.environ
openapi_request = WerkzeugOpenAPIRequest(Request(environ))

openapi_request = WerkzeugOpenAPIRequest(request.httprequest._HTTPRequest__wrapped)
result = openapi.unmarshal_request(openapi_request)

The problem is that the system (Odoo) has a wrapper around the original werkzeug request so I tried making a new one with the original environ variable or using the original wrapped one, both methods give the same error when validating or unamrshalling, the WerkzeugOpenAPIRequest does work fine though.

The thing is though, I think unmarshal would work perfectly fine if that openapi-core check wouldn't be there.

htmhmeer avatar Mar 10 '24 10:03 htmhmeer

If I do isinstance(Request(environ), Request) it returns True, however, it still gives me the same error: TypeError: 'request' argument is not type of Request Tried: result = openapi.unmarshal_request(Request(environ)) Same error: I'm literally putting in the exact same Type and it just doesn't work

htmhmeer avatar Mar 10 '24 13:03 htmhmeer

The problem is that the system (Odoo) has a wrapper around the original werkzeug request

Because it's made for werkzeug request You can try to extract original request from it.

Alternatively Nnthing stopping you from creating your own class for the wrapper based on WerkzeugOpenAPIRequest just override __init__ method.

p1c2u avatar Mar 10 '24 16:03 p1c2u