-
-
Notifications
You must be signed in to change notification settings - Fork 230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix schema for IpAddr type #277
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest this not merge. From the JSON Schema draft 7 spec:
https://json-schema.org/draft-07/draft-handrews-json-schema-validation-01#rfc.section.7.2
Implementations MAY add custom format attributes. Save for agreement between parties, schema authors SHALL NOT expect a peer implementation to support this keyword and/or custom format attributes.
Is there a reason the "ip" format is causing issues for the author? We've found "ip" to be useful.
any_of: Some(vec![ | ||
gen.subschema_for::<Ipv4Addr>(), | ||
gen.subschema_for::<Ipv6Addr>(), | ||
]), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be a oneOf
?
any_of: Some(vec![ | |
gen.subschema_for::<Ipv4Addr>(), | |
gen.subschema_for::<Ipv6Addr>(), | |
]), | |
one_of: Some(vec![ | |
gen.subschema_for::<Ipv4Addr>(), | |
gen.subschema_for::<Ipv6Addr>(), | |
]), |
let schema_object = SchemaObject { | ||
instance_type: Some(SingleOrVec::Single(Box::new(InstanceType::String))), | ||
subschemas: Some(Box::new(SubschemaValidation { | ||
any_of: Some(vec![ | ||
gen.subschema_for::<Ipv4Addr>(), | ||
gen.subschema_for::<Ipv6Addr>(), | ||
]), | ||
..Default::default() | ||
})), | ||
..Default::default() | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might consider this to label the subschemas; this makes it easier for code generators to infer what's going on.
let schema_object = SchemaObject { | |
instance_type: Some(SingleOrVec::Single(Box::new(InstanceType::String))), | |
subschemas: Some(Box::new(SubschemaValidation { | |
any_of: Some(vec![ | |
gen.subschema_for::<Ipv4Addr>(), | |
gen.subschema_for::<Ipv6Addr>(), | |
]), | |
..Default::default() | |
})), | |
..Default::default() | |
}; | |
let schema_object = SchemaObject { | |
instance_type: Some(SingleOrVec::Single(Box::new(InstanceType::String))), | |
subschemas: Some(Box::new(SubschemaValidation { | |
any_of: Some(vec![ | |
SchemaObject { | |
metadata: Some(Box::new(Metadata { | |
title: Some("V4".into()), | |
..Default::default() | |
})), | |
subschemas: Some(Box::new(SubschemaValidation { | |
all_of: Some(vec![gen.subschema_for::<Ipv4Addr>()]), | |
..Default::default() | |
})), | |
..Default::default() | |
} | |
.into(), | |
SchemaObject { | |
metadata: Some(Box::new(Metadata { | |
title: Some("V6".into()), | |
..Default::default() | |
})), | |
subschemas: Some(Box::new(SubschemaValidation { | |
all_of: Some(vec![gen.subschema_for::<Ipv6Addr>()]), | |
..Default::default() | |
})), | |
..Default::default() | |
} | |
.into(), | |
]), | |
..Default::default() | |
})), | |
..Default::default() | |
}; |
The IpAddr type returns
which isn't a valid JSON format type. See here for the correct implementation.
I have changed this type to instead use