Do not generate readOnly outside Schema properties

openapi3
Cristi Vîjdea 2018-01-01 15:26:26 +01:00
parent 10deea826d
commit 02b72c466e
3 changed files with 13 additions and 12 deletions

View File

@ -182,7 +182,7 @@ class FieldInspector(BaseInspector):
- arguments specified by the ``kwargs`` parameter of :meth:`._get_partial_types` - arguments specified by the ``kwargs`` parameter of :meth:`._get_partial_types`
- ``instance_kwargs`` passed to the constructor function - ``instance_kwargs`` passed to the constructor function
- ``title``, ``description``, ``required``, ``default`` and ``read_only`` inferred from the field, - ``title``, ``description``, ``required`` and ``default`` inferred from the field,
where appropriate where appropriate
If ``existing_object`` is not ``None``, it is updated instead of creating a new object. If ``existing_object`` is not ``None``, it is updated instead of creating a new object.
@ -233,11 +233,6 @@ class FieldInspector(BaseInspector):
if default is not None: if default is not None:
instance_kwargs['default'] = default instance_kwargs['default'] = default
if 'read_only' not in instance_kwargs and swagger_object_type == openapi.Schema:
# TODO: read_only is only relevant for schema `properties` - should not be generated in other cases
if field.read_only:
instance_kwargs['read_only'] = True
instance_kwargs.setdefault('title', title) instance_kwargs.setdefault('title', title)
instance_kwargs.setdefault('description', description) instance_kwargs.setdefault('description', description)
instance_kwargs.update(kwargs) instance_kwargs.update(kwargs)

View File

@ -63,11 +63,18 @@ class InlineSerializerInspector(SerializerInspector):
def make_schema_definition(): def make_schema_definition():
properties = OrderedDict() properties = OrderedDict()
required = [] required = []
for key, value in serializer.fields.items(): for property_name, child in serializer.fields.items():
key = self.get_property_name(key) property_name = self.get_property_name(property_name)
properties[key] = self.probe_field_inspectors(value, ChildSwaggerType, use_references) prop_kwargs = {
if value.required: 'read_only': child.read_only or None
required.append(key) }
prop_kwargs = filter_none(prop_kwargs)
properties[property_name] = self.probe_field_inspectors(
child, ChildSwaggerType, use_references, **prop_kwargs
)
if child.required:
required.append(property_name)
return SwaggerType( return SwaggerType(
type=openapi.TYPE_OBJECT, type=openapi.TYPE_OBJECT,

View File

@ -1109,7 +1109,6 @@ definitions:
type: string type: string
format: slug format: slug
pattern: ^[-a-zA-Z0-9_]+$ pattern: ^[-a-zA-Z0-9_]+$
readOnly: true
readOnly: true readOnly: true
uniqueItems: true uniqueItems: true
securityDefinitions: securityDefinitions: