-
Notifications
You must be signed in to change notification settings - Fork 6
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
Describe validation API response #25
Comments
Example response for
Open questions:
|
Zou |
And re:3; Alternative would be to add a top level 'validation_type' key |
Re:1: A code makes more sense to me, since I think that's easier to keep in sync between frontend and backend. That is assuming we don't use HTTP response status codes to communicate success/failure. That does raise the question what kind of repsonse status code scheme we want to use and how it would differ from HTTP response status codes. |
re:2: Code in the response, so the frontend can determine the message shown to the user? Seems confusing to me to put a message in the response and show a different message in the UI. |
Valid point, we could turn it into an array. I assumed the frontend would have some knowledge of these validation rules too so it could highlight other relevant fields, but maybe an array would make more sense.
HTTP response status codes don't cover every scenario, but I think would be a good start. I agreed with @lkleuver that it would be useful to always have a response body too.
Agreed, this would mostly be for the developer. Do we want to create a specific code for each specific validation rule, or would several generic ones (e.g. |
Several generic ones would suffice, I think. There aren't that many, they aren't that complicated, we have them documented in the use cases, it's not a public API. So we can assume some domain knowledge. And if |
A specific code for each specific validation rule could be useful in the future if/when we implement analytics. That doesn't mean we have to use those same codes in the API, though. |
@lkleuver ☝️ |
New example: Request: POST http://localhost:8080/api/polling_stations/1/data_entries/12
Content-Type: application/json
Content-Length: 360
Accept: */*
{
"data": {
"voters_counts": {
"poll_card_count": 2000000000,
"proxy_certificate_count": 50,
"voter_card_count": 75,
"total_admitted_voters_count": 225
},
"votes_counts": {
"votes_candidates_counts": 200,
"blank_votes_count": 10,
"invalid_votes_count": 15,
"total_votes_cast_count": 225
}
}
} Response: HTTP/1.1 200 OK
content-type: application/json
content-length: 380
date: Tue, 14 May 2024 12:34:17 GMT
{
"saved": true,
"message": "Data entry saved successfully",
"validation_results": {
"errors": [
{
"fields": [
"data.voters_counts.poll_card_count"
],
"code": "OutOfRange"
},
{
"fields": [
"data.voters_counts.total_admitted_voters_count",
"data.voters_counts.poll_card_count",
"data.voters_counts.proxy_certificate_count",
"data.voters_counts.voter_card_count"
],
"code": "IncorrectTotal"
}
],
"warnings": []
}
} |
what is the test to see if the the request was a success? |
I think errors is always present, right @praseodym ? so just checking if it has a length > 0 should be enough |
The request is a success when the response status code is 200 OK. In that case the response body will also contain
|
Implemented in #42 according to this design. The OpenAPI specification is leading. |
No description provided.
The text was updated successfully, but these errors were encountered: