Fix schema generation with OneToOneFields (#81)
* Fix: OneToOneRel, used by OneToOneField doesn't have help_text nor primary_key attributes, thus breaking OpenAPISchemaGenerator; use hasattr() as safe-guard. * Fix: use getattr() with a default value instead of hasattr() + acessing the value * Add: 'people' app that breaks drf_yasg without previous commits * Update tests/references.yaml + run isort and flake8 * Fix: set on_delete for Person.identity as Django-2+ requires it
This commit is contained in:
@@ -409,9 +409,9 @@ class OpenAPISchemaGenerator(object):
|
||||
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:
|
||||
if model_field and getattr(model_field, 'help_text', False):
|
||||
description = force_text(model_field.help_text)
|
||||
elif model_field and model_field.primary_key:
|
||||
elif model_field and getattr(model_field, 'primary_key', False):
|
||||
description = get_pk_description(model, model_field)
|
||||
else:
|
||||
description = None
|
||||
|
||||
Reference in New Issue
Block a user