api: Add response body schemas for versions APIs
We move a check for unset microversions to after the check for a min or max version filter. If we're not filtering, we don't need to fail. Change-Id: Ic3b11b8233b3bb3e5016bce6653bb86908ef8874 Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
@@ -23,3 +23,110 @@ multi_query = {
|
||||
'properties': {},
|
||||
'additionalProperties': True,
|
||||
}
|
||||
|
||||
_version_obj = {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'id': {'type': 'string'},
|
||||
'status': {
|
||||
'type': 'string',
|
||||
'enum': ['CURRENT', 'SUPPORTED', 'DEPRECATED'],
|
||||
},
|
||||
'links': {
|
||||
'type': 'array',
|
||||
'items': {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'href': {'type': 'string'},
|
||||
'rel': {'type': 'string'},
|
||||
'type': {'type': 'string'},
|
||||
},
|
||||
'required': ['rel', 'href'],
|
||||
'additionalProperties': False,
|
||||
},
|
||||
},
|
||||
'min_version': {'type': 'string'},
|
||||
'updated': {'type': 'string', 'format': 'date-time'},
|
||||
'version': {'type': 'string'},
|
||||
},
|
||||
'required': ['id', 'status', 'links', 'min_version', 'updated'],
|
||||
'additionalProperties': False,
|
||||
}
|
||||
|
||||
index_response = {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'versions': {'type': 'array', 'items': _version_obj}
|
||||
},
|
||||
'required': ['versions'],
|
||||
'additionalProperties': False,
|
||||
}
|
||||
|
||||
_version_obj_with_media_types = _version_obj
|
||||
_version_obj_with_media_types['properties'].update({
|
||||
'media-types': {
|
||||
'type': 'array',
|
||||
'items': {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'base': {'type': 'string'},
|
||||
'type': {'type': 'string'},
|
||||
},
|
||||
'required': ['base', 'type'],
|
||||
'additionalProperties': False,
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
show_response = {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'version': _version_obj_with_media_types
|
||||
},
|
||||
'required': ['version'],
|
||||
'additionalProperties': False,
|
||||
}
|
||||
|
||||
_legacy_version_obj = {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'id': {'type': 'string'},
|
||||
'status': {'type': 'string'},
|
||||
'links': {
|
||||
'type': 'array',
|
||||
'items': {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'href': {'type': 'string'},
|
||||
'rel': {'type': 'string'},
|
||||
'type': {'type': 'string'},
|
||||
},
|
||||
'required': ['rel', 'href'],
|
||||
'additionalProperties': False,
|
||||
},
|
||||
},
|
||||
'media-types': {
|
||||
'type': 'array',
|
||||
'items': {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'base': {'type': 'string'},
|
||||
'type': {'type': 'string'},
|
||||
},
|
||||
'required': ['base', 'type'],
|
||||
'additionalProperties': False,
|
||||
},
|
||||
},
|
||||
},
|
||||
'required': ['id', 'status', 'links', 'media-types'],
|
||||
'additionalProperties': False,
|
||||
}
|
||||
|
||||
multi_response = {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'choices': {'type': 'array', 'items': _legacy_version_obj}
|
||||
},
|
||||
'required': ['choices'],
|
||||
'additionalProperties': False,
|
||||
}
|
||||
|
||||
@@ -83,6 +83,7 @@ class Versions(wsgi.Resource):
|
||||
super(Versions, self).__init__(None)
|
||||
|
||||
@validation.query_schema(schema.show_query)
|
||||
@validation.response_body_schema(schema.index_response)
|
||||
def index(self, req, body=None):
|
||||
"""Return all versions."""
|
||||
builder = views_versions.get_view_builder(req)
|
||||
@@ -90,6 +91,7 @@ class Versions(wsgi.Resource):
|
||||
|
||||
@wsgi.response(300)
|
||||
@validation.query_schema(schema.multi_query)
|
||||
@validation.response_body_schema(schema.multi_response)
|
||||
def multi(self, req, body=None):
|
||||
"""Return multiple choices."""
|
||||
builder = views_versions.get_view_builder(req)
|
||||
@@ -111,7 +113,10 @@ class VersionsV2(wsgi.Resource):
|
||||
def __init__(self):
|
||||
super(VersionsV2, self).__init__(None)
|
||||
|
||||
# NOTE(stephenfin): Despite being called index, this is actually called as
|
||||
# a show action
|
||||
@validation.query_schema(schema.show_query)
|
||||
@validation.response_body_schema(schema.show_response)
|
||||
def index(self, req, body=None):
|
||||
builder = views_versions.get_view_builder(req)
|
||||
ver = 'v2.0' if req.is_legacy_v2() else 'v2.1'
|
||||
|
||||
@@ -26,6 +26,7 @@ class VersionsController(wsgi.Controller):
|
||||
|
||||
@wsgi.expected_errors(404)
|
||||
@validation.query_schema(schema.show_query)
|
||||
@validation.response_body_schema(schema.show_response)
|
||||
def show(self, req, id='v2.1'):
|
||||
builder = views_versions.get_view_builder(req)
|
||||
if req.is_legacy_v2():
|
||||
|
||||
Reference in New Issue
Block a user