Skip to content

Latest commit

 

History

History
15 lines (8 loc) · 892 Bytes

File metadata and controls

15 lines (8 loc) · 892 Bytes

json schema to rust struct

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

Usage

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