Skip to content

Commit 8e9cb1e

Browse files
authored
Merge pull request #5014 from dczech/feature/decouple-bigautofield
Include URL path regexs in API schemas where valid.
2 parents 7d64cf5 + 54d0901 commit 8e9cb1e

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

rest_framework/schemas.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,7 @@ def get_path_fields(self, path, method, view):
526526
title = ''
527527
description = ''
528528
schema_cls = coreschema.String
529+
kwargs = {}
529530
if model is not None:
530531
# Attempt to infer a field description if possible.
531532
try:
@@ -541,14 +542,16 @@ def get_path_fields(self, path, method, view):
541542
elif model_field is not None and model_field.primary_key:
542543
description = get_pk_description(model, model_field)
543544

544-
if isinstance(model_field, models.AutoField):
545+
if hasattr(view, 'lookup_value_regex') and view.lookup_field == variable:
546+
kwargs['pattern'] = view.lookup_value_regex
547+
elif isinstance(model_field, models.AutoField):
545548
schema_cls = coreschema.Integer
546549

547550
field = coreapi.Field(
548551
name=variable,
549552
location='path',
550553
required=True,
551-
schema=schema_cls(title=title, description=description)
554+
schema=schema_cls(title=title, description=description, **kwargs)
552555
)
553556
fields.append(field)
554557

0 commit comments

Comments
 (0)