mirror of
https://github.com/correl/openapi-core.git
synced 2024-11-22 03:00:10 +00:00
Convert Flask path variables to OpenAPI path parameters
This commit is contained in:
parent
2ec02e473e
commit
3ef0c6adcf
1 changed files with 8 additions and 1 deletions
|
@ -1,9 +1,16 @@
|
|||
"""OpenAPI core wrappers module"""
|
||||
import re
|
||||
|
||||
from openapi_core.wrappers.base import BaseOpenAPIRequest, BaseOpenAPIResponse
|
||||
|
||||
# http://flask.pocoo.org/docs/1.0/quickstart/#variable-rules
|
||||
PATH_PARAMETER_PATTERN = r'<(?:(?:string|int|float|path|uuid):)?(\w+)>'
|
||||
|
||||
|
||||
class FlaskOpenAPIRequest(BaseOpenAPIRequest):
|
||||
|
||||
path_regex = re.compile(PATH_PARAMETER_PATTERN)
|
||||
|
||||
def __init__(self, request):
|
||||
self.request = request
|
||||
|
||||
|
@ -24,7 +31,7 @@ class FlaskOpenAPIRequest(BaseOpenAPIRequest):
|
|||
if self.request.url_rule is None:
|
||||
return self.path
|
||||
|
||||
return self.request.url_rule.rule
|
||||
return self.path_regex.sub(r'{\1}', self.request.url_rule.rule)
|
||||
|
||||
@property
|
||||
def parameters(self):
|
||||
|
|
Loading…
Reference in a new issue