Release 1.8.0: Fluent Validation API with Collect-All-Errors #129
MoonWorm
announced in
Announcements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Overview
This release rebuilds the validation system from the ground up. The new fluent API provides a single entry point for validating path segments, query parameters, HTTP headers, and request body — with automatic error source mapping and collect-all-errors behavior.
Previously, validation was fail-fast: one error per round-trip. Now, all configured validators run and every error is returned in a single JSON:API response.
Fluent Validation API
Use
JsonApiRequestValidator.forRequest(request)to build validation rules declaratively:Relationship validators can be extracted as method references for reuse across create and update:
Automatic Error Source
The builder knows where each validator sits in the request and populates the JSON:API error
sourcefield automatically. For example,withResourceIdValidatoron a body section maps to"pointer": "/data/id", while the same validator on a path section maps to"path": "{resourceId}". No need to passErrorSourcesmanually — just throw, the framework figures out the location.Collect-All-Errors
When multiple validators fail, the response contains all errors at once:
{ "errors": [ { "id": "...", "status": "400", "code": "VALUE_IS_ABSENT", "detail": "value can't be null", "source": { "pointer": "/data/attributes" } }, { "id": "...", "status": "400", "code": "INVALID_ENUM_VALUE", "detail": "'wrong' value is not allowed, available values: [countries]", "source": { "pointer": "/data/relationships/citizenships/data/0/type" } } ] }Each developer-provided lambda is atomic — fail-fast within a lambda, collect-all across lambdas. This prevents NPEs from interdependent checks while collecting errors across independent validators.
Framework-Internal Validation Rebuilt
The built-in structural validator (
DefaultJsonApiBuildInRequestValidator) — responsible for resource type checks, ID length, filter/sort/include limits, and payload structure — was rewritten to use the sameforRequest()API. One validation model for both framework internals and developer code.HTTP Headers on Request
JsonApiRequestnow carries HTTP headers viaHeadersAwareRequest. Validate them alongside path and query parameters using the same builder:Other Changes
filter[id]requests into configurable per-resource-type chunks, fetched in parallel. Only cache misses are fetched. Configure viajsonapi4j.cd.defaultMaxBatchSizeandjsonapi4j.cd.batchSizeMapping.Resources
Beta Was this translation helpful? Give feedback.
All reactions