Hi all,
For new REST APIs written for product IS that is being dispatched from
identity-rest-dispatcher[1] it is now possible to do input validations[2]
such as; request body property null check, input validation against regx
patterns, etc. You can define the required validations in the DTOs,
methods, etc and add the @Valid annotation to mark that validation is
required[3].
Any input validation errors will be caught by the
InputValidationExceptionMapper[4]. The error response will be as follows;
Status code 400
{
"code": "UE-10000",
"message": "Invalid Request",
"description": "<All input validation errors caught>",
"traceId": "<correlation id>"
}
Example
{
"code": "UE-10000",
"message": "Invalid Request",
"description": "Property displayName cannot be null. Property
description does not conform to ^([a-z]{7})$ pattern.",
"traceId": "d9bb6c40-980b-4a47-a6e9-2849ecb0acf6"
}
The error descriptoin is taken from the message property of the validation
annotation.
Ex: @NotNull(message = "Property displayName cannot be null.")
If you are using the [5] for swagger code generation then you can mark the
required fields in the swagger and also the relevant regx patterns[6] and
the gen tool will add the relevant annotations to the code for validation.
Currently, the gen tool supports adding @NotNull for required fields
and @Pattern for regex patterns defined in the swagger.
For @NotNull the message will be generated in the following format; "
Property <property_name> cannot be null."
For @Pattern the message will be generated in the following format; "
Property <property_name> does not conform to <regx_pattern> pattern."
[1] - https://github.com/wso2/identity-rest-dispatcher
[2] - https://github.com/wso2/identity-rest-dispatcher/pull/39
[3] -
http://cxf.apache.org/docs/validationfeature.html#ValidationFeature-CommonBeanValidation1.1Interceptors
[4] -
https://github.com/wso2/identity-rest-dispatcher/blob/master/components/org.wso2.carbon.identity.api.dispatcher/src/main/java/org/wso2/carbon/identity/api/dispatcher/InputValidationExceptionMapper.java
[5] - https://github.com/IsuraD/swagger2cxf-maven-plugin/tree/swagger_to_jar
[6] - https://swagger.io/docs/specification/data-models/data-types/#pattern
Best Regards,
--
*Janak Amarasena* | Software Engineer | WSO2 Inc.
(m) +94777764144 | (w) +94112145345 | (e) [email protected]
<https://wso2.com/signature>
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev