Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/s-fabian/schemars-to-zod
Convert schemars's Schema into a zod schema
https://github.com/s-fabian/schemars-to-zod
json-schema rust schemars typescript zod
Last synced: 3 months ago
JSON representation
Convert schemars's Schema into a zod schema
- Host: GitHub
- URL: https://github.com/s-fabian/schemars-to-zod
- Owner: s-fabian
- Created: 2024-01-04T11:24:14.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-07-25T10:19:27.000Z (5 months ago)
- Last Synced: 2024-09-26T19:05:59.713Z (3 months ago)
- Topics: json-schema, rust, schemars, typescript, zod
- Language: Rust
- Homepage:
- Size: 37.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# schemars-zod
## Example
```rust
use schemars::{JsonSchema, schema_for, schema::Schema};
use schemars_zod::{Config, Parser};#[derive(JsonSchema)]
struct MyStruct {
name: String,
age: u8,
}fn main() {
let schema = schema_for!(MyStruct);
let schema = Schema::Object(schema.schema);let parser = Parser::new(Config {
// useful when generating a js client
// where a date would otherwise get parsed as a string
use_coerce_date: true,
array_wrapper: false,
explicit_min_max: false,
add_descriptions: false,
union_first: true,
add_default: false,
});
// with the feature pretty
let result = parser.parse_pretty_default(&schema).unwrap();
// without the feature pretty
let result = parser.parse(&schema).unwrap();
println!("{}", result);
}
```## NOTE
After I made this library, I realised there is already a library with the same functionality.
You can find the original library (schemars-zod) [here](https://github.com/audiocloud/schemars-zod).
This library (schemars-to-zod) is __not__ [the one on crates.io](https://crates.io/crates/schemars-zod).Also, this library is heavily inspired by the [node package](https://github.com/StefanTerdell/json-schema-to-zod).