Skip to content

Conversation

@chavanananada1995
Copy link

@chavanananada1995 chavanananada1995 commented Sep 29, 2021

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

@chavanananada1995 chavanananada1995 changed the title Changes for validate required fields,pattern,and lenth and etc Changes for validate required fields,pattern,and length and etc Sep 29, 2021
@chavanananada1995 chavanananada1995 changed the title Changes for validate required fields,pattern,and length and etc Changes for validate required fields,pattern and length and etc Sep 29, 2021
"type": "string",
"format": "date"
"format": "date",
"pattern": "^\\d{4}-\\d{2}-\\d{2}$"
Copy link
Contributor

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 ?

Copy link
Author

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maheshkumargangula Please review code

Comment on lines +78 to +86
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";
}
}
Copy link
Collaborator

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.

Copy link
Author

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.

Copy link
Author

@chavanananada1995 chavanananada1995 Oct 9, 2021

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"
}
}

  1. 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants