-
Notifications
You must be signed in to change notification settings - Fork 174
Changes for validate required fields,pattern and length and etc #743
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: release-4.2.0
Are you sure you want to change the base?
Changes for validate required fields,pattern and length and etc #743
Conversation
| "type": "string", | ||
| "format": "date" | ||
| "format": "date", | ||
| "pattern": "^\\d{4}-\\d{2}-\\d{2}$" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since format is already set to date, is setting pattern required ? Is the JSON schema validation not working out of the box ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we set only format then allow minus values in date format that why we add this
@coolbung
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@maheshkumargangula Please review code
| case "minLength": { | ||
| int actual = (int) problem.parametersAsMap().get("actual"); | ||
| int limit = (int) problem.parametersAsMap().get("limit"); | ||
| if( actual < limit) | ||
| { | ||
| return problem.getPointer().replaceAll("/", "") | ||
| + " must be at least "+ problem.parametersAsMap().get("limit") +" characters long"; | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need a custom code to handle minLength. The library which we are using support this. Please validate it again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you sir for review code we are check again validate for minlength.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@maheshkumargangula
Thank you for review and comments. I have checked "minLength" again, but it's not supporting. Here attaching request-response :1) Validating "minLength" without adding custom code for minLength :
POST 'localhost:9000/event/v4/create'
Request Body:
{
"request": {
"event": {
"name": "a",
"status": "Draft",
"code": "EVENT",
"startDate": "2021-08-18",
"endDate": "2021-08-19",
"startTime": "11:20:39+00:00",
"endTime": "10:20:39+00:00",
"registrationEndDate": "2021-08-13",
"eventType": "Online",
"onlineProvider": "BigBlueButton"
}
}
}
Response:
- Event got successfully created without any validation error, even if we have provided event name with single character "a", which is < minLength.
{
"id": "api.event.create",
"ver": "4.0",
"ts": "2021-10-09T12:07:06Z+05:30",
"params": {
"resmsgid": "9a0c332b-363f-4887-977f-ca3ba9019b7e",
"msgid": null,
"err": null,
"status": "successful",
"errmsg": null
},
"responseCode": "OK",
"result": {
"identifier": "do_11338377350280806411",
"node_id": "do_11338377350280806411",
"versionKey": "1633761422263"
}
}
- Validating "minLength" with adding custom code for minLength :
POST 'localhost:9000/event/v4/create'
Request Body:
{
"request": {
"event": {
"name": "a",
"status": "Draft",
"code": "EVENT",
"startDate": "2021-08-18",
"endDate": "2021-08-19",
"startTime": "11:20:39+00:00",
"endTime": "10:20:39+00:00",
"registrationEndDate": "2021-08-13",
"eventType": "Online",
"onlineProvider": "BigBlueButton"
}
}
}
**Response:
- After adding custom code, it supports validation and gives corresponding length error.**
{
"id": "api.event.create",
"ver": "4.0",
"ts": "2021-10-09T11:06:20Z+05:30",
"params": {
"resmsgid": "c288254c-9d24-4ccf-b6fb-492b3191ef2c",
"msgid": null,
"err": "CLIENT_ERROR",
"status": "failed",
"errmsg": "Validation Errors"
},
"responseCode": "CLIENT_ERROR",
"result": {
"messages": [
"name must be at least 5 characters long"
]
}
}
We had also raised ticket about same :
https://github.com/project-sunbird/sunbird-community/discussions/567#discussion-3580472
Validate following cases :
1)Validate field are not accept null and empty values
2) validate length of character
3)Validate pattern like string must be alphanumeric string,accept special character and some cases should not accept special character
4)Validate date should not accept negative values