Merge "api: Add response body schemas for availability zone APIs"

This commit is contained in:
Zuul
2024-12-07 00:11:05 +00:00
committed by Gerrit Code Review
2 changed files with 60 additions and 0 deletions
@@ -106,6 +106,7 @@ class AvailabilityZoneController(wsgi.Controller):
@wsgi.expected_errors(())
@validation.query_schema(schema.index_query)
@validation.response_body_schema(schema.index_response)
def index(self, req):
"""Returns a summary list of availability zone."""
context = req.environ['nova.context']
@@ -115,6 +116,7 @@ class AvailabilityZoneController(wsgi.Controller):
@wsgi.expected_errors(())
@validation.query_schema(schema.detail_query)
@validation.response_body_schema(schema.detail_response)
def detail(self, req):
"""Returns a detailed list of availability zone."""
context = req.environ['nova.context']
@@ -12,6 +12,9 @@
# License for the specific language governing permissions and limitations
# under the License.
import copy
# TODO(stephenfin): Remove additionalProperties in a future API version
index_query = {
'type': 'object',
@@ -20,3 +23,58 @@ index_query = {
}
detail_query = index_query
index_response = {
'type': 'object',
'properties': {
'availabilityZoneInfo': {
'type': 'array',
'items': {
'type': 'object',
'properties': {
'hosts': {'type': 'null'},
'zoneName': {'type': 'string'},
'zoneState': {
'type': 'object',
'properties': {
'available': {'type': 'boolean'},
},
},
},
'required': ['hosts', 'zoneName', 'zoneState'],
'additionalProperties': False,
},
},
},
'required': ['availabilityZoneInfo'],
'additionalProperties': False,
}
detail_response = copy.deepcopy(index_response)
detail_response['properties']['availabilityZoneInfo']['items']['properties']['hosts'] = { # noqa: E501
'type': ['null', 'object'],
'patternProperties': {
'^.+$': {
'type': 'object',
'patternProperties': {
'^.+$': {
'type': 'object',
'properties': {
'active': {'type': 'boolean'},
'available': {'type': 'boolean'},
'updated_at': {
'oneOf': [
{'type': 'null'},
{'type': 'string', 'format': 'date-time'},
],
},
},
'required': ['active', 'available', 'updated_at'],
'additionalProperties': False,
},
},
'additionalProperties': False,
},
},
'additionalProperties': False,
}