Set x-nullable based on allow_null (#217)
Many fields may be set a nullable in an API. While not covered explicitly by Swagger 2, this information is usually indicated as a [vendor extension](https://swagger.io/docs/specification/2-0/swagger-extensions/) using the x-nullable field.
This commit is contained in:
committed by
Cristi Vîjdea
parent
c510de13d7
commit
d41f0c5ac4
@@ -192,7 +192,7 @@ class FieldInspector(BaseInspector):
|
||||
|
||||
- arguments specified by the ``kwargs`` parameter of :meth:`._get_partial_types`
|
||||
- ``instance_kwargs`` passed to the constructor function
|
||||
- ``title``, ``description``, ``required`` and ``default`` inferred from the field,
|
||||
- ``title``, ``description``, ``required``, ``x-nullable`` and ``default`` inferred from the field,
|
||||
where appropriate
|
||||
|
||||
If ``existing_object`` is not ``None``, it is updated instead of creating a new object.
|
||||
@@ -225,6 +225,9 @@ class FieldInspector(BaseInspector):
|
||||
instance_kwargs.setdefault('title', title)
|
||||
if description is not None:
|
||||
instance_kwargs.setdefault('description', description)
|
||||
if field.allow_null and not instance_kwargs.get('required', False) and not field.required:
|
||||
instance_kwargs['x_nullable'] = True
|
||||
|
||||
instance_kwargs.update(kwargs)
|
||||
|
||||
if existing_object is not None:
|
||||
|
||||
Reference in New Issue
Block a user