-
Notifications
You must be signed in to change notification settings - Fork 6
Add: json_schema feature #80
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
Add: json_schema feature #80
Conversation
Coudln't this have a better naming, maybe something like "BluebpsMessage", etc? |
I didn't notice the numerations. In fact, we have a set of Messages for each structure, so schemars automatically indexed it, which was smart haha. https://docs.bluerobotics.com/ping-rs/bluerobotics_ping/ping1d/enum.Messages.html Let me check if we can change just the ref IDs to something from our builder/macro. |
@joaoantoniocardoso seems it breaks all other generated refs. |
@joaoantoniocardoso did it, just let me organize it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job, I have just some small (and optional) suggestions :)
tests/schema_test.rs
Outdated
fn save_schema(filename: &str) { | ||
let schema = schema_for!(Messages); | ||
let schema_json = serde_json::to_string_pretty(&schema).unwrap(); | ||
let mut file = File::create(filename).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could use tmp dir here (not tested):
let mut path = std::env::temp_dir();
path.join(filename);
let mut file = std::fs::File::create(&path).unwrap();
But I see that for manual inspection, it can be useful to create it in an more easily accessible place. In this case, you can add a "tests/tmp" folder to ".gitignore" and use it instead (not tested):
let mut path = std::fs::Path::new("tests/tmp").unwrap();
create_dir_all(path).unwrap();
path.join(filename);
let mut file = std::fs::File::create(&path).unwrap();
obviously, the load_schema
function would have to adapt.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approach 2 seems good, we can improve this afterward with some WASM example
ping @patrickelectric |
Details:
Add json schema feature for PingProtocol definitions,
tested on PingViewerNext:


Details of jsonschema:
message_schema.json