[HLAPI] Validate inputs within API #23042
Draft
+66
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Checklist before requesting a review
Description
Working on adding the ability to create/update resources in a frontend app now and it is clear that the messages from GLPI itself about missing/invalid fields are inconsistent, not programatically understandable, and sometimes stop after finding the first issue.
This PR adds validation based on the defined schemas within the API system to have a clean error message response that can show issues at the field level. This allows frontends to take the field issues and show validation messages next to the field with the issue.
Ideally, a frontend would read the requirements from the schema and do client-side validation, but server-side validation is required in case they don't, they somehow are validating against an outdated schema, or in case there are complex validation cases that can only be done on the server.
Example response:
Error that shows without the validation logic in the API: