feat: generate user-facing write/read schema models + offline validation
Summary
Adds generated, user-facing write and read schema models to the SDK plus an offline validate_schema() so a schema can be checked for correctness with no running Infrahub server. Part of the user-facing schema separation (opsmill/infrahub, INFP-234).
Key Changes
- New generated models
infrahub_sdk/schema/generated/{write,read}.py— the write model is exactly what/api/schema/loadaccepts (constrained fields carry their allowed values asLiteral[...];extra="forbid"); read = write + visible-but-not-settable fields. validate_schema()(infrahub_sdk/schema/validate.py) — field-level offline validation with dotted error locations; also gates schemaextensions.- Drift/presence guard test so the generated models can't silently go stale.
- Regenerated
protocols.py(pre-existing drift vs current backend schema).
Related Context
Generated from the backend's schema definitions; consumed by the backend PR (opsmill/infrahub). Depends on nothing else in this repo.
Test Plan
uv run pytest tests/unit/test_schema_offline_validation.py tests/unit/test_schema_generated_models.py
14 offline-validation cases + generated-model guard pass, pydantic-only (no server).
Notes
Draft: the backend still ships a parallel hand-written model set; full consolidation of the SDK's hand-written schema models is tracked as a follow-up.
🤖 Generated with Claude Code
Summary by cubic
Adds generated user-facing write/read schema models and an offline validator so schemas can be checked without a server. This separates user schema from internal models and satisfies INFP-234; validation covers extensions and now requires the root version.
-
New Features
- Committed generated models in
infrahub_sdk/schema/generated/{enums,write,read}.py; exportInfrahubSchema{Write,Read}and enums; read addsProfile/Template; write includesextensions;extra="ignore"withuse_enum_values=True. - Attributes and computed attributes are kind‑discriminated unions; typed
parametersandchoices; enums live ingenerated/enums.py. validate_schema()checks the full document (nodes,generics,extensions) viaInfrahubSchemaWrite, returnsSchemaValidationResultwith dotted paths; drops non‑write/unknown fields; includes a generated‑model drift guard; requiresversion.
- Committed generated models in
-
Refactors
- Public SDK schema classes now wrap the generated models;
*SchemaAPIinherit generated read models; enums re‑exported;CoreNodeBase._schemaisMainSchemaTypesAPI. - Read‑only
kind/hashmoved to generated read models; write nodes expose a non‑serializing.kind;SchemaRootexposesextensionsand validates payloads viaInfrahubSchemaWrite. - Relationship helpers inlined on
RelationshipSchemaAPI;AttributeSchemaconstruction is lenient; removedAttributeKind.STRING; defaults match the server (relationshipmin_count/max_count=0; nodebranch="aware",generate_profile=True,generate_template=False); regeneratedprotocols.py; skipIPAddresskind tests pending backend support.
- Public SDK schema classes now wrap the generated models;