feat(core): validate resource update requests - #34
Conversation
Refine the milestone into an implementation-ready contract covering endpoint-identity context, stable rule codes, primary-scoped update rules, and both plan-review rounds.
Add UPDATE_REQUEST document usage with primary-single-resource shape, relationship replacement-data, and optional expected endpoint identity checks (EndpointIdentity on ValidationContext), scoped to the primary resource so included resources keep response semantics.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
🚧 Files skipped from review as they are similar to previous changes (4)
📝 WalkthroughWalkthroughPhase 1.3 adds JSON:API update-request validation. The change adds endpoint identity support, update-specific rule codes, primary-resource and relationship checks, focused tests, and documentation. ChangesUpdate request validation
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Caller
participant ValidationContext
participant JsonApiDocumentValidator
participant ValidationErrors
Caller->>ValidationContext: configure UPDATE_REQUEST
Caller->>ValidationContext: set expected EndpointIdentity
Caller->>JsonApiDocumentValidator: validate document
JsonApiDocumentValidator->>ValidationContext: read update settings
JsonApiDocumentValidator->>JsonApiDocumentValidator: validate primary resource and relationships
JsonApiDocumentValidator->>ValidationErrors: report rule codes and JSON pointers
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (3)
jsonapi-java-core/src/main/java/io/github/kazemek/jsonapi/core/validation/package-info.java (1)
9-13: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueScope the relationship requirement to the primary resource.
The validator applies the
datarequirement only to relationships of the primary resource. Included resources keep response semantics. State that scope here so readers do not expect the rule on included resources.📝 Proposed wording
- * single-resource primary data, replacement {`@code` data} on every supplied relationship, and — when + * single-resource primary data, replacement {`@code` data} on every relationship supplied by the + * primary resource, and — when🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@jsonapi-java-core/src/main/java/io/github/kazemek/jsonapi/core/validation/package-info.java` around lines 9 - 13, Update the UPDATE_REQUEST documentation in package-info.java to clarify that the replacement data requirement applies only to relationships of the primary resource; explicitly preserve response semantics for included resources.jsonapi-java-core/src/test/groovy/io/github/kazemek/jsonapi/core/validation/UpdateRequestValidationSpec.groovy (1)
282-293: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd a test for endpoint identity preservation across the
with*methods.Every call here applies
withExpectedEndpointIdentitylast.ValidationContext.withDocumentUsage,withLinksContext, andwithSparseFieldsetExceptionnow copyexpectedEndpointIdentityforward. If one of those copies were dropped, this suite would still pass.💚 Proposed additional feature
+ def "expected endpoint identity survives context derivation"() { + given: + def base = ValidationContext.defaults() + .withExpectedEndpointIdentity(new EndpointIdentity("articles", "1")) + + expect: + base.withDocumentUsage(DocumentUsage.UPDATE_REQUEST).expectedEndpointIdentity() == + new EndpointIdentity("articles", "1") + base.withLinksContext(LinksContext.RESOURCE).expectedEndpointIdentity() == + new EndpointIdentity("articles", "1") + base.withSparseFieldsetException(true).expectedEndpointIdentity() == + new EndpointIdentity("articles", "1") + }As per coding guidelines, "Add or update mirrored Spock tests for requested production behavior."
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@jsonapi-java-core/src/test/groovy/io/github/kazemek/jsonapi/core/validation/UpdateRequestValidationSpec.groovy` around lines 282 - 293, Extend the UpdateRequestValidationSpec coverage around the existing matching endpoint identity test to apply withDocumentUsage, withLinksContext, and withSparseFieldsetException after withExpectedEndpointIdentity, then validate the document and assert no exception is thrown. Ensure the test verifies expectedEndpointIdentity is preserved through each with* method rather than setting it last.Source: Coding guidelines
jsonapi-java-core/src/main/java/io/github/kazemek/jsonapi/core/validation/JsonApiDocumentValidator.java (1)
327-348: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueReplace the path-string primary-scope test with an explicit parameter.
Both this method and
validateResourceRelationshipsat line 157 detect the primary resource by comparingpathto the"/data"literal. This couples an update-policy decision to pointer formatting. A future change to the primary pointer, or a new caller that passes an equivalent path, would silently disable the update rules. Pass aboolean primaryflag fromvalidatePrimaryDatainstead.This is a maintainability improvement. Current behavior is correct because
validatePrimaryDatais the only caller that usesPATH_DATA, and update documents allow only single-resource primary data.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@jsonapi-java-core/src/main/java/io/github/kazemek/jsonapi/core/validation/JsonApiDocumentValidator.java` around lines 327 - 348, Replace path-based primary-resource detection in validateUpdateEndpointIdentity and validateResourceRelationships with an explicit boolean primary parameter. Update validatePrimaryData to pass true for the primary resource and pass false for relationship resources or other callers, then base the update-policy checks on that flag instead of comparing path with PATH_DATA. Preserve the existing validation behavior for primary update data.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.agentWork/milestones/phase-1-3-update-request-validation.md:
- Around line 232-254: Update the Phase 1.3 milestone document to mark the
milestone complete only when every listed acceptance criterion has supporting
evidence; otherwise keep it incomplete and record blockers for each unverified
test, build, Spotless, module-docs, or Sonar check. Then synchronize the
corresponding milestone status in the milestone index README.
In `@docs/conformance.md`:
- Line 68: Update the conformance checklist row for omitted/present/present-null
attributes and wrappers to distinguish absent or present-empty relationship
wrappers from explicit null values within Attributes. Clarify that attributes:
null and relationships: null are not implied as supported, while preserving the
documented no-normalization behavior.
---
Nitpick comments:
In
`@jsonapi-java-core/src/main/java/io/github/kazemek/jsonapi/core/validation/JsonApiDocumentValidator.java`:
- Around line 327-348: Replace path-based primary-resource detection in
validateUpdateEndpointIdentity and validateResourceRelationships with an
explicit boolean primary parameter. Update validatePrimaryData to pass true for
the primary resource and pass false for relationship resources or other callers,
then base the update-policy checks on that flag instead of comparing path with
PATH_DATA. Preserve the existing validation behavior for primary update data.
In
`@jsonapi-java-core/src/main/java/io/github/kazemek/jsonapi/core/validation/package-info.java`:
- Around line 9-13: Update the UPDATE_REQUEST documentation in package-info.java
to clarify that the replacement data requirement applies only to relationships
of the primary resource; explicitly preserve response semantics for included
resources.
In
`@jsonapi-java-core/src/test/groovy/io/github/kazemek/jsonapi/core/validation/UpdateRequestValidationSpec.groovy`:
- Around line 282-293: Extend the UpdateRequestValidationSpec coverage around
the existing matching endpoint identity test to apply withDocumentUsage,
withLinksContext, and withSparseFieldsetException after
withExpectedEndpointIdentity, then validate the document and assert no exception
is thrown. Ensure the test verifies expectedEndpointIdentity is preserved
through each with* method rather than setting it last.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: f35c679a-5d88-4256-ac6c-5af7627ddeac
📒 Files selected for processing (15)
.agentWork/milestones/README.md.agentWork/milestones/phase-1-3-update-request-validation.mddocs/conformance.mdjsonapi-java-core/README.mdjsonapi-java-core/src/main/java/io/github/kazemek/jsonapi/core/validation/DocumentUsage.javajsonapi-java-core/src/main/java/io/github/kazemek/jsonapi/core/validation/EndpointIdentity.javajsonapi-java-core/src/main/java/io/github/kazemek/jsonapi/core/validation/JsonApiDocumentValidator.javajsonapi-java-core/src/main/java/io/github/kazemek/jsonapi/core/validation/ValidationContext.javajsonapi-java-core/src/main/java/io/github/kazemek/jsonapi/core/validation/ValidationRuleCode.javajsonapi-java-core/src/main/java/io/github/kazemek/jsonapi/core/validation/package-info.javajsonapi-java-core/src/test/groovy/io/github/kazemek/jsonapi/core/validation/JsonApiDocumentValidatorSpec.groovyjsonapi-java-core/src/test/groovy/io/github/kazemek/jsonapi/core/validation/UpdateRequestValidationSpec.groovyjsonapi-java-core/src/test/groovy/io/github/kazemek/jsonapi/core/validation/ValidatorCoverageSpec.groovyjsonapi-java-jackson3/src/test/groovy/io/github/kazemek/jsonapi/jackson3/DocumentReaderSpec.groovyjsonapi-java-test-fixtures/src/main/groovy/io/github/kazemek/jsonapi/testfixtures/writer/Models.groovy
Thread a boolean primary flag from validatePrimaryData instead of comparing the resource path against /data, so primary-scoped update rules cannot be silently disabled by pointer-format changes.
Assert withDocumentUsage, withLinksContext, and withSparseFieldsetException preserve the expected endpoint identity, so a dropped copy-forward is caught.
Scope the update relationship-data wording to the primary resource, clarify presence states in the conformance checklist, mark the milestone acceptance criteria complete, and sync the milestone mechanism description to the primary flag.
|
Review feedback addressed in three commits pushed to
All gates green on the final tree: focused spec, |
|



Refine the milestone into an implementation-ready contract covering
endpoint-identity context, stable rule codes, primary-scoped update
rules, and both plan-review rounds.
Add UPDATE_REQUEST document usage with primary-single-resource shape,
relationship replacement-data, and optional expected endpoint identity
checks (EndpointIdentity on ValidationContext), scoped to the primary
resource so included resources keep response semantics.
Summary by CodeRabbit
New Features
Documentation
Tests