krisprice / ipnet

IpNet, Ipv4Net, and Ipv6Net types and methods for Rust
Apache License 2.0
122 stars 26 forks source link

JsonSchema does not correspond to Serde representation #40

Closed hgzimmerman closed 2 years ago

hgzimmerman commented 2 years ago

Currently, the JsonSchema trait is derived instead of manually implemented to match the parser for IpNet, IpV4Net, and IpV6Net. This causes it to generate a schema object that indicates that for IpV4Net, the serde deserializer expects a JSON object like:

{
    "addr": "0.0.0.0",
    "prefix_len": 0
}

when in reality, the deserializer expects, and serializer produces:

"0.0.0.0/0"

This can be resolved by implementing JsonSchema manually

krisprice commented 2 years ago

Hi @hgzimmerman - thanks. Yeah I figured this would be needed hence asking in the original PR #31 if the default output was actually satisfactory. Since @smklein was the original requestor for this with the use case at his employer Oxide I wonder if he could weigh in here on whether this change will work for him or not? CC @ralpha and @xfbs in case they have opinions too.

Thanks

smklein commented 2 years ago

That change works for us - the 0.0.0.0/0 format actually matches our hand-rolled implementation more closely than the derived version!

krisprice commented 2 years ago

Thanks @hgzimmerman and @smklein I've merged and published these fixes.

hgzimmerman commented 2 years ago

Thanks!