Merge "Separate API schemas for v2.0 compatible API"

This commit is contained in:
Jenkins
2015-09-10 20:51:54 +00:00
committed by Gerrit Code Review
3 changed files with 63 additions and 5 deletions

View File

@@ -190,7 +190,7 @@ class ServiceController(wsgi.Controller):
return {'services': _services}
@extensions.expected_errors((400, 404))
@validation.schema(services.service_update, '2.1', '2.10')
@validation.schema(services.service_update, '2.0', '2.10')
@validation.schema(services.service_update_v211, '2.11')
def update(self, req, id, body):
"""Perform service update"""

View File

@@ -49,7 +49,19 @@ def schema(request_body_schema, min_version=None, max_version=None):
else:
ver = args[1].api_version_request
legacy_v2 = args[1].is_legacy_v2()
if ver.matches(min_ver, max_ver):
if legacy_v2:
# NOTE: For v2.0 compatible API, here should work like
# client | schema min_version | schema
# -----------+--------------------+--------
# legacy_v2 | None | work
# legacy_v2 | 2.0 | work
# legacy_v2 | 2.1+ | don't
if min_version is None or min_version == '2.0':
schema_validator = validators._SchemaValidator(
request_body_schema, legacy_v2)
schema_validator.validate(kwargs['body'])
elif ver.matches(min_ver, max_ver):
# Only validate against the schema if it lies within
# the version range specified. Note that if both min
# and max are not specified the validator will always