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

Provide example/functionality for validating incoming json against schema #363

Open
TheButlah opened this issue Jan 9, 2025 · 3 comments

Comments

@TheButlah
Copy link

There are many examples of extracting a schema from a rust type. But what I would really like is for me to deserialize a RootSchema from my backend, and use it to validate incoming data entirely dynamically. In other words, my code will only have a RootSchema but no concrete types that have #[derive(JsonSchema)].

As far as I can tell, there is no way to do this with schemars.

@yassun7010
Copy link

Hello.

Do you want something like axum_jsonschema?

@TheButlah
Copy link
Author

TheButlah commented Jan 13, 2025

I'm not using axum, so probably not. I mean something more like this, where the schema and value are dynamic and serializeable.

@yassun7010
Copy link

My understanding is that this crate is intended to provide the ability to generate JSON Schema.

What axum_jsonschema does is to create a JSON Schema with schemars and then validate it using jsonschema and serde_json.
(#[derive(Deserialize, JsonSchema)] is required for struct)

If you want to validate a structure after deserializing it with serde_json, you can use a combination of schemars and validator.
(#[derive(Deserialize, JsonSchema, Validate)] is required for struct)

In any case, a devive like #[derive(JsonSchema)] is necessary if you want to use schemars.

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