Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support derive for JsonSchema #12

Closed
FranklinChen opened this issue Feb 14, 2023 · 8 comments
Closed

Support derive for JsonSchema #12

FranklinChen opened this issue Feb 14, 2023 · 8 comments

Comments

@FranklinChen
Copy link

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?

@greyblake
Copy link
Owner

@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?

@FranklinChen
Copy link
Author

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)]
   |                                     ^^^^^^^^^^

[...]

@FranklinChen
Copy link
Author

Any more thoughts on this?

@greyblake
Copy link
Owner

@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.

@greyblake
Copy link
Owner

@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.

@FranklinChen
Copy link
Author

Thank you!

@greyblake
Copy link
Owner

@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

@greyblake
Copy link
Owner

@FranklinChen FYI the feature is available in 0.2.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

No branches or pull requests

2 participants