Leave parameters with regex pattern as String

This commit is contained in:
Dariusz Czech 2017-03-21 15:15:20 +01:00
parent 9074e3e478
commit 54d0901f38

View File

@ -526,6 +526,7 @@ class SchemaGenerator(object):
title = '' title = ''
description = '' description = ''
schema_cls = coreschema.String schema_cls = coreschema.String
kwargs = {}
if model is not None: if model is not None:
# Attempt to infer a field description if possible. # Attempt to infer a field description if possible.
try: try:
@ -541,15 +542,16 @@ class SchemaGenerator(object):
elif model_field is not None and model_field.primary_key: elif model_field is not None and model_field.primary_key:
description = get_pk_description(model, model_field) description = get_pk_description(model, model_field)
# BigAutoField is outside of Integer range if hasattr(view, 'lookup_value_regex') and view.lookup_field == variable:
if isinstance(model_field, models.AutoField) and not isinstance(model_field, models.BigAutoField): kwargs['pattern'] = view.lookup_value_regex
elif isinstance(model_field, models.AutoField):
schema_cls = coreschema.Integer schema_cls = coreschema.Integer
field = coreapi.Field( field = coreapi.Field(
name=variable, name=variable,
location='path', location='path',
required=True, required=True,
schema=schema_cls(title=title, description=description) schema=schema_cls(title=title, description=description, **kwargs)
) )
fields.append(field) fields.append(field)