Do not set pattern on non-string values

Fixes #68
This commit is contained in:
Cristi Vîjdea
2018-02-23 18:51:55 +02:00
parent 058fd7096d
commit b38d3e6805
3 changed files with 9 additions and 3 deletions
+2 -2
View File
@@ -405,8 +405,8 @@ class OpenAPISchemaGenerator(object):
for variable in uritemplate.variables(path):
model, model_field = get_queryset_field(queryset, variable)
attrs = get_basic_type_info(model_field) or {'type': openapi.TYPE_STRING}
if hasattr(view_cls, 'lookup_value_regex') and getattr(view_cls, 'lookup_field', None) == variable:
attrs['pattern'] = view_cls.lookup_value_regex
if getattr(view_cls, 'lookup_field', None) == variable and attrs['type'] == openapi.TYPE_STRING:
attrs['pattern'] = getattr(view_cls, 'lookup_value_regex', attrs.get('pattern', None))
if model_field and model_field.help_text:
description = force_text(model_field.help_text)