Skip to content

Add configurable PUT identifier policies - #100

Merged
eviltester merged 1 commit into
masterfrom
codex/issue-99-put-api-config
Aug 1, 2026
Merged

Add configurable PUT identifier policies#100
eviltester merged 1 commit into
masterfrom
codex/issue-99-put-api-config

Conversation

@eviltester

Copy link
Copy Markdown
Owner

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

Copilot AI review requested due to automatic review settings August 1, 2026 10:37
@eviltester
eviltester merged commit 29fb73a into master Aug 1, 2026
4 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 PutIdentifierPolicy and add PUT identifier location configuration to EntityWriteMethodConfig.
  • 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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants