1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//! Shared YAML spec version validation helper.
//! Ensures presence of integer `version` field and equality to expected version.
//! Centralizes error message strings to keep parser modules consistent.
//!
//! # Purpose
//! Single source of truth for spec version checks so all parsers emit identical
//! error messages and evolve coherently when new versions are introduced.
//!
//! # Usage
//! ```rust,ignore
//! use serde_yaml::Value;
//! // Inside crate: use spec::version::validate_version
//! let v: Value = serde_yaml::from_str("version: 1").unwrap();
//! let ver = allora::spec::version::validate_version(&v).unwrap();
//! assert_eq!(ver, 1);
//! ```
//!
//! # Error Semantics
//! * Missing field -> `missing 'version'`
//! * Non-integer type -> `'version' must be integer`
//! * Unsupported value -> `unsupported version (expected 1)`
//!
//! # Extension Strategy
//! For a future v2 schema, prefer adding `validate_version_v2` or making this
//! function accept an `expected: u32` parameter. Keep old helper available to
//! avoid breaking existing parsers. Example:
//! ```ignore
//! pub(crate) fn validate_version_expected(yaml: &Value, expected: u32) -> Result<u32> { /* ... */ }
//! ```
//!
//! # Design Notes
//! * Returns `u32` (small range, explicit cast from i64): avoids accidental
//! negative values after validation.
//! * Does not attempt coercion (e.g. strings); strict typing keeps configs clean.
//! * Performs only version validation; structural validation remains in each
//! parser to keep responsibilities localized.
use crate;
use Value as YamlValue;
/// Validate that `yaml` contains an integer `version` equal to 1.
///
/// # Errors
/// * Missing field -> `"missing 'version'"`
/// * Non-integer -> `"'version' must be integer"`
/// * Unsupported value -> `"unsupported version (expected 1)"`
pub