# lawref.schemas

*module*

Реестр нормативных схем базового пакета (WP-03 + DECISION-0006).

Решение по кодогенерации (WP-03, зафиксировано): типы пишутся руками в обеих
реализациях, схемы служат контрактом через валидацию — кодогенераторы из JSON
Schema 2020-12 не переваривают allOf/if-then legal-ir и дают непригодные типы.
Addendum-схемы (ontology-package, kz-corpus-*) — вне скоупа (план WP-03).

SPEC [§0.1](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/00-preamble.ru.md#01-нормативные-артефакты-и-порядок-разрешения-расхождений): схемы нормативно определяют форму, prose — семантику.

## lawref.schemas.IR_SCHEMA_VERSIONS

*attribute* · *module attribute*

```python
IR_SCHEMA_VERSIONS = ('law.core.ir/0.1', 'law.core.ir/0.2', 'law.core.ir/0.3', 'law.core.ir/0.4', 'law.core.ir/0.5')
```

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/schemas.py#L116-L117)

## lawref.schemas.NORMATIVE_SCHEMAS

*attribute* · *module attribute*

```python
NORMATIVE_SCHEMAS = {'concept-catalog-inputs': 'concept-catalog-inputs.schema.json', 'concept-alignment-policy': 'concept-alignment-policy.schema.json', 'concept-alignment-report': 'concept-alignment-report.schema.json', 'concept-rule-alignment-policy': 'concept-rule-alignment-policy.schema.json', 'concept-rule-alignment-report': 'concept-rule-alignment-report.schema.json', 'import-ir': 'import-ir.schema.json', 'import-mapping': 'import-mapping.schema.json', 'import-package-policy': 'import-package-policy.schema.json', 'import-package-plan': 'import-package-plan.schema.json', 'import-bundle': 'import-bundle.schema.json', 'import-report': 'import-report.schema.json', 'import-recipe': 'import-recipe.schema.json', 'native-records': 'native-records.schema.json', 'native-modules': 'native-modules.schema.json', 'import-diff': 'import-diff.schema.json', 'native-dag': 'native-dag.schema.json', 'import-inventory': 'import-inventory.schema.json', 'import-coverage': 'import-coverage.schema.json', 'import-adapter': 'import-adapter.schema.json', 'legal-ir': 'legal-ir.schema.json', 'evaluation': 'evaluation.schema.json', 'calendar-dataset': 'calendar-dataset.schema.json', 'package-manifest': 'package-manifest.schema.json', 'package-info': 'package-info.schema.json', 'package-passport': 'package-passport.schema.json', 'case-export': 'case-export.schema.json', 'profile': 'profile.schema.json', 'profile-descriptor': 'profile-descriptor.schema.json', 'package-report': 'package-report.schema.json', 'package-benchmark': 'package-benchmark.schema.json', 'lockfile': 'lockfile.schema.json', 'diagnostic': 'diagnostic.schema.json', 'editor-index': 'editor-index.schema.json', 'editor-source-map': 'editor-source-map.schema.json', 'law-expansion': 'law-expansion.schema.json', 'conformance-descriptor': 'conformance-descriptor.schema.json', 'review-approval': 'review-approval.schema.json', 'feature-registry': 'feature-registry.schema.json', 'parameter-dataset': 'parameter-dataset.schema.json', 'decision-table': 'decision-table.schema.json', 'external-snapshot': 'external-snapshot.schema.json', 'counterfactual-input': 'counterfactual-input.schema.json', 'counterfactual-result': 'counterfactual-result.schema.json', 'query-result': 'query-result.schema.json', 'query': 'query.schema.json', 'focused-evaluation': 'focused-evaluation.schema.json', 'business-requirements': 'business-requirements.schema.json', 'evaluation-request': 'evaluation-request.schema.json', 'screen-binding': 'screen-binding.schema.json', 'change-set': 'change-set.schema.json', 'change-dossier': 'change-dossier.schema.json', 'population-bank': 'population-bank.schema.json', 'population-binding': 'population-binding.schema.json', 'population-materialization': 'population-materialization.schema.json', 'population-impact-report': 'population-impact-report.schema.json', 'package-descriptor': 'package-descriptor.schema.json', 'package-questions': 'package-questions.schema.json'}
```

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/schemas.py#L33-L110)

## lawref.schemas.SCHEMA_BASE_URL

*attribute* · *module attribute*

```python
SCHEMA_BASE_URL = 'https://law.arxo.io/schema/'
```

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/schemas.py#L30-L30)

## lawref.schemas.SCHEMA_DIR

*attribute* · *module attribute*

```python
SCHEMA_DIR = schema_dir()
```

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/schemas.py#L26-L26)

## lawref.schemas.VERDICT_CACHE_DIR

*attribute* · *module attribute*

```python
VERDICT_CACHE_DIR = cache_dir() / 'schema-verdicts'
```

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/schemas.py#L189-L189)

## lawref.schemas.cached_valid

*function*

```python
def cached_valid(name: str, raw: bytes) -> bool
```

Есть ли в кэше положительный вердикт для этих байтов под этой схемой.

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/schemas.py#L212-L217)

## lawref.schemas.fast_validator

*function* · *cached*

```python
def fast_validator(name: str)
```

Скомпилированный `fastjsonschema`-валидатор схемы либо None, если
зависимости нет или схема ему не по зубам (тогда только `jsonschema`).

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/schemas.py#L164-L178)

## lawref.schemas.load

*function* · *cached*

```python
def load(name: str) -> dict
```

Загрузка схемы по имени с self-check-ом (Draft 2020-12).

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/schemas.py#L120-L126)

## lawref.schemas.registry

*function* · *cached*

```python
def registry() -> Registry
```

Registry for relative cross-schema references used by Core artifacts.

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/schemas.py#L129-L146)

## lawref.schemas.remember_valid

*function*

```python
def remember_valid(name: str, raw: bytes) -> None
```

Записать положительный вердикт (атомарно; ошибки ввода-вывода молча).

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/schemas.py#L220-L231)

## lawref.schemas.schemas_fingerprint

*function* · *cached*

```python
def schemas_fingerprint() -> str
```

sha256 байтов всех нормативных схем и формата кэша — отпечаток вердикта.

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/schemas.py#L193-L202)

## lawref.schemas.validate

*function*

```python
def validate(name: str, document: dict) -> list[str]
```

Список сообщений об ошибках; пустой — документ валиден.

Валидный документ (штатный путь: CLIR зависимостей при каждом `ask`,
минуты `jsonschema` на КоАП) проверяется скомпилированным
`fastjsonschema` — на порядок быстрее. Найденная им ошибка не
отчитывается его словами: документ заново проходит `jsonschema`, чьи
формулировки входят в конверты отказов и голдены; ответ тот же байт в байт.

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/schemas.py#L245-L265)

## lawref.schemas.validate_bytes

*function*

```python
def validate_bytes(name: str, raw: bytes, document: dict) -> list[str]
```

`validate` с кэшем между запусками по байтам документа: `raw` — те
самые байты, из которых разобран `document`.

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/schemas.py#L234-L242)

## lawref.schemas.validator

*function* · *cached*

```python
def validator(name: str) -> Draft202012Validator
```

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/schemas.py#L149-L151)
