mirror of
https://github.com/correl/openapi-core.git
synced 2024-12-28 19:19:23 +00:00
Fix the Falcon integration to properly handle URLs with query strings.
Bring main README up to date for current falcon
This commit is contained in:
parent
753637d2d0
commit
9b9e5d3df9
4 changed files with 23 additions and 7 deletions
|
@ -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)
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue