Validation of input parameters through JSON Schema

Registered by Dongdong Pei on 2017-12-13

Nova, Cinder and Keystone have used JSON Schema to validate input parameters in start of operation itself instead of going ahead and reported error after error occurs.

We should follow same in Manila.

Nova JSON Schema Validation::
## Validation:

    def validate(self, *args, **kwargs):
        try:
            self.validator.validate(*args, **kwargs)
        except jsonschema.ValidationError as ex:
            # NOTE: For whole OpenStack message consistency, this error
            # message has been written as the similar format of WSME.
            if len(ex.path) > 0:
                detail = _("Invalid input for field/attribute %(path)s."
                           " Value: %(value)s. %(message)s") % {
                               'path': ex.path.pop(), 'value': ex.instance,
                               'message': ex.message
                           }
            else:
                detail = ex.message
            raise exception.ValidationError(detail=detail)
        except TypeError as ex:
            # NOTE: If passing non string value to patternProperties parameter,
            # TypeError happens. Here is for catching the TypeError.
            detail = six.text_type(ex)
            raise exception.ValidationError(detail=detail)

## At API layer:
https://github.com/openstack/nova/blob/master/nova/api/openstack/compute/create_backup.py

    @validation.schema(create_backup.create_backup, '2.1')
    def _create_backup(self, req, id, body):
        """Backup a server instance.

https://github.com/openstack/nova/tree/master/nova/api/openstack/compute/schemas

Cinder JSON Schema Validation:
[1] https://blueprints.launchpad.net/cinder/+spec/json-schema-validation
[2] https://review.openstack.org/#/c/507386/

Blueprint information

Status:
Started
Approver:
Goutham Pacha Ravi
Priority:
High
Drafter:
Dongdong Pei
Direction:
Approved
Assignee:
Dongdong Pei
Definition:
Approved
Series goal:
None
Implementation:
Slow progress
Milestone target:
None
Started by
Dongdong Pei on 2018-04-18

Related branches

Sprints

Whiteboard

Gerrit topic: https://review.openstack.org/#q,topic:bp/json-schema-validation,n,z

Addressed by: https://review.openstack.org/553662
    Add json schema validation for Manila APIs

Addressed by: https://review.openstack.org/563429
    V2 jsonschema validation: base schema framework & share-types

(?)

Work Items

This blueprint contains Public information 
Everyone can see this information.

Subscribers

No subscribers.