rustgd / cgmath

A linear algebra and mathematics library for computer graphics.
https://docs.rs/cgmath
Apache License 2.0
1.12k stars 155 forks source link

Optional JSON schema generation #516

Open afnanenayet opened 4 years ago

afnanenayet commented 4 years ago

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.

kvark commented 4 years ago

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?

afnanenayet commented 4 years ago

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.

kvark commented 4 years ago

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

afnanenayet commented 4 years ago

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.