schemars
schemars copied to clipboard
impl JsonSchema for basic camino types
I'd like to be able to use Utf8Path and Utf8PathBuf like the std equivalents when deriving JsonSchema. I believe the implementation is the same as for those types over in primitives.
There should be a camino feature that gates this based on the optional dependency.
Is this gonna be merged soon ? TBH We use a lot Utf8PathBuf instead of PathBuf in our apps. And since we are planning to migrate to axum and use aide (OpenApi/Swagger) we absolutely need this feature.
I am also looking forward to when this will merge. We use Utf8PathBuf all over the place which prevents me from using schemars until this is merged in.
(camino maintainer here)
Meanwhile, you can use this really simple impl:
fn path_schema(gen: &mut SchemaGenerator) -> Schema {
let mut schema: SchemaObject = <String>::json_schema(gen).into();
schema.format = Some("Utf8PathBuf".to_owned());
schema.into()
}
and annotate your schemas with #[schemars(schema_with = "path_schema")].
You can do something similar for Option<Utf8PathBuf>, Vec<Utf8PathBuf> etc.
This is too trivial to be copyrightable, but in case it ever is, consider this to be CC0-1.0.
sunshowers's comment works for me! Thank you @sunshowers .