From 54d0901f381b9fdd95dfeb5b9b26f6839eaba433 Mon Sep 17 00:00:00 2001 From: Dariusz Czech Date: Tue, 21 Mar 2017 15:15:20 +0100 Subject: [PATCH] Leave parameters with regex pattern as String --- rest_framework/schemas.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/rest_framework/schemas.py b/rest_framework/schemas.py index f89f347ac..c15ed0bfd 100644 --- a/rest_framework/schemas.py +++ b/rest_framework/schemas.py @@ -526,6 +526,7 @@ class SchemaGenerator(object): title = '' description = '' schema_cls = coreschema.String + kwargs = {} if model is not None: # Attempt to infer a field description if possible. try: @@ -541,15 +542,16 @@ class SchemaGenerator(object): elif model_field is not None and model_field.primary_key: description = get_pk_description(model, model_field) - # BigAutoField is outside of Integer range - if isinstance(model_field, models.AutoField) and not isinstance(model_field, models.BigAutoField): + if hasattr(view, 'lookup_value_regex') and view.lookup_field == variable: + kwargs['pattern'] = view.lookup_value_regex + elif isinstance(model_field, models.AutoField): schema_cls = coreschema.Integer field = coreapi.Field( name=variable, location='path', required=True, - schema=schema_cls(title=title, description=description) + schema=schema_cls(title=title, description=description, **kwargs) ) fields.append(field)