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

add checks for json schema changes #19

Merged
merged 2 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ jobs:
rosdep update
rosdep resolve -q ament_cmake std_msgs example_interfaces | sed '/^#/d' | xargs sudo apt install -y
- name: cargo test
run: . /ros_entrypoint.sh && cargo test
run: . /ros_entrypoint.sh && cargo test --all-features
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ name = "redf"
version = "0.1.0"
edition = "2021"
default-run = "redf"
license = "Apache-2.0"
license-file = "LICENSE"

[[bin]]
Expand Down
4 changes: 2 additions & 2 deletions redf.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"description",
"message_type",
"title",
"topic",
"topic_name",
"type"
],
"properties": {
Expand All @@ -101,7 +101,7 @@
"title": {
"type": "string"
},
"topic": {
"topic_name": {
"type": "string"
},
"type": {
Expand Down
28 changes: 27 additions & 1 deletion src/generate-schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,32 @@ use schemars::schema_for;

fn main() -> Result<(), Box<dyn std::error::Error>> {
let schema = schema_for!(Redf);
std::fs::write("redf.schema.json", serde_json::to_string_pretty(&schema)?)?;
let f = std::fs::OpenOptions::new()
.write(true)
.truncate(true)
.create(true)
.open("redf.schema.json")
.unwrap();
serde_json::to_writer_pretty(f, &schema).unwrap();
Ok(())
}

#[cfg(test)]
mod test {
use super::*;
use std::iter::zip;

#[test]
fn check_schema_changes() -> Result<(), String> {
let cur_schema_json = std::fs::read("redf.schema.json").unwrap();
let schema = schema_for!(Redf);
let new_schema_json = serde_json::to_vec_pretty(&schema).unwrap();

if cur_schema_json.len() != new_schema_json.len()
|| zip(cur_schema_json, new_schema_json).any(|(a, b)| a != b)
{
return Err(String::from("There are changes in the json schema, please run `cargo run -F json_schema --bin generate-schema` to regenerate it"));
}
Ok(())
}
}
Loading