IpNet schema rejects a serialized IPv4 network
A serialized IpNet should satisfy its generated schema, but the JsonSchema implementations for IpNet under both schemars08 and schemars1 reject 192.168.0.0/24: it matches both oneOf branches. See the 0.8 integration and 1.x integration.
For ipnet 2.12.2 with serde and schemars1, run cargo run with:
[dependencies]
ipnet = { version = "=2.12.2", features = ["serde", "schemars1"] }
schemars = { version = "=1.2.1", default-features = false }
serde_json = "=1.0.151"
jsonschema = { version = "=0.33.0", default-features = false }
use ipnet::IpNet;
fn main() {
let net: IpNet = "192.168.0.0/24".parse().unwrap();
let value = serde_json::to_value(net).unwrap();
let schema = serde_json::to_value(schemars::schema_for!(IpNet)).unwrap();
let validator = jsonschema::validator_for(&schema).unwrap();
assert!(validator.is_valid(&value));
}
The assertion fails: the generated schema rejects the serialized value.
Change history
- v1 · created · 2026-10-28 13:36 UTC
{ "title": "IpNet schema rejects a serialized IPv4 network", "body": "A serialized `IpNet` should satisfy its generated schema, but the `JsonSchema` implementations for `IpNet` under both `schemars08` and `schemars1` reject `192.168.0.0/24`: it matches both `oneOf` branches. See the [0.8 integration](https://github.com/krisprice/ipnet/blob/13c5c5873c02127679b1e8e64b538e4e36942640/src/ipnet_schemars_08.rs) and [1.x integration](https://github.com/krisprice/ipnet/blob/13c5c5873c02127679b1e8e64b538e4e36942640/src/ipnet_schemars_1.rs).\n\nFor ipnet 2.12.2 with `serde` and `schemars1`, run `cargo run` with:\n\n```toml\n[dependencies]\nipnet = { version = \"=2.12.2\", features = [\"serde\", \"schemars1\"] }\nschemars = { version = \"=1.2.1\", default-features = false }\nserde_json = \"=1.0.151\"\njsonschema = { version = \"=0.33.0\", default-features = false }\n```\n\n```rust\nuse ipnet::IpNet;\n\nfn main() {\n let net: IpNet = \"192.168.0.0/24\".parse().unwrap();\n let value = serde_json::to_value(net).unwrap();\n let schema = serde_json::to_value(schemars::schema_for!(IpNet)).unwrap();\n let validator = jsonschema::validator_for(&schema).unwrap();\n assert!(validator.is_valid(&value));\n}\n```\n\nThe assertion fails: the generated schema rejects the serialized value.", "validity": "reported", "upstream_status": "not_reported" } - v2 · link_added · 2026-10-28 13:54 UTC
{ "id": "f821e03c-bd17-4921-872a-7bf94e140cd7", "kind": "issue", "url": "https://github.com/krisprice/ipnet/issues/74", "version": null, "target_report_id": null, "target_revision_no": null, "edit_version": 1 }