From 40a028ffe7a5f814e3171221f3f9b60bd62cd1cc Mon Sep 17 00:00:00 2001 From: Benoit Ranque Date: Wed, 1 Jan 2025 16:18:54 -0400 Subject: [PATCH] add manually triggered tests to generate schema files for test file validation --- crates/tests/tests-common/Cargo.toml | 9 ++++-- crates/tests/tests-common/src/request.rs | 39 ++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/crates/tests/tests-common/Cargo.toml b/crates/tests/tests-common/Cargo.toml index 71f683434..237235ea9 100644 --- a/crates/tests/tests-common/Cargo.toml +++ b/crates/tests/tests-common/Cargo.toml @@ -24,10 +24,15 @@ axum-test-helper = { workspace = true } env_logger = { workspace = true } hyper = { workspace = true, features = ["tcp"] } reqwest = { workspace = true } +schemars = { workspace = true } serde = { workspace = true } serde_json = { workspace = true, features = ["raw_value"] } -sqlx = { workspace = true, features = [ "json", "postgres", "runtime-tokio-rustls" ] } +sqlx = { workspace = true, features = [ + "json", + "postgres", + "runtime-tokio-rustls", +] } tokio = { workspace = true, features = ["full"] } tracing = { workspace = true } url = { workspace = true } -uuid = { workspace = true, features = [ "v4", "fast-rng", "macro-diagnostics" ] } +uuid = { workspace = true, features = ["v4", "fast-rng", "macro-diagnostics"] } diff --git a/crates/tests/tests-common/src/request.rs b/crates/tests/tests-common/src/request.rs index 5ae66cf33..6427cf6b1 100644 --- a/crates/tests/tests-common/src/request.rs +++ b/crates/tests/tests-common/src/request.rs @@ -153,3 +153,42 @@ async fn make_request serde::Deserialize<'a>>( ) }) } + +/// Generate/Update static/query.schema.json +/// this test should be ignored unless explicitly invoked +#[ignore] +#[test] +fn generate_query_request_schema() { + let query_schema = + serde_json::to_string_pretty(&schemars::schema_for!(ndc_sdk::models::QueryRequest)) + .expect("Should serialize query schema to json"); + std::fs::write("../../../static/query.schema.json", query_schema) + .expect("Should be able to write out schema file"); +} +/// Generate/Update static/mutation.schema.json +/// this test should be ignored unless explicitly invoked +#[ignore] +#[test] +fn generate_mutation_request_schema() { + let mutation_schema = + serde_json::to_string_pretty(&schemars::schema_for!(ndc_sdk::models::MutationRequest)) + .expect("Should serialize mutation schema to json"); + std::fs::write("../../../static/mutation.schema.json", mutation_schema) + .expect("Should be able to write out schema file"); +} + +/// Generate/Update static/configuration.schema.json +/// this test should be ignored unless explicitly invoked +#[ignore] +#[test] +fn generate_configuration_schema() { + let configuration_schema = serde_json::to_string_pretty(&schemars::schema_for!( + ndc_postgres_configuration::version5::ParsedConfiguration + )) + .expect("Should serialize configuration schema to json"); + std::fs::write( + "../../../static/configuration.schema.json", + configuration_schema, + ) + .expect("Should be able to write out schema file"); +}