Skip to content

feat(core): add validation of entity template property rules against type#45

Merged
evebrnd merged 18 commits intomainfrom
feat/add-property-rules-validation-of-entity-template
May 6, 2026
Merged

feat(core): add validation of entity template property rules against type#45
evebrnd merged 18 commits intomainfrom
feat/add-property-rules-validation-of-entity-template

Conversation

@evebrnd
Copy link
Copy Markdown
Collaborator

@evebrnd evebrnd commented Apr 27, 2026

PR Description

What this PR Provides

  • Validate property rules against their type when user creates or updates their template
  • STRING: support only format, enum_values, regex, max_length, and min_length (with 0 <= min <= max). enum_values, regex and format are incompatible, mutually exclusive. enum_values is also incompatible with max_length and min_length
  • NUMBER: support only max_value and min_value (with min_value < max_value)
  • BOOLEAN: enforce that no rule is provided
  • Enforce globally "fail on unknown properties" to avoid silent fails / edge cases of incoming JSON requests
  • Remove rules identifier from DTO OUT of templates
  • Property rules "format" and "enum_values" are case-insensitive

Review

The reviewer must double-check these points:

  • The reviewer has tested the feature
  • The reviewer has reviewed the implementation of the feature
  • The documentation has been updated
  • The feature implementation respects the Technical Doc / ADR previously produced

How to test

POST /entity-templates

  • Valid String rules: create a STRING with min_length <= max_length (201 Created)
  • Invalid String range: create a STRING with min_length > max_length (400 Bad Request)
  • Invalid String regex: create a STRING with an invalid regex pattern (400 Bad Request)
  • Dangerous String regex: create a STRING with a dangerous regex pattern (a+)+$ (400 Bad Request)
  • Valid Number rules: create a NUMBER with min_value < max_value (201 Created)
  • Incompatible rules: create a NUMBER containing a regex or format rule (400 Bad Request)
  • Boolean Rule violation: create a BOOLEAN with any rules object defined (400 Bad Request)

PUT /entity-templates

  • Update compatibility: update an existing template with a valid rule set (200 OK)
  • Invalid update: change an existing template to have incompatible type/rule pairs (400 Bad Request)

Breaking changes

N/A

@evebrnd evebrnd marked this pull request as ready for review April 27, 2026 16:05
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds domain-level validation to ensure EntityTemplate property rules are compatible with their declared property types during create/update, and tightens JSON deserialization to reject unknown request fields.

Changes:

  • Introduce PropertyRulesService + PropertyRulesConflictException and enforce validation from EntityTemplateService on create/update.
  • Map PropertyRulesConflictException to HTTP 400 and enable Jackson fail-on-unknown-properties.
  • Refactor API DTO out / mapper packages from entitytemplateentity_template and update tests/fixtures accordingly.

Reviewed changes

Copilot reviewed 19 out of 23 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
src/main/java/com/decathlon/idp_core/domain/service/entity_template/PropertyRulesService.java New domain validation logic for rule/type compatibility (STRING/NUMBER/BOOLEAN).
src/main/java/com/decathlon/idp_core/domain/service/entity_template/EntityTemplateService.java Calls property-rules validation during template create/update; renames update method.
src/main/java/com/decathlon/idp_core/domain/exception/PropertyRulesConflictException.java New domain exception used to surface rule/type conflicts.
src/main/java/com/decathlon/idp_core/infrastructure/adapters/api/handler/ApiExceptionHandler.java Maps PropertyRulesConflictException to HTTP 400 responses.
src/main/resources/application.yml Enables global Jackson fail-on-unknown-properties.
src/main/java/com/decathlon/idp_core/infrastructure/adapters/api/controller/EntityTemplateController.java Updates service method call and DTO out / mapper package imports.
src/main/java/com/decathlon/idp_core/infrastructure/adapters/api/mapper/entity_template/EntityTemplateMapper.java Moves mapper package and updates DTO out package imports.
src/main/java/com/decathlon/idp_core/infrastructure/adapters/api/mapper/entity/EntityDtoOutMapper.java Updates import to moved EntityTemplateService.
src/main/java/com/decathlon/idp_core/infrastructure/adapters/api/configuration/SwaggerConfiguration.java Updates import to moved EntityTemplateDtoOut package.
src/main/java/com/decathlon/idp_core/infrastructure/adapters/api/dto/out/entity_template/EntityTemplateDtoOut.java Package rename to entity_template.
src/main/java/com/decathlon/idp_core/infrastructure/adapters/api/dto/out/entity_template/PropertyDefinitionDtoOut.java Package rename to entity_template.
src/main/java/com/decathlon/idp_core/infrastructure/adapters/api/dto/out/entity_template/PropertyRulesDtoOut.java Package rename to entity_template.
src/main/java/com/decathlon/idp_core/infrastructure/adapters/api/dto/out/entity_template/RelationDefinitionDtoOut.java Package rename to entity_template.
src/main/java/com/decathlon/idp_core/domain/constant/ValidationMessages.java Adds property-rules validation message templates/helpers; adjusts relation message text.
src/main/java/com/decathlon/idp_core/domain/exception/EntityTemplateAlreadyExistsException.java Updates import to moved EntityTemplateService.
src/main/java/com/decathlon/idp_core/domain/exception/EntityTemplateNameAlreadyExistsException.java Updates import to moved EntityTemplateService.
src/test/java/com/decathlon/idp_core/domain/service/entity_template/PropertyRulesServiceTest.java New unit tests covering rule/type compatibility scenarios.
src/test/java/com/decathlon/idp_core/infrastructure/adapters/api/controller/EntityTemplateControllerTest.java Adds integration test for invalid STRING rules → 400.
src/test/java/com/decathlon/idp_core/infrastructure/adapters/api/mapper/EntityTemplateMapperTest.java Updates imports for renamed DTO out / mapper packages.
src/test/resources/integration_test/json/entity-template/v1/postEntityTemplate_400_invalid_rules.json New fixture for invalid rule/type combinations.
src/test/resources/integration_test/json/entity-template/v1/postEntityTemplate_201.json Adjusts fixture rules to avoid disallowed numeric rules for STRING.
src/test/resources/integration_test/json/entity-template/v1/postEntityTemplateWithoutRelationsDefinitions_201.json Adjusts fixture rules to avoid disallowed numeric rules for STRING.
src/test/resources/integration_test/json/entity-template/v1/putEntityTemplate_200.json Adjusts fixture rules to avoid disallowed numeric rules for STRING.

Comment thread src/main/resources/application.yml
Comment thread src/main/java/com/decathlon/idp_core/domain/constant/ValidationMessages.java Outdated
Copy link
Copy Markdown
Collaborator

@brandPittCode brandPittCode left a comment

Choose a reason for hiding this comment

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

Drop the rules.id field from the PropertyRulesDtoOut.

We should make our enum caseInsensitive for the inputDto. For example for type in the propertyDefinition object.

We can explore the spring configuration way:
jackson:
deserialization:
read_enum_values_using_index: false
accept_case_insensitive_enums: true

or the annotation in class option.

@Tchoupinax
Copy link
Copy Markdown

Coucou

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 6, 2026

@evebrnd evebrnd merged commit 6047c3c into main May 6, 2026
20 checks passed
@evebrnd evebrnd deleted the feat/add-property-rules-validation-of-entity-template branch May 6, 2026 14:15
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.

5 participants