Merge pull request #233 from dlarrick/falcon-params

Fix the Falcon integration to properly handle URLs with query strings.
This commit is contained in:
A 2020-05-10 15:37:43 +01:00 committed by GitHub
commit 97b568dc55
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 7 deletions

View file

@ -260,9 +260,9 @@ For Falcon you can use FalconOpenAPIRequest a Falcon request factory:
.. code-block:: python
from openapi_core.validation.request.validators import RequestValidator
from openapi_core.contrib.falcon import FalconOpenAPIRequest
from openapi_core.contrib.falcon import FalconOpenAPIRequestFactory
openapi_request = FalconOpenAPIRequest(falcon_request)
openapi_request = FalconOpenAPIRequestFactory.create(falcon_request)
validator = RequestValidator(spec)
result = validator.validate(openapi_request)
@ -271,9 +271,9 @@ You can use FalconOpenAPIResponse as a Falcon response factory:
.. code-block:: python
from openapi_core.validation.response.validators import ResponseValidator
from openapi_core.contrib.falcon import FalconOpenAPIResponse
from openapi_core.contrib.falcon import FalconOpenAPIResponseFactory
openapi_response = FalconOpenAPIResponse(falcon_response)
openapi_response = FalconOpenAPIResponseFactory.create(falcon_response)
validator = ResponseValidator(spec)
result = validator.validate(openapi_request, openapi_response)

View file

@ -23,7 +23,7 @@ class FalconOpenAPIRequestFactory:
# Support falcon-jsonify.
body = (
dumps(request.json) if getattr(request, "json", None)
else request.bounded_stream.read()
else dumps(request.media)
)
mimetype = request.options.default_media_type
if request.content_type:
@ -36,8 +36,9 @@ class FalconOpenAPIRequestFactory:
cookie=request.cookies,
path=path,
)
url_pattern = request.prefix + request.path
return OpenAPIRequest(
full_url_pattern=request.url,
full_url_pattern=url_pattern,
method=method,
parameters=parameters,
body=body,

View file

@ -13,12 +13,18 @@ paths:
description: the ID of the resource to retrieve
schema:
type: integer
- name: detail_level
in: query
required: false
description: optional level of detail to provide
schema:
type: integer
get:
responses:
200:
description: Return the resource.
content:
application/json:
application/json:
schema:
type: object
required:

View file

@ -32,3 +32,12 @@ class TestFalconOpenAPIValidation(object):
openapi_request = FalconOpenAPIRequestFactory.create(request)
result = validator.validate(openapi_request)
assert not result.errors
def test_request_validator_with_query(self, spec, request_factory):
validator = RequestValidator(spec)
request = request_factory('GET', '/browse/12',
query_string='detail_level=2',
subdomain='kb')
openapi_request = FalconOpenAPIRequestFactory.create(request)
result = validator.validate(openapi_request)
assert not result.errors