Skip to content

Conversation

@cconard96
Copy link
Contributor

Checklist before requesting a review

  • I have read the CONTRIBUTING document.
  • I have performed a self-review of my code.
  • I have added tests that prove my fix is effective or that my feature works.
  • This change requires a documentation update.

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:

{
	"status": "ERROR_INVALID_PARAMETER",
	"title": "Invalid input parameters",
	"detail": {
		"name": [
			{
				"error": "required",
				"message": "This field is required"
			}
		],
		"min_required_approval_percent": [
			{
				"error": "range",
				"message": "This field must be between 0 and 100",
				"minimum": 0,
				"maximum": 100
			}
		]
	}
}

Error that shows without the validation logic in the API:

{
	"status": "ERROR",
	"title": "Failed to create item(s)",
	"detail": null,
	"additional_messages": [
		{
			"priority": "error",
			"message": "The name field is mandatory"
		},
		{
			"priority": "error",
			"message": "The Minimal required approval percent field is mandatory and must be beetween 0 and 100."
		}
	]
}

@cconard96 cconard96 self-assigned this Feb 6, 2026
@cconard96 cconard96 added the api label Feb 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant