I could not find a good json schema parser that outputs rust structs that is able to preserve validation info like string lengths and integer bounds, most of them would elide these checks.
So I created a parser myself
It is not complete to handle all json schemas, but it was for my use case
Call generate_api_models!("<json_schema_file_path>");
to generate the rust code. It will generate the rust struct with other validation info. You can then deserialize a json object and call .validate()
on it to validate the special type constraints like the string lengths and integer bounds. This is implemented on the validate crate
You can see an example in /src/lib.rs
- any number with a decimal will be deserialized as a rust decimal for exact precision continueity