Skip to content

Keep IPv4 and IPv6 JSON schema alternatives disjoint - #75

Open
omrzk wants to merge 1 commit into
krisprice:masterfrom
omrzk:fix/disjoint-ipnet-schemas-74
Open

omrzk wants to merge 1 commit into
krisprice:masterfrom
omrzk:fix/disjoint-ipnet-schemas-74

Conversation

@omrzk

@omrzk omrzk commented Oct 29, 2026

Copy link
Copy Markdown

192.168.0.0/24 matches both oneOf alternatives generated for IpNet, so the schema rejects a value produced by its own serializer. The IPv6 regex currently accepts a dotted IPv4 address without any colon.

Require a colon in the IPv6 pattern in both schemars integrations. IPv4 values then match only the IPv4 branch, while compressed, full-width and IPv4-mapped IPv6 values continue to match the IPv6 branch. Fixes #74.

The regression uses an actual JSON Schema validator against serialized IpNet, Ipv4Net and Ipv6Net values, including wrong-family and invalid-prefix controls; both schemars versions fail against the original source. With the fix:

  • cargo test --all-features: 37 unit tests, 2 schema regressions and 56 doctests pass.
  • cargo test --no-default-features --features serde,schemars08 and the corresponding serde,schemars1 command: each passes 37 unit tests, its schema regression and 56 doctests.
  • cargo build --all-features, cargo clippy --all-features --all-targets, focused test formatting and git diff --check pass. Clippy reports existing source warnings, also present on a clean-master control.

The JSON Schema validator is a development-only dependency with network-resolution defaults disabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IpNet schema rejects a serialized IPv4 network

1 participant