schema: Fix metadata schema patterns
This patch set fixes the schema pattern enforced by metadata_document and metadata_control. Currently, both allow a schema with either pattern: - ^metadata/Control/v\d+$ - ^metadata/Document/v\d+$ However, the metadata_control schema should only allow the former and the metadata_document schema should only allow the latter. Change-Id: Ic1b88a7158755818002de4c88cdf2d7b716f656d
This commit is contained in:
parent
f745e4b6e7
commit
d5462d0c70
|
@ -192,7 +192,7 @@ class GenericValidator(BaseValidator):
|
||||||
class DataSchemaValidator(GenericValidator):
|
class DataSchemaValidator(GenericValidator):
|
||||||
"""Validator for validating ``DataSchema`` documents."""
|
"""Validator for validating ``DataSchema`` documents."""
|
||||||
|
|
||||||
__slots__ = ('_default_schema_map', '_external_data_schemas')
|
__slots__ = ('_default_schema_map', '_current_data_schemas')
|
||||||
|
|
||||||
def _build_schema_map(self, data_schemas):
|
def _build_schema_map(self, data_schemas):
|
||||||
schema_map = copy.deepcopy(self._default_schema_map)
|
schema_map = copy.deepcopy(self._default_schema_map)
|
||||||
|
@ -218,7 +218,7 @@ class DataSchemaValidator(GenericValidator):
|
||||||
global _DEFAULT_SCHEMAS
|
global _DEFAULT_SCHEMAS
|
||||||
|
|
||||||
self._default_schema_map = _DEFAULT_SCHEMAS
|
self._default_schema_map = _DEFAULT_SCHEMAS
|
||||||
self._external_data_schemas = [d.data for d in data_schemas]
|
self._current_data_schemas = [d.data for d in data_schemas]
|
||||||
self._schema_map = self._build_schema_map(data_schemas)
|
self._schema_map = self._build_schema_map(data_schemas)
|
||||||
|
|
||||||
def _generate_validation_error_output(self, schema, document, error,
|
def _generate_validation_error_output(self, schema, document, error,
|
||||||
|
@ -424,9 +424,9 @@ class DocumentValidation(object):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self._documents = []
|
self._documents = []
|
||||||
self._external_data_schemas = [document_wrapper.DocumentDict(d)
|
self._current_data_schemas = [document_wrapper.DocumentDict(d)
|
||||||
for d in existing_data_schemas or []]
|
for d in existing_data_schemas or []]
|
||||||
data_schema_map = {d.meta: d for d in self._external_data_schemas}
|
data_schema_map = {d.meta: d for d in self._current_data_schemas}
|
||||||
|
|
||||||
raw_properties = ('data', 'metadata', 'schema')
|
raw_properties = ('data', 'metadata', 'schema')
|
||||||
|
|
||||||
|
@ -441,11 +441,11 @@ class DocumentValidation(object):
|
||||||
|
|
||||||
document = document_wrapper.DocumentDict(raw_document)
|
document = document_wrapper.DocumentDict(raw_document)
|
||||||
if document.schema.startswith(types.DATA_SCHEMA_SCHEMA):
|
if document.schema.startswith(types.DATA_SCHEMA_SCHEMA):
|
||||||
self._external_data_schemas.append(document)
|
self._current_data_schemas.append(document)
|
||||||
# If a newer version of the same DataSchema was passed in,
|
# If a newer version of the same DataSchema was passed in,
|
||||||
# only use the new one and discard the old one.
|
# only use the new one and discard the old one.
|
||||||
if document.meta in data_schema_map:
|
if document.meta in data_schema_map:
|
||||||
self._external_data_schemas.remove(
|
self._current_data_schemas.remove(
|
||||||
data_schema_map.pop(document.meta))
|
data_schema_map.pop(document.meta))
|
||||||
|
|
||||||
self._documents.append(document)
|
self._documents.append(document)
|
||||||
|
@ -453,7 +453,7 @@ class DocumentValidation(object):
|
||||||
self._pre_validate = pre_validate
|
self._pre_validate = pre_validate
|
||||||
|
|
||||||
self._validators = [
|
self._validators = [
|
||||||
DataSchemaValidator(self._external_data_schemas),
|
DataSchemaValidator(self._current_data_schemas),
|
||||||
]
|
]
|
||||||
if self._pre_validate:
|
if self._pre_validate:
|
||||||
# Only perform this additional validation "offline". The controller
|
# Only perform this additional validation "offline". The controller
|
||||||
|
|
|
@ -8,11 +8,8 @@ data:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
schema:
|
schema:
|
||||||
anyOf:
|
type: string
|
||||||
- type: string
|
pattern: ^metadata/Control/v\d+$
|
||||||
pattern: ^metadata/Document/v\d+$
|
|
||||||
- type: string
|
|
||||||
pattern: ^metadata/Control/v\d+$
|
|
||||||
name:
|
name:
|
||||||
type: string
|
type: string
|
||||||
labels:
|
labels:
|
||||||
|
|
|
@ -44,11 +44,8 @@ data:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
schema:
|
schema:
|
||||||
anyOf:
|
type: string
|
||||||
- type: string
|
pattern: ^metadata/Document/v\d+$
|
||||||
pattern: ^metadata/Document/v\d+$
|
|
||||||
- type: string
|
|
||||||
pattern: ^metadata/Control/v\d+$
|
|
||||||
name:
|
name:
|
||||||
type: string
|
type: string
|
||||||
labels:
|
labels:
|
||||||
|
|
Loading…
Reference in New Issue