From 4dc02b0967016c2284004bd940e918956d85f8e0 Mon Sep 17 00:00:00 2001 From: Tom Harding Date: Wed, 10 Apr 2024 08:35:59 +0100 Subject: [PATCH] Add a binary for generating the OpenAPI schema for the metadata type. (#453) ## Description I needed this, so I made it. It's nothing too complex: we just pretty-print the `schemars` schema for the root `Metadata` type. ## Changelog - Add a changelog entry (in the "Changelog entry" section below) if the changes in this PR have any user-facing impact. See [changelog guide](https://github.com/hasura/graphql-engine-mono/wiki/Changelog-Guide). - If no changelog is required ignore/remove this section and add a `no-changelog-required` label to the PR. ### Product _(Select all products this will be available in)_ - [ ] community-edition - [ ] cloud ### Type _(Select only one. In case of multiple, choose the most appropriate)_ - [ ] highlight - [ ] enhancement - [ ] bugfix - [ ] behaviour-change - [ ] performance-enhancement - [ ] security-fix ### Changelog entry _Replace with changelog entry_ V3_GIT_ORIGIN_REV_ID: a9e75bfa06c35577c17d8cbf0d021b1f56826a28 --- v3/Cargo.lock | 9 +++++++++ v3/crates/metadata-schema-generator/Cargo.toml | 10 ++++++++++ v3/crates/metadata-schema-generator/README.md | 9 +++++++++ v3/crates/metadata-schema-generator/src/main.rs | 8 ++++++++ 4 files changed, 36 insertions(+) create mode 100644 v3/crates/metadata-schema-generator/Cargo.toml create mode 100644 v3/crates/metadata-schema-generator/README.md create mode 100644 v3/crates/metadata-schema-generator/src/main.rs diff --git a/v3/Cargo.lock b/v3/Cargo.lock index d3084831440..2b4f01ffc7d 100644 --- a/v3/Cargo.lock +++ b/v3/Cargo.lock @@ -1798,6 +1798,15 @@ dependencies = [ "autocfg", ] +[[package]] +name = "metadata-schema-generator" +version = "0.1.0" +dependencies = [ + "open-dds", + "schemars", + "serde_json", +] + [[package]] name = "mime" version = "0.3.17" diff --git a/v3/crates/metadata-schema-generator/Cargo.toml b/v3/crates/metadata-schema-generator/Cargo.toml new file mode 100644 index 00000000000..8cbe72a554c --- /dev/null +++ b/v3/crates/metadata-schema-generator/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "metadata-schema-generator" +version.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +open-dds = { path = "../open-dds" } +serde_json = "1.0.92" +schemars = { version = "0.8.12", features = ["smol_str"] } diff --git a/v3/crates/metadata-schema-generator/README.md b/v3/crates/metadata-schema-generator/README.md new file mode 100644 index 00000000000..619fb8a1d8d --- /dev/null +++ b/v3/crates/metadata-schema-generator/README.md @@ -0,0 +1,9 @@ +# Metadata Schema Generator + +When we make changes to the metadata schema, we need to regenerate the +goldenfile to make the tests happy. We can use the following command to get the +schema immediately for whatever reason: + +```bash +$ cargo run --bin metadata-schema-generator +``` diff --git a/v3/crates/metadata-schema-generator/src/main.rs b/v3/crates/metadata-schema-generator/src/main.rs new file mode 100644 index 00000000000..8bc54122f7f --- /dev/null +++ b/v3/crates/metadata-schema-generator/src/main.rs @@ -0,0 +1,8 @@ +use open_dds::traits::gen_root_schema_for; +use open_dds::Metadata; +use schemars::gen::SchemaGenerator; + +fn main() { + let schema = gen_root_schema_for::(&mut SchemaGenerator::default()); + println!("{}", serde_json::to_string_pretty(&schema).unwrap()); +}