Skip to content
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

impl JsonSchema on Utf8Path[Buf] #91

Closed
aidanwolter3 opened this issue Mar 29, 2024 · 1 comment
Closed

impl JsonSchema on Utf8Path[Buf] #91

aidanwolter3 opened this issue Mar 29, 2024 · 1 comment

Comments

@aidanwolter3
Copy link

I would like to use the schemars crate in a project that heavily uses camino, but am currently prevented from doing so because Utf8Path[Buf] does not implement schemars::JsonSchema.

This PR in schemars has not gone anywhere because the maintainer has not reviewed it.
GREsau/schemars#214

Could we add these impls in camino instead?

@sunshowers
Copy link
Collaborator

sunshowers commented Mar 30, 2024

Thanks for the question! Sadly no, that wouldn't be the right thing to do, because it would mean that none of the many crates that schemars depends on could depend on camino.

However you can do what I did at work, and use this very 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 schema with #[schemars(schema_with = "path_schema")].

This is too trivial to be copyrightable, but in case it ever is, consider this to be CC0-1.0.

@sunshowers sunshowers closed this as not planned Won't fix, can't repro, duplicate, stale Mar 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants