Add configurable PUT identifier policies - #100
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a configurable policy for where PUT identifiers may appear (URI vs payload) while preserving the existing default behavior (URI identifier required; payload identifier optional). This enables optional collection-level PUT routing when configured, updates generated docs/Allow headers accordingly, and introduces validation warnings plus regression tests.
Changes:
- Introduce
PutIdentifierPolicyand add PUT identifier location configuration toEntityWriteMethodConfig. - Enable/deny PUT routing on collection/instance routes based on identifier policy, and update Allow/doc generation accordingly.
- Add API config validation reporting (warnings) and expand test coverage for the new PUT behaviors.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| thingifier/src/test/java/uk/co/compendiumdev/thingifier/apiconfig/WriteMethodsConfigTest.java | Adds assertions and validation-warning tests for new PUT identifier policy defaults/config copying. |
| thingifier/src/test/java/uk/co/compendiumdev/thingifier/api/restapihandlers/WriteMethodPolicyTest.java | Adds end-to-end REST policy tests for default behavior, collection PUT, and identifier policy combinations. |
| thingifier/src/test/java/uk/co/compendiumdev/thingifier/api/restapihandlers/ThingWriteRequestMapperTest.java | Adds mapper-level tests for collection PUT mapping and identifier-policy validation errors. |
| thingifier/src/main/java/uk/co/compendiumdev/thingifier/application/EntityInstanceDraftBuilder.java | Treats primary key fields as identity fields to prevent unintended PK changes during replacement. |
| thingifier/src/main/java/uk/co/compendiumdev/thingifier/application/AmendThingHandler.java | Preserves primary key on replace by injecting identifier into field values when missing. |
| thingifier/src/main/java/uk/co/compendiumdev/thingifier/apiconfig/WriteMethodsConfig.java | Adds validation entry point for write-method configuration. |
| thingifier/src/main/java/uk/co/compendiumdev/thingifier/apiconfig/ThingifierApiConfig.java | Exposes validate() to surface write-method validation results. |
| thingifier/src/main/java/uk/co/compendiumdev/thingifier/apiconfig/PutIdentifierPolicy.java | New enum defining identifier location policy (MANDATORY/OPTIONAL/DISALLOWED). |
| thingifier/src/main/java/uk/co/compendiumdev/thingifier/apiconfig/EntityWriteMethodConfig.java | Adds PUT identifier policy fields, setters/getters, copy behavior, and validation warning emission. |
| thingifier/src/main/java/uk/co/compendiumdev/thingifier/apiconfig/ApiConfigValidationReport.java | New report type for config validation errors/warnings. |
| thingifier/src/main/java/uk/co/compendiumdev/thingifier/api/spec/ThingifierApiSpec.java | Extends write-policy rule generation to include collection-level PUT rules. |
| thingifier/src/main/java/uk/co/compendiumdev/thingifier/api/restapihandlers/RestApiPutHandler.java | Passes entity write-method config into the PUT request mapper for policy-aware mapping. |
| thingifier/src/main/java/uk/co/compendiumdev/thingifier/api/http/ThingifierRequestContext.java | Adds store query helper for “entity exists by identifier” checks. |
| thingifier/src/main/java/uk/co/compendiumdev/thingifier/api/docgen/WriteMethodRoutePolicy.java | Applies identifier-policy gating to generated PUT routes and rejects invalid configs. |
| thingifier/src/main/java/uk/co/compendiumdev/thingifier/adapter/http/apihandlers/WriteMethodPolicy.java | Updates runtime method-allowance decisions and Allow header generation to consider PUT identifier policy and collection PUT. |
| thingifier/src/main/java/uk/co/compendiumdev/thingifier/adapter/http/apihandlers/ThingWriteRequestMapper.java | Enables collection PUT mapping when configured and enforces identifier policy during PUT mapping. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+127
to
+147
| boolean hasPayloadIdentifier = hasPayloadIdentifier(bodyFields, entity); | ||
| if (entityWriteMethods.putIdentifierInPayload() == PutIdentifierPolicy.MANDATORY | ||
| && !hasPayloadIdentifier) { | ||
| if (!entity.hasPrimaryKeyField()) { | ||
| return missingPrimaryKeyDefinitionError(entity); | ||
| } | ||
| return ApiMappingError.withMessage( | ||
| 422, | ||
| String.format( | ||
| "PUT payload must include identifier field %s", | ||
| entity.primaryKeyFieldName())); | ||
| } | ||
| if (entityWriteMethods.putIdentifierInPayload() == PutIdentifierPolicy.DISALLOWED | ||
| && hasPayloadIdentifier) { | ||
| return ApiMappingError.withMessage( | ||
| 422, | ||
| String.format( | ||
| "PUT payload must not include identifier field %s", | ||
| entity.primaryKeyFieldName())); | ||
| } | ||
| return null; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Adds configurable PUT identifier location policies for core Thingifier behavior, preserving the default URI-mandatory and payload-optional behavior. Includes collection-level PUT routing when enabled, validation warnings, generated docs and Allow header updates, replacement primary-key preservation, and focused regression coverage.\n\nValidation:\n- mvn -pl thingifier -Dtest=WriteMethodsConfigTest,ThingWriteRequestMapperTest,WriteMethodPolicyTest test\n- mvn -pl thingifier test\n- mvn -pl thingifier verify reaches existing Checkstyle project-rule violations outside this change