cgmath icon indicating copy to clipboard operation
cgmath copied to clipboard

Optional JSON schema generation

Open afnanenayet opened this issue 5 years ago • 4 comments

Allow users to optionally derive JSON schemas using structs from this crate if they include schemars. This will allow consumers of this library to generate JSON schemas from structs that include structs created in this crate.

afnanenayet avatar Aug 30 '20 01:08 afnanenayet

Thank you for making this PR!

I honestly haven't worked with JSON schemas in Rust. And I don't know what the established conventions are, so it's hard to tell if schemars would be needed in cgmath. Given that cgmath is fairly low-supported atm, I'm curious to see if other libraries (with better support and stuffing) investigated their part. Did nalgebra, glam, and whatever, came to any conclusion wrt schemars integration?

kvark avatar Sep 02 '20 04:09 kvark

It doesn't seem like either of the libraries mentioned have dealt with schema generation yet, at least not that I was able to find.

My use case is that I'm serializing structs that have Vector3 as a field, and I want to derive the JSON schema for those structs, and I can't do that unless every underlying struct also derives the schema.

afnanenayet avatar Sep 03 '20 00:09 afnanenayet

What are the stability guarantees for schemars? Would it work if the struct has fields serialized by different versions of this crate?

kvark avatar Sep 03 '20 00:09 kvark

I'm actually not entirely sure, the documentation says this:

One of the main aims of this library is compatibility with Serde. Any generated schema should match how serde_json would serialize/deserialize to/from JSON.

serde_json and serde seem incredibly stable, so if this is piggybacking off of that, then I think this shouldn't have issues. I'll try to dig around the schemars source and see what's going on.

afnanenayet avatar Sep 03 '20 01:09 afnanenayet