diff --git a/rest_framework/schemas/openapi.py b/rest_framework/schemas/openapi.py index 9b3082822..9774a94c7 100644 --- a/rest_framework/schemas/openapi.py +++ b/rest_framework/schemas/openapi.py @@ -554,7 +554,9 @@ class AutoSchema(ViewInspector): if isinstance(v, URLValidator): schema['format'] = 'uri' 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): attr_name = 'maxLength' if isinstance(field, serializers.ListField): diff --git a/tests/schemas/test_openapi.py b/tests/schemas/test_openapi.py index 0e86a7f50..d483f3d45 100644 --- a/tests/schemas/test_openapi.py +++ b/tests/schemas/test_openapi.py @@ -855,6 +855,7 @@ class TestOperationIntrospection(TestCase): assert properties['url']['type'] == 'string' assert properties['url']['nullable'] is True assert properties['url']['default'] == 'http://www.example.com' + assert '\\Z' not in properties['url']['pattern'] assert properties['uuid']['type'] == 'string' assert properties['uuid']['format'] == 'uuid'