Avoid invalid usage of readOnly
parent
608abaf0e1
commit
9b56e1a4c8
|
|
@ -118,6 +118,8 @@ class InlineSerializerInspector(SerializerInspector):
|
||||||
|
|
||||||
definitions = self.components.with_scope(openapi.SCHEMA_DEFINITIONS)
|
definitions = self.components.with_scope(openapi.SCHEMA_DEFINITIONS)
|
||||||
actual_schema = definitions.setdefault(ref_name, make_schema_definition)
|
actual_schema = definitions.setdefault(ref_name, make_schema_definition)
|
||||||
|
actual_schema._remove_read_only()
|
||||||
|
|
||||||
actual_serializer = get_serializer_class(getattr(actual_schema, '_serializer', None))
|
actual_serializer = get_serializer_class(getattr(actual_schema, '_serializer', None))
|
||||||
this_serializer = get_serializer_class(field)
|
this_serializer = get_serializer_class(field)
|
||||||
if actual_serializer and actual_serializer != this_serializer: # pragma: no cover
|
if actual_serializer and actual_serializer != this_serializer: # pragma: no cover
|
||||||
|
|
|
||||||
|
|
@ -387,8 +387,6 @@ class Parameter(SwaggerDict):
|
||||||
:param default: default value if the parameter is not provided; must conform to parameter type
|
:param default: default value if the parameter is not provided; must conform to parameter type
|
||||||
"""
|
"""
|
||||||
super(Parameter, self).__init__(**extra)
|
super(Parameter, self).__init__(**extra)
|
||||||
if (not schema and not type) or (schema and type):
|
|
||||||
raise AssertionError("either schema or type are required for Parameter object!")
|
|
||||||
self.name = name
|
self.name = name
|
||||||
self.in_ = in_
|
self.in_ = in_
|
||||||
self.description = description
|
self.description = description
|
||||||
|
|
@ -401,6 +399,10 @@ class Parameter(SwaggerDict):
|
||||||
self.items = items
|
self.items = items
|
||||||
self.default = default
|
self.default = default
|
||||||
self._insert_extras__()
|
self._insert_extras__()
|
||||||
|
if (not schema and not type) or (schema and type):
|
||||||
|
raise AssertionError("either schema or type are required for Parameter object (not both)!")
|
||||||
|
if schema and isinstance(schema, Schema):
|
||||||
|
schema._remove_read_only()
|
||||||
if self['in'] == IN_PATH:
|
if self['in'] == IN_PATH:
|
||||||
# path parameters must always be required
|
# path parameters must always be required
|
||||||
assert required is not False, "path parameter cannot be optional"
|
assert required is not False, "path parameter cannot be optional"
|
||||||
|
|
@ -465,6 +467,11 @@ class Schema(SwaggerDict):
|
||||||
if pattern and type != TYPE_STRING:
|
if pattern and type != TYPE_STRING:
|
||||||
raise AssertionError("pattern can only be used when type is string")
|
raise AssertionError("pattern can only be used when type is string")
|
||||||
|
|
||||||
|
def _remove_read_only(self):
|
||||||
|
# readOnly is only valid for Schemas inside another Schema's properties;
|
||||||
|
# when placing Schema elsewhere we must take care to remove the readOnly flag
|
||||||
|
self.pop('readOnly', '')
|
||||||
|
|
||||||
|
|
||||||
class _Ref(SwaggerDict):
|
class _Ref(SwaggerDict):
|
||||||
ref_name_re = re.compile(r"#/(?P<scope>.+)/(?P<name>[^/]+)$")
|
ref_name_re = re.compile(r"#/(?P<scope>.+)/(?P<name>[^/]+)$")
|
||||||
|
|
@ -497,12 +504,12 @@ class _Ref(SwaggerDict):
|
||||||
ref_match = self.ref_name_re.match(self.ref)
|
ref_match = self.ref_name_re.match(self.ref)
|
||||||
return resolver.get(ref_match.group('name'), scope=ref_match.group('scope'))
|
return resolver.get(ref_match.group('name'), scope=ref_match.group('scope'))
|
||||||
|
|
||||||
def __setitem__(self, key, value, **kwargs):
|
def __setitem__(self, key, value):
|
||||||
if key == "$ref":
|
if key == "$ref":
|
||||||
return super(_Ref, self).__setitem__(key, value, **kwargs)
|
return super(_Ref, self).__setitem__(key, value)
|
||||||
raise NotImplementedError("only $ref can be set on Reference objects (not %s)" % key)
|
raise NotImplementedError("only $ref can be set on Reference objects (not %s)" % key)
|
||||||
|
|
||||||
def __delitem__(self, key, **kwargs):
|
def __delitem__(self, key):
|
||||||
raise NotImplementedError("cannot delete property of Reference object")
|
raise NotImplementedError("cannot delete property of Reference object")
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -560,6 +567,8 @@ class Response(SwaggerDict):
|
||||||
self.schema = schema
|
self.schema = schema
|
||||||
self.examples = examples
|
self.examples = examples
|
||||||
self._insert_extras__()
|
self._insert_extras__()
|
||||||
|
if schema and isinstance(schema, Schema):
|
||||||
|
schema._remove_read_only()
|
||||||
|
|
||||||
|
|
||||||
class ReferenceResolver(object):
|
class ReferenceResolver(object):
|
||||||
|
|
|
||||||
|
|
@ -1599,7 +1599,6 @@ definitions:
|
||||||
title: Foo
|
title: Foo
|
||||||
type: string
|
type: string
|
||||||
minLength: 1
|
minLength: 1
|
||||||
readOnly: true
|
|
||||||
MethodFieldExample:
|
MethodFieldExample:
|
||||||
title: Hint example
|
title: Hint example
|
||||||
type: object
|
type: object
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue