Skip to content

abacef/json_schema_to_rust_struct

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Convert json schema to rust structs, with automatic validation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages