Files
mdm-ordinis/ordinis-rest-api
Zimin A.N. 414267807e feat(refs): cross-dictionary x-references validation (v2)
JSON Schema extension `x-references: "dict_name.field"` объявляет что
значение поля должно ссылаться на active record в указанном словаре.
На POST/PUT record service валидирует existence + scope visibility.

Пример:
  {
    "type":"object",
    "properties":{
      "satTypeCode":{
        "type":"string",
        "x-references":"satellite_type.code"
      }
    }
  }

ReferenceValidator (ordinis-rest-api/service/reference/):
- Walks schema properties, finds x-references markers
- Для каждого ref: lookup target dictionary + active record by JSONB
  field value (использует existing findActiveByJsonField repo method)
- Returns ValidationError list, intergrates с RecordValidator pipeline
  через DictionaryRecordService.validate()
- Scope hide: target dict не accessible → "not_found" error (не
  "scope_denied"), чтобы не leak'ало existence
- Optional поля: если value missing, skip (JSON Schema validation
  отдельно отлавливает required)

Error codes:
- x_references_malformed (spec не "dict.field")
- x_references_dict_not_found (target dictionary не существует)
- x_references_target_not_found (referenced record нет / scope hidden)
- x_references_non_string (v1 поддерживает только string values)

v1 ограничения (документированы в JavaDoc):
- Top-level fields only (nested objects не поддержаны)
- Only string values
- No cascade on delete/close (orphan FK alert — v2.5)

Tests (15 в ReferenceValidatorTest):
- parseRef: valid, empty, missing dot, trailing dot, nested paths
- validate: no refs, missing value (optional skip), existing record OK,
  missing record error, missing dictionary error, scope-hidden error,
  non-string value error, malformed spec error, multiple fields
  validated independently, null schema graceful

Total project tests: 176 → 191.

Note: Mockito не может mock entity classes на JDK 25 (subclass
mock-maker limitation). Используем real entity ctor для
DictionaryDefinition + DictionaryRecord в тестах.
2026-05-06 17:13:47 +03:00
..