topmark.toml.schema¶
Static TOML schema metadata and validation helpers for TopMark.
This module defines the explicit, typed schema used to validate the structure
of TopMark TOML documents before value-level parsing. It complements
topmark.toml.keys, which remains the canonical registry
for user-facing TOML section/key names while this module owns structural schema
metadata and validation rules.
The schema layer focuses on shape validation
- known top-level sections,
- allowed keys inside closed sections,
- open sections such as
[fields], - nested policy subtables such as
[policy_by_type.<filetype>], - dump/provenance-only keys that should not appear in ordinary input mode.
Malformed-section handling policy
- unknown sections/keys are reported as warnings and ignored,
- known sections with invalid shapes (for example a scalar where a table is required) are reported as warnings and ignored,
- malformed nested child sections such as
[policy_by_type.<filetype>]follow the same warning-and-ignore policy, - missing known sections are reported as informational diagnostics so callers can distinguish absent sections from malformed-present sections.
TomlSection ¶
Bases: str, Enum
Known top-level TOML sections owned by TopMark.
TomlValidationMode ¶
Bases: str, Enum
Validation modes for TopMark TOML documents.
INPUT validates user-authored configuration. PROVENANCE additionally
allows dump-only keys emitted by commands such as
topmark config dump --show-origin.
TomlSchemaSection
dataclass
¶
Schema metadata for a named top-level TOML section.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
TomlSection
|
Canonical top-level section name. |
allowed_keys |
frozenset[str]
|
Keys accepted directly inside this section. |
open_keys |
bool
|
Whether arbitrary user-defined keys are allowed. |
dump_only_keys |
frozenset[str]
|
Extra keys valid only in provenance/dump mode. |
keys_for_mode ¶
Return the effective allowed keys for the given validation mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode
|
TomlValidationMode
|
Validation mode to evaluate. |
required |
Returns:
| Type | Description |
|---|---|
frozenset[str]
|
Allowed keys, including dump-only keys in provenance mode. |
Source code in src/topmark/toml/schema.py
TomlNestedSchema
dataclass
¶
Schema metadata for dynamic nested TOML subtables.
This is used for structures such as [policy_by_type.<filetype>], where
the child table names are dynamic but the keys inside each child table are
fixed.
Attributes:
| Name | Type | Description |
|---|---|---|
parent |
TomlSection
|
Parent top-level section containing dynamic child subtables. |
allowed_child_keys |
frozenset[str]
|
Keys accepted in each child subtable. |
child_label |
str
|
Human-readable label for the dynamic child name. |
TomlSchema
dataclass
¶
Static schema for TopMark TOML document shape validation.
The schema owns section-level structure and emits
TomlValidationIssue
instances for unknown keys, wrong section shapes, and nested-policy shape
mismatches.
Attributes:
| Name | Type | Description |
|---|---|---|
sections |
dict[TomlSection, TomlSchemaSection]
|
Mapping of known top-level sections to their schema metadata. |
policy_by_type_nested |
TomlNestedSchema | None
|
Optional nested schema for
|
validate_top_level_keys ¶
Validate top-level entries and section table shapes.
Top-level TopMark TOML entries are expected to be named sections such as
[config] or [files]. Unknown top-level tables are therefore reported
as unknown sections, while unknown non-table entries are reported as
misplaced top-level keys.
Known sections must be TOML tables. When a known section is present with the wrong shape, the validator emits a warning and the malformed section is ignored by later parsing. Missing sections are not diagnosed by this helper; they are reported later during full-schema validation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table
|
TomlTable
|
Top-level TOML table to validate. |
required |
mode
|
TomlValidationMode
|
Validation mode controlling context-specific allowances. |
required |
Returns:
| Type | Description |
|---|---|
TomlValidationIssue
|
Structured validation issues for unknown top-level entries and |
...
|
invalid top-level section types. |
Source code in src/topmark/toml/schema.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | |
validate_section_keys ¶
Validate keys inside a known top-level TOML section.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
section
|
TomlSection
|
Known section being validated. |
required |
table
|
TomlTable
|
Section table contents. |
required |
mode
|
TomlValidationMode
|
Validation mode controlling dump-only-key allowances. |
required |
Returns:
| Type | Description |
|---|---|
tuple[TomlValidationIssue, ...]
|
Structured validation issues for unknown or context-disallowed keys. |
Source code in src/topmark/toml/schema.py
validate ¶
Validate a complete TopMark TOML table against the static schema.
This performs shape validation for the full TopMark TOML fragment, including top-level entries, fixed-key sections, open sections, and nested policy-by-type child tables.
The validator is intentionally non-fatal for malformed sections: warnings are emitted, malformed sections are ignored by later parsing, and validation continues so callers can accumulate a complete issue set. Missing known sections are reported as informational diagnostics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table
|
TomlTable
|
Top-level TOML table to validate. |
required |
mode
|
TomlValidationMode
|
Validation mode controlling dump-only-key allowances. |
required |
Returns:
| Type | Description |
|---|---|
tuple[TomlValidationIssue, ...]
|
Structured TOML validation issues. |