Improve validation error messages

Registered by John Wood

The current jsonschema-derived error messages on schema validations does not specify the exact field name that is in error, but rather only the value that is in error. This blueprint tries to add this field name info to the response error back to the user.

[Per Huseyin Gedikli]
Just confirmed invalid fields can be retrieved by calling iter_errors on the validation object, or schema_path attribute returns the invalid field from the JSON. Since error messages is most likely to change with the requirements, my recommendation would be creating a new blueprint to update all test code which depends on the error messages.

InvalidObject exception should contain a list of name of the invalid attributes (which are less likely to change) and all test code should be checking to see if the list contains the validated attribute after the validation.

---> So my take away is that we could pull the list of error fields from the validation exception, and then add this info to the returned error message for display to the user. We could also add this fields list to the InvalidObject exception to support unit testing.

[Brute force way, in case the above doesn't work out]
I think the easiest way is to add a method to barbican/common/validators.py to take a schema.ValidationError such as at line 104 and then take a str() of it, and then extract the text after "['properties']['" up to the next ' character. Then the final message could look like ''.join([e.message, _(' for field '), field_name]).

Blueprint information

Status:
Complete
Approver:
None
Priority:
Medium
Drafter:
John Wood
Direction:
Approved
Assignee:
Huseyin Gedikli
Definition:
Approved
Series goal:
Accepted for icehouse
Implementation:
Implemented
Milestone target:
milestone icon icehouse-2
Started by
John Wood
Completed by
John Wood

Related branches

Sprints

Whiteboard

Gerrit topic: https://review.openstack.org/#q,topic:bug/1246871,n,z

Addressed by: https://review.openstack.org/65573
    Adding invalid_property attr to support test code

(?)

Work Items

This blueprint contains Public information 
Everyone can see this information.