parent
058fd7096d
commit
b38d3e6805
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -361,7 +361,10 @@ def get_basic_type_info(field):
|
|||
else: # pragma: no cover
|
||||
return None
|
||||
|
||||
pattern = find_regex(field) if format in (None, openapi.FORMAT_SLUG) else None
|
||||
pattern = None
|
||||
if swagger_type == openapi.TYPE_STRING and format in (None, openapi.FORMAT_SLUG):
|
||||
pattern = find_regex(field)
|
||||
|
||||
limits = find_limits(field)
|
||||
|
||||
result = OrderedDict([
|
||||
|
|
|
|||
|
|
@ -8,6 +8,9 @@ class TodoViewSet(viewsets.ReadOnlyModelViewSet):
|
|||
queryset = Todo.objects.all()
|
||||
serializer_class = TodoSerializer
|
||||
|
||||
lookup_field = 'id'
|
||||
lookup_value_regex = '[0-9]+'
|
||||
|
||||
|
||||
class TodoAnotherViewSet(viewsets.ReadOnlyModelViewSet):
|
||||
queryset = TodoAnother.objects.all()
|
||||
|
|
|
|||
Loading…
Reference in New Issue