$ cargo test --features=schemars test_ipnetwork_json
Blocking waiting for file lock on build directory
Compiling does-it-json v0.0.1 (/Users/ahl/src/does-it-json)
Compiling ipnetwork v0.19.0 (/Users/ahl/src/ipnetwork)
Finished test [unoptimized + debuginfo] target(s) in 2.20s
Running unittests src/lib.rs (target/debug/deps/ipnetwork-5bc3e27d373077a5)
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 63 filtered out; finished in 0.00s
Running tests/test_json.rs (target/debug/deps/test_json-c7e0909f58ffe5cf)
running 1 test
test tests::test_ipnetwork_json ... FAILED
failures:
---- tests::test_ipnetwork_json stdout ----
thread 'tests::test_ipnetwork_json' panicked at 'error: "127.1.0.0/24" did not conform to the schema at #/definitions/IpNetwork.oneOf: value validated against 0 of 2 `oneOf` schemas (rather than 1)
schema: {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "MyStruct",
"type": "object",
"required": [
"ipnetwork"
],
"properties": {
"ipnetwork": {
"type": "array",
"items": {
"$ref": "#/definitions/IpNetwork"
}
}
},
"definitions": {
"IpNetwork": {
"description": "Represents a generic network range. This type can have two variants: the v4 and the v6 case.",
"oneOf": [
{
"type": "object",
"required": [
"V4"
],
"properties": {
"V4": {
"$ref": "#/definitions/Ipv4Network"
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"V6"
],
"properties": {
"V6": {
"$ref": "#/definitions/Ipv6Network"
}
},
"additionalProperties": false
}
]
},
"Ipv4Network": {
"description": "Represents a network range where the IP addresses are of v4",
"type": "object",
"required": [
"addr",
"prefix"
],
"properties": {
"addr": {
"type": "string",
"format": "ipv4"
},
"prefix": {
"type": "integer",
"format": "uint8",
"minimum": 0.0
}
}
},
"Ipv6Network": {
"description": "Represents a network range where the IP addresses are of v6",
"type": "object",
"required": [
"addr",
"prefix"
],
"properties": {
"addr": {
"type": "string",
"format": "ipv6"
},
"prefix": {
"type": "integer",
"format": "uint8",
"minimum": 0.0
}
}
}
}
}
value: {
"ipnetwork": [
"127.1.0.0/24",
"::1/0"
]
}', tests/test_json.rs:69:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
tests::test_ipnetwork_json
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 2 filtered out; finished in 0.00s
error: test failed, to rerun pass '--test test_json'
The problem is that #153 simply derived JsonSchema rather than generating a schema that matches the implementation of Serialize. I would be happy to submit a PR; just let me know.
See: https://github.com/ahl/ipnetwork/tree/fail
The problem is that #153 simply derived
JsonSchema
rather than generating a schema that matches the implementation ofSerialize
. I would be happy to submit a PR; just let me know.