From ca369f795a0c539ee7b3995af55ac032e3879fe1 Mon Sep 17 00:00:00 2001 From: Pedro Peixoto Date: Sat, 13 Jul 2019 08:46:18 -0300 Subject: [PATCH] Creating read_only and write_only properties on the Schema --- openapi_core/schema/schemas/factories.py | 4 +++- openapi_core/schema/schemas/models.py | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/openapi_core/schema/schemas/factories.py b/openapi_core/schema/schemas/factories.py index f92d598..55b48fe 100644 --- a/openapi_core/schema/schemas/factories.py +++ b/openapi_core/schema/schemas/factories.py @@ -46,6 +46,8 @@ class SchemaFactory(object): exclusive_maximum = schema_deref.get('exclusiveMaximum', False) min_properties = schema_deref.get('minProperties', 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) @@ -81,7 +83,7 @@ class SchemaFactory(object): exclusive_maximum=exclusive_maximum, exclusive_minimum=exclusive_minimum, min_properties=min_properties, max_properties=max_properties, - extensions=extensions, + read_only=read_only, write_only=write_only, extensions=extensions, _source=schema_deref, ) diff --git a/openapi_core/schema/schemas/models.py b/openapi_core/schema/schemas/models.py index 37fe06f..15e409c 100644 --- a/openapi_core/schema/schemas/models.py +++ b/openapi_core/schema/schemas/models.py @@ -26,7 +26,8 @@ class Schema(object): min_length=None, max_length=None, pattern=None, unique_items=False, minimum=None, maximum=None, multiple_of=None, 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): self.type = SchemaType(schema_type) self.properties = properties and dict(properties) or {} @@ -56,6 +57,11 @@ class Schema(object): if min_properties is not None else None self.max_properties = int(max_properties)\ 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 {}