parent
058fd7096d
commit
b38d3e6805
|
|
@ -405,8 +405,8 @@ class OpenAPISchemaGenerator(object):
|
||||||
for variable in uritemplate.variables(path):
|
for variable in uritemplate.variables(path):
|
||||||
model, model_field = get_queryset_field(queryset, variable)
|
model, model_field = get_queryset_field(queryset, variable)
|
||||||
attrs = get_basic_type_info(model_field) or {'type': openapi.TYPE_STRING}
|
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:
|
if getattr(view_cls, 'lookup_field', None) == variable and attrs['type'] == openapi.TYPE_STRING:
|
||||||
attrs['pattern'] = view_cls.lookup_value_regex
|
attrs['pattern'] = getattr(view_cls, 'lookup_value_regex', attrs.get('pattern', None))
|
||||||
|
|
||||||
if model_field and model_field.help_text:
|
if model_field and model_field.help_text:
|
||||||
description = force_text(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
|
else: # pragma: no cover
|
||||||
return None
|
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)
|
limits = find_limits(field)
|
||||||
|
|
||||||
result = OrderedDict([
|
result = OrderedDict([
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,9 @@ class TodoViewSet(viewsets.ReadOnlyModelViewSet):
|
||||||
queryset = Todo.objects.all()
|
queryset = Todo.objects.all()
|
||||||
serializer_class = TodoSerializer
|
serializer_class = TodoSerializer
|
||||||
|
|
||||||
|
lookup_field = 'id'
|
||||||
|
lookup_value_regex = '[0-9]+'
|
||||||
|
|
||||||
|
|
||||||
class TodoAnotherViewSet(viewsets.ReadOnlyModelViewSet):
|
class TodoAnotherViewSet(viewsets.ReadOnlyModelViewSet):
|
||||||
queryset = TodoAnother.objects.all()
|
queryset = TodoAnother.objects.all()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue