Creating read_only and write_only properties on the Schema

This commit is contained in:
Pedro Peixoto 2019-07-13 08:46:18 -03:00 committed by Artur Maciag
parent baf042cbb6
commit ca369f795a
2 changed files with 10 additions and 2 deletions

View file

@ -46,6 +46,8 @@ class SchemaFactory(object):
exclusive_maximum = schema_deref.get('exclusiveMaximum', False) exclusive_maximum = schema_deref.get('exclusiveMaximum', False)
min_properties = schema_deref.get('minProperties', None) min_properties = schema_deref.get('minProperties', None)
max_properties = schema_deref.get('maxProperties', None) max_properties = schema_deref.get('maxProperties', None)
read_only = schema_deref.get('readOnly', False)
write_only = schema_deref.get('writeOnly', False)
extensions = self.extensions_generator.generate(schema_deref) extensions = self.extensions_generator.generate(schema_deref)
@ -81,7 +83,7 @@ class SchemaFactory(object):
exclusive_maximum=exclusive_maximum, exclusive_maximum=exclusive_maximum,
exclusive_minimum=exclusive_minimum, exclusive_minimum=exclusive_minimum,
min_properties=min_properties, max_properties=max_properties, min_properties=min_properties, max_properties=max_properties,
extensions=extensions, read_only=read_only, write_only=write_only, extensions=extensions,
_source=schema_deref, _source=schema_deref,
) )

View file

@ -26,7 +26,8 @@ class Schema(object):
min_length=None, max_length=None, pattern=None, unique_items=False, min_length=None, max_length=None, pattern=None, unique_items=False,
minimum=None, maximum=None, multiple_of=None, minimum=None, maximum=None, multiple_of=None,
exclusive_minimum=False, exclusive_maximum=False, exclusive_minimum=False, exclusive_maximum=False,
min_properties=None, max_properties=None, extensions=None, min_properties=None, max_properties=None,
read_only=False, write_only=False, extensions=None,
_source=None): _source=None):
self.type = SchemaType(schema_type) self.type = SchemaType(schema_type)
self.properties = properties and dict(properties) or {} self.properties = properties and dict(properties) or {}
@ -56,6 +57,11 @@ class Schema(object):
if min_properties is not None else None if min_properties is not None else None
self.max_properties = int(max_properties)\ self.max_properties = int(max_properties)\
if max_properties is not None else None if max_properties is not None else None
self.read_only = read_only
self.write_only = write_only
if self.read_only and self.write_only:
raise OpenAPISchemaError("Schema cannot be readOnly AND writeOnly")
self.extensions = extensions and dict(extensions) or {} self.extensions = extensions and dict(extensions) or {}