greyblake / nutype

Rust newtype with guarantees 🇺🇦 🦀

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support derive for JsonSchema

FranklinChen opened this issue · comments

I have a project where I use Schemars https://docs.rs/schemars/latest/schemars/ in conjunction with Serde and derive JsonSchema. When trying to insert use of nutype, I get

error: unsupported trait derive: JsonSchema

Could support be added for this?

@FranklinChen

Hi Franklin, thanks for reporting your issue.
I cannot promise for sure yet, I will investigate how exactly schemars work.
Anyway, would you mind showing a code sample to exactly reproduce your issue?

Here is a test repo: https://github.com/FranklinChen/test-nutype

$ cargo check
error: unsupported trait derive: JsonSchema
  --> src/main.rs:11:37
   |
11 | #[derive(*, Serialize, Deserialize, JsonSchema)]
   |                                     ^^^^^^^^^^

[...]

Any more thoughts on this?

@FranklinChen Hi!
Sorry, I haven't worked with the schemars crate yet, and haven't invesitgated what would it cost to add a support for this.

@FranklinChen I started working on it (#21), it turned it not that hard.
I still need to add some tests, but it will be in the next release.

Thank you!

@FranklinChen This is addressed in #21 and was just merged.

Please note:

  • The new version is not yet released on crates.io
  • You need to enable schemars08 featurue
  • At this moment, validation rules are not reflected in json schema

@FranklinChen FYI the feature is available in 0.2.0.