Fallible visitors
When writing somewhat more complex Visitors (such as https://github.com/kube-rs/kube-rs/pull/779) there are scenarios where we simply can't apply the transform (like when properties end up conflicting...). It would be nice if we could return proper structured errors in those cases, rather than panicking or silently ending up with a corrupt schema.
Something like this?
pub trait OutputVisitor {
type Output;
fn visit_root_schema(&mut self, root: &mut RootSchema) -> Self::Output;
fn visit_schema(&mut self, schema: &mut Schema) -> Self::Output;
fn visit_schema_object(&mut self, schema: &mut SchemaObject) -> Self::Output;
}
Perhaps the existing visitor could simply be a wrapper where Output = ()
I think we would need to do something like this to ensure that schemars knows how to identify and propagate errors:
pub trait OutputVisitor {
type Error;
fn visit_root_schema(&mut self, root: &mut RootSchema) -> Result<(), Self::Error>;
fn visit_schema(&mut self, schema: &mut Schema) -> Result<(), Self::Error>;
fn visit_schema_object(&mut self, schema: &mut SchemaObject) -> Result<(), Self::Error>;
}
Infallible visitors could set type Error = Infallible;, which would ensure that the error case is compiled away.