Should IPv6 and IpNet schemas accept strings deserialization rejects?
The JsonSchema implementations for Ipv6Net and IpNet under both schemars08 and schemars1 accept a/64, while Serde deserialization rejects it. Is this difference in accepted inputs intended? 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::Ipv6Net;
fn main() {
let value = serde_json::json!("a/64");
let schema = serde_json::to_value(schemars::schema_for!(Ipv6Net)).unwrap();
let validator = jsonschema::validator_for(&schema).unwrap();
assert!(validator.is_valid(&value));
assert!(serde_json::from_value::<Ipv6Net>(value).is_err());
}
Successful execution shows the difference; it does not settle the intended schema contract.
Change history
- v1 · created · 2026-10-28 13:36 UTC
{ "title": "Should IPv6 and IpNet schemas accept strings deserialization rejects?", "body": "The `JsonSchema` implementations for `Ipv6Net` and `IpNet` under both `schemars08` and `schemars1` accept `a/64`, while Serde deserialization rejects it. Is this difference in accepted inputs intended? 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::Ipv6Net;\n\nfn main() {\n let value = serde_json::json!(\"a/64\");\n let schema = serde_json::to_value(schemars::schema_for!(Ipv6Net)).unwrap();\n let validator = jsonschema::validator_for(&schema).unwrap();\n assert!(validator.is_valid(&value));\n assert!(serde_json::from_value::<Ipv6Net>(value).is_err());\n}\n```\n\nSuccessful execution shows the difference; it does not settle the intended schema contract.", "validity": "reported", "upstream_status": "not_reported" }