mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-25 19:14:01 +03:00
Corrected regex serialization for OpenAPI. (#7389)
* replace \Z by \z in regex * fix test cases for Django >= 3.0 * fix isort * Added comment for why `\z`. Co-authored-by: Carlton Gibson <carlton@noumenal.es>
This commit is contained in:
parent
19915d1917
commit
5ce237e004
|
@ -554,7 +554,9 @@ class AutoSchema(ViewInspector):
|
||||||
if isinstance(v, URLValidator):
|
if isinstance(v, URLValidator):
|
||||||
schema['format'] = 'uri'
|
schema['format'] = 'uri'
|
||||||
if isinstance(v, RegexValidator):
|
if isinstance(v, RegexValidator):
|
||||||
schema['pattern'] = v.regex.pattern
|
# In Python, the token \Z does what \z does in other engines.
|
||||||
|
# https://stackoverflow.com/questions/53283160
|
||||||
|
schema['pattern'] = v.regex.pattern.replace('\\Z', '\\z')
|
||||||
elif isinstance(v, MaxLengthValidator):
|
elif isinstance(v, MaxLengthValidator):
|
||||||
attr_name = 'maxLength'
|
attr_name = 'maxLength'
|
||||||
if isinstance(field, serializers.ListField):
|
if isinstance(field, serializers.ListField):
|
||||||
|
|
|
@ -855,6 +855,7 @@ class TestOperationIntrospection(TestCase):
|
||||||
assert properties['url']['type'] == 'string'
|
assert properties['url']['type'] == 'string'
|
||||||
assert properties['url']['nullable'] is True
|
assert properties['url']['nullable'] is True
|
||||||
assert properties['url']['default'] == 'http://www.example.com'
|
assert properties['url']['default'] == 'http://www.example.com'
|
||||||
|
assert '\\Z' not in properties['url']['pattern']
|
||||||
|
|
||||||
assert properties['uuid']['type'] == 'string'
|
assert properties['uuid']['type'] == 'string'
|
||||||
assert properties['uuid']['format'] == 'uuid'
|
assert properties['uuid']['format'] == 'uuid'
|
||||||
|
|
Loading…
Reference in New Issue
Block a user