From 36ec9e03de8967b2b43f16be7247c13150f1057a Mon Sep 17 00:00:00 2001 From: David Bernard Date: Wed, 10 Jan 2024 11:29:27 +0100 Subject: [PATCH 01/34] revert: remove useless scaffolded code Signed-off-by: David Bernard --- bindings/Cargo.toml | 9 --------- bindings/src/main.rs | 3 --- factory/Cargo.toml | 9 --------- factory/src/main.rs | 3 --- zz_artifact/Cargo.toml | 9 --------- zz_artifact/src/main.rs | 3 --- zz_branch/Cargo.toml | 8 -------- zz_branch/src/main.rs | 3 --- zz_build/Cargo.toml | 9 --------- zz_build/src/main.rs | 3 --- zz_change/Cargo.toml | 9 --------- zz_change/src/main.rs | 3 --- zz_environment/Cargo.toml | 9 --------- zz_environment/src/main.rs | 3 --- zz_incident/Cargo.toml | 9 --------- zz_incident/src/main.rs | 3 --- zz_pipeline/Cargo.toml | 9 --------- zz_pipeline/src/main.rs | 3 --- zz_repository/Cargo.toml | 9 --------- zz_repository/src/main.rs | 3 --- zz_service/Cargo.toml | 9 --------- zz_service/src/main.rs | 3 --- zz_task/Cargo.toml | 9 --------- zz_task/src/main.rs | 3 --- 24 files changed, 143 deletions(-) delete mode 100644 bindings/Cargo.toml delete mode 100644 bindings/src/main.rs delete mode 100644 factory/Cargo.toml delete mode 100644 factory/src/main.rs delete mode 100644 zz_artifact/Cargo.toml delete mode 100644 zz_artifact/src/main.rs delete mode 100644 zz_branch/Cargo.toml delete mode 100644 zz_branch/src/main.rs delete mode 100644 zz_build/Cargo.toml delete mode 100644 zz_build/src/main.rs delete mode 100644 zz_change/Cargo.toml delete mode 100644 zz_change/src/main.rs delete mode 100644 zz_environment/Cargo.toml delete mode 100644 zz_environment/src/main.rs delete mode 100644 zz_incident/Cargo.toml delete mode 100644 zz_incident/src/main.rs delete mode 100644 zz_pipeline/Cargo.toml delete mode 100644 zz_pipeline/src/main.rs delete mode 100644 zz_repository/Cargo.toml delete mode 100644 zz_repository/src/main.rs delete mode 100644 zz_service/Cargo.toml delete mode 100644 zz_service/src/main.rs delete mode 100644 zz_task/Cargo.toml delete mode 100644 zz_task/src/main.rs diff --git a/bindings/Cargo.toml b/bindings/Cargo.toml deleted file mode 100644 index 65745a0..0000000 --- a/bindings/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "bindings" -version = "0.1.0" -edition = "2021" -license = "MIT" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/bindings/src/main.rs b/bindings/src/main.rs deleted file mode 100644 index e7a11a9..0000000 --- a/bindings/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("Hello, world!"); -} diff --git a/factory/Cargo.toml b/factory/Cargo.toml deleted file mode 100644 index f3f3fc4..0000000 --- a/factory/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "factory" -version = "0.1.0" -edition = "2021" -license = "MIT" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/factory/src/main.rs b/factory/src/main.rs deleted file mode 100644 index e7a11a9..0000000 --- a/factory/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("Hello, world!"); -} diff --git a/zz_artifact/Cargo.toml b/zz_artifact/Cargo.toml deleted file mode 100644 index b3154c8..0000000 --- a/zz_artifact/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "zz_artifact" -version = "0.1.0" -edition = "2021" -license = "MIT" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/zz_artifact/src/main.rs b/zz_artifact/src/main.rs deleted file mode 100644 index e7a11a9..0000000 --- a/zz_artifact/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("Hello, world!"); -} diff --git a/zz_branch/Cargo.toml b/zz_branch/Cargo.toml deleted file mode 100644 index 0ca65b3..0000000 --- a/zz_branch/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "zz_branch" -version = "0.1.0" -edition = "2021" -license = "MIT" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/zz_branch/src/main.rs b/zz_branch/src/main.rs deleted file mode 100644 index e7a11a9..0000000 --- a/zz_branch/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("Hello, world!"); -} diff --git a/zz_build/Cargo.toml b/zz_build/Cargo.toml deleted file mode 100644 index a6e5725..0000000 --- a/zz_build/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "zz_build" -version = "0.1.0" -edition = "2021" -license = "MIT" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/zz_build/src/main.rs b/zz_build/src/main.rs deleted file mode 100644 index e7a11a9..0000000 --- a/zz_build/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("Hello, world!"); -} diff --git a/zz_change/Cargo.toml b/zz_change/Cargo.toml deleted file mode 100644 index 2c12cc1..0000000 --- a/zz_change/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "zz_change" -version = "0.1.0" -edition = "2021" -license = "MIT" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/zz_change/src/main.rs b/zz_change/src/main.rs deleted file mode 100644 index e7a11a9..0000000 --- a/zz_change/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("Hello, world!"); -} diff --git a/zz_environment/Cargo.toml b/zz_environment/Cargo.toml deleted file mode 100644 index 74aca6d..0000000 --- a/zz_environment/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "zz_environment" -version = "0.1.0" -edition = "2021" -license = "MIT" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/zz_environment/src/main.rs b/zz_environment/src/main.rs deleted file mode 100644 index e7a11a9..0000000 --- a/zz_environment/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("Hello, world!"); -} diff --git a/zz_incident/Cargo.toml b/zz_incident/Cargo.toml deleted file mode 100644 index 219775c..0000000 --- a/zz_incident/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "zz_incident" -version = "0.1.0" -edition = "2021" -license = "MIT" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/zz_incident/src/main.rs b/zz_incident/src/main.rs deleted file mode 100644 index e7a11a9..0000000 --- a/zz_incident/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("Hello, world!"); -} diff --git a/zz_pipeline/Cargo.toml b/zz_pipeline/Cargo.toml deleted file mode 100644 index d6d8b3f..0000000 --- a/zz_pipeline/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "zz_pipeline" -version = "0.1.0" -edition = "2021" -license = "MIT" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/zz_pipeline/src/main.rs b/zz_pipeline/src/main.rs deleted file mode 100644 index e7a11a9..0000000 --- a/zz_pipeline/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("Hello, world!"); -} diff --git a/zz_repository/Cargo.toml b/zz_repository/Cargo.toml deleted file mode 100644 index 5ba7ef0..0000000 --- a/zz_repository/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "zz_repository" -version = "0.1.0" -edition = "2021" -license = "MIT" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/zz_repository/src/main.rs b/zz_repository/src/main.rs deleted file mode 100644 index e7a11a9..0000000 --- a/zz_repository/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("Hello, world!"); -} diff --git a/zz_service/Cargo.toml b/zz_service/Cargo.toml deleted file mode 100644 index a52932e..0000000 --- a/zz_service/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "zz_service" -version = "0.1.0" -edition = "2021" -license = "MIT" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/zz_service/src/main.rs b/zz_service/src/main.rs deleted file mode 100644 index e7a11a9..0000000 --- a/zz_service/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("Hello, world!"); -} diff --git a/zz_task/Cargo.toml b/zz_task/Cargo.toml deleted file mode 100644 index 428d7bb..0000000 --- a/zz_task/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "zz_task" -version = "0.1.0" -edition = "2021" -license = "MIT" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/zz_task/src/main.rs b/zz_task/src/main.rs deleted file mode 100644 index e7a11a9..0000000 --- a/zz_task/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("Hello, world!"); -} From 4353836d59cc8b618eb0b9a3314739258586e101 Mon Sep 17 00:00:00 2001 From: David Bernard Date: Wed, 10 Jan 2024 21:28:57 +0100 Subject: [PATCH 02/34] feat: first working basic `generator` Signed-off-by: David Bernard --- .gitmodules | 4 ++ Cargo.toml | 34 ++++----- generator/Cargo.toml | 22 ++++++ generator/README.md | 22 ++++++ generator/src/main.rs | 119 ++++++++++++++++++++++++++++++++ generator/templates/mod.hbs | 14 ++++ generator/templates/subject.hbs | 11 +++ 7 files changed, 210 insertions(+), 16 deletions(-) create mode 100644 .gitmodules create mode 100644 generator/Cargo.toml create mode 100644 generator/README.md create mode 100644 generator/src/main.rs create mode 100644 generator/templates/mod.hbs create mode 100644 generator/templates/subject.hbs diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..ed8598b --- /dev/null +++ b/.gitmodules @@ -0,0 +1,4 @@ +[submodule "cdevents-spec"] + path = cdevents-spec + url = git@github.com:cdevents/spec.git + branch = spec-v0.3 diff --git a/Cargo.toml b/Cargo.toml index b482c38..eb5a335 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,16 +1,18 @@ -[workspace] -members = [ - "bindings", - "factory", - "types", - "zz_artifact", - "zz_branch", - "zz_build", - "zz_change", - "zz_environment", - "zz_incident", - "zz_pipeline", - "zz_repository", - "zz_service", - "zz_task", -] +[workspace] +resolver = "2" +members = ["cdevents", "generator"] + +[workspace.package] +edition = "2021" +version = "0.1.0" +authors = ["David Bernard"] +license = "ASL-2.0" +repository = "https://github.com/cdevents/sdk-rust" +rust-version = "1.75" +publish = false + +[workspace.metadata.release] +pre-release-commit-message = "🚀 (cargo-release) version {{version}}" +tag-prefix = "" +tag-name = "{{prefix}}{{version}}" +tag-message = "🔖 {{version}}" diff --git a/generator/Cargo.toml b/generator/Cargo.toml new file mode 100644 index 0000000..831dc1e --- /dev/null +++ b/generator/Cargo.toml @@ -0,0 +1,22 @@ +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[package] +name = "generator" +description = "generate cdevents type from json schema on cdevents-spec" +edition.workspace = true +version.workspace = true +authors.workspace = true +repository.workspace = true +license.workspace = true +publish.workspace = true + +[dependencies] +anyhow = "1.0" +clap = { version = "4", features = ["derive"] } +cruet = "0.14" +handlebars = { version = "5", features = ["dir_source"] } +serde_json = "*" +url = "2.5" +handlebars_misc_helpers = { version = "0.15", default-features = false, features = [ + "string", + "json", +] } diff --git a/generator/README.md b/generator/README.md new file mode 100644 index 0000000..9a1b3ee --- /dev/null +++ b/generator/README.md @@ -0,0 +1,22 @@ +# cdevents rust code generator + +Goals: generate rust code for cdevents from jsonschema provided as part of cdevents specs. + +- The generator take read jsonschema as json apply them to a set of templates +- The generator is very basic (no json schema semantic, no `$ref` resolution) like [eventuallyconsultant/codegenr: Fast handlebars templates based code generator, ingesting swagger/openapi and other json/yaml documents with $refs, or graphql schema, outputs whatever you template](https://github.com/eventuallyconsultant/codegenr/) +- The generator is currently used to generated Subjects + +## Why not use a jsonschema to rust generator? + +- I tried some (like ) and they failed (no error), maybe too early, not support for the version of jsonschema used by cdevents (often they support jsonschema draft-4) +- The json schema (v0.3) are not connected, so lot of duplication (context,...), so classical generator will create as many Context type as Event type,... + +## Run + +To generate the `subjects` into sibling crate `cdevents/src/generated` from content of `cdevents-spec/schemas`, from root workspace + +```sh +cargo run -p generator -- --help +cargo run -p generator -- --templates-dir "generator/templates" --jsonschema-dir "cdevents-spec/schemas" --dest +"cdevents/src/generated" +``` \ No newline at end of file diff --git a/generator/src/main.rs b/generator/src/main.rs new file mode 100644 index 0000000..3dba149 --- /dev/null +++ b/generator/src/main.rs @@ -0,0 +1,119 @@ +use anyhow::{anyhow, Context, Result}; +use clap::Parser; +use handlebars::{handlebars_helper, DirectorySourceOptions, Handlebars}; +use serde_json::{json, Value}; +use std::{fs, path::PathBuf}; + +/// generator of part of the rust code of cdevents from spec +#[derive(Parser, Debug)] +struct Settings { + /// directory with handlebars templates + #[arg(long, default_value = "templates")] + templates_dir: PathBuf, + + /// directory with json schemas of events to generate + #[arg(long, default_value = "../cdevents-spec/schemas")] + jsonschema_dir: PathBuf, + + /// destination directory where to generate code + #[arg(long, default_value = "../cdevents/src/generated")] + dest: PathBuf, +} + +fn main() -> Result<()> { + let settings = Settings::parse(); + + let mut hbs = Handlebars::new(); + hbs.set_strict_mode(true); + hbs.register_escape_fn(handlebars::no_escape); + //hbs.unregister_escape_fn(); + hbs.register_helper("type_of", Box::new(type_of)); + hbs.register_helper("normalize_ident", Box::new(normalize_ident)); + handlebars_misc_helpers::register(&mut hbs); + hbs.register_templates_directory(settings.templates_dir, DirectorySourceOptions::default())?; + + fs::create_dir_all(&settings.dest)?; + + let mut subjects = vec![]; + let mut jsonfiles = + std::fs::read_dir(settings.jsonschema_dir)?.collect::, _>>()?; + jsonfiles.sort_by_key(|v| v.file_name()); + for entry in jsonfiles { + let path = entry.path(); + if let Some(extension) = path.extension() { + if extension == "json" { + let json = serde_json::from_str(&std::fs::read_to_string(&path)?)?; + let (type_name, code) = generate_subject(&hbs, json) + .with_context(|| format!("failed to generate subject on {:?}", &path))?; + let file = settings + .dest + .join(cruet::to_snake_case(&type_name)) + .with_extension("rs"); + fs::write(file, code)?; + subjects.push(type_name); + } + } + } + + let (type_name, code) = + generate_module(&hbs, &subjects).with_context(|| "failed to generate module")?; + let file = settings + .dest + .join(cruet::to_snake_case(&type_name)) + .with_extension("rs"); + fs::write(file, code)?; + + Ok(()) +} + +fn generate_subject(hbs: &Handlebars, jsonschema: Value) -> Result<(String, String)> { + let id = jsonschema["$id"] + .as_str() + .ok_or(anyhow!("$id not found or not a string")) + .and_then(|s| url::Url::parse(s).with_context(|| format!("failed to parse: {}", s)))?; + let type_name = id + .path_segments() + .and_then(|v| v.last()) + .map(cruet::to_class_case) + .ok_or(anyhow!("no path in $id"))? + .replace("Event", "Subject"); + let mut data = jsonschema.clone(); + data.as_object_mut().and_then(|m| { + m.insert( + "type_name".to_string(), + serde_json::to_value(&type_name).unwrap(), + ) + }); + let code = hbs.render("subject", &data)?; + Ok((type_name.to_string(), code)) +} + +fn generate_module(hbs: &Handlebars, subjects: &[String]) -> Result<(String, String)> { + let data = json!({ + "subjects": subjects + }); + let code = hbs.render("mod", &data)?; + Ok(("mod".to_string(), code)) +} + +//TODO helper to convert into type +//TODO helper to check if optionnal +handlebars_helper!(type_of: |field_name: Value, def: Value, required: Value| { + let mut t = match def["type"].as_str() { + Some("string") => "String", + Some("object") => "serde_json::Map", + x => todo!("impl type {:?}", x), + }.to_string(); + if required.as_array().map(|a| a.contains(&field_name)).unwrap_or(false) { + t = format!("Option<{}>", t); + } + t +}); + +handlebars_helper!(normalize_ident: |v: Value| { + match v.as_str() { + Some("type") => "tpe", + Some(x) => x, + None => unimplemented!(), + } +}); diff --git a/generator/templates/mod.hbs b/generator/templates/mod.hbs new file mode 100644 index 0000000..2df24c6 --- /dev/null +++ b/generator/templates/mod.hbs @@ -0,0 +1,14 @@ +// code generated by cdevents/sdk-rust/generator (mod.hbs) +{{#each subjects }} +mod {{to_snake_case this}}; +{{/each}} + +use serde::{Serialize, Deserialize}; + +#[derive(Debug,Clone,Serialize,Deserialize)] +#[serde(untagged)] // TODO how to use content of context.type as discriminator ? +pub enum Subject { + {{#each subjects }} + {{this}}({{to_snake_case this}}::{{this}}), + {{/each}} +} diff --git a/generator/templates/subject.hbs b/generator/templates/subject.hbs new file mode 100644 index 0000000..b66e4a2 --- /dev/null +++ b/generator/templates/subject.hbs @@ -0,0 +1,11 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct {{ type_name }} { + {{assign "required" properties.subject.required }} + {{#each properties.subject.properties }} + #[serde(rename = "{{ @key }}")] + pub {{normalize_ident @key }}: {{type_of @key this required }}, + {{/each}} +} From 82bfe86e420ea5838dcc911722009738f35b207b Mon Sep 17 00:00:00 2001 From: David Bernard Date: Wed, 10 Jan 2024 21:29:26 +0100 Subject: [PATCH 03/34] feat: first working basic `cdevents` implementation Signed-off-by: David Bernard --- cdevents/Cargo.toml | 22 +++++ .../generated/artifact_packaged_subject.rs | 15 ++++ .../generated/artifact_published_subject.rs | 15 ++++ .../src/generated/artifact_signed_subject.rs | 15 ++++ .../src/generated/branch_created_subject.rs | 15 ++++ .../src/generated/branch_deleted_subject.rs | 15 ++++ .../src/generated/build_finished_subject.rs | 15 ++++ .../src/generated/build_queued_subject.rs | 15 ++++ .../src/generated/build_started_subject.rs | 15 ++++ .../src/generated/change_abandoned_subject.rs | 15 ++++ .../src/generated/change_created_subject.rs | 15 ++++ .../src/generated/change_merged_subject.rs | 15 ++++ .../src/generated/change_reviewed_subject.rs | 15 ++++ .../src/generated/change_updated_subject.rs | 15 ++++ .../generated/environment_created_subject.rs | 15 ++++ .../generated/environment_deleted_subject.rs | 15 ++++ .../generated/environment_modified_subject.rs | 15 ++++ .../generated/incident_detected_subject.rs | 15 ++++ .../generated/incident_reported_subject.rs | 15 ++++ .../generated/incident_resolved_subject.rs | 15 ++++ cdevents/src/generated/mod.rs | 86 +++++++++++++++++++ .../pipeline_run_finished_subject.rs | 15 ++++ .../generated/pipeline_run_queued_subject.rs | 15 ++++ .../generated/pipeline_run_started_subject.rs | 15 ++++ .../generated/repository_created_subject.rs | 15 ++++ .../generated/repository_deleted_subject.rs | 15 ++++ .../generated/repository_modified_subject.rs | 15 ++++ .../src/generated/service_deployed_subject.rs | 15 ++++ .../generated/service_published_subject.rs | 15 ++++ .../src/generated/service_removed_subject.rs | 15 ++++ .../generated/service_rolledback_subject.rs | 15 ++++ .../src/generated/service_upgraded_subject.rs | 15 ++++ .../generated/task_run_finished_subject.rs | 15 ++++ .../src/generated/task_run_started_subject.rs | 15 ++++ .../test_case_run_finished_subject.rs | 15 ++++ .../generated/test_case_run_queued_subject.rs | 15 ++++ .../test_case_run_started_subject.rs | 15 ++++ .../test_output_published_subject.rs | 15 ++++ .../generated/test_suite_finished_subject.rs | 15 ++++ .../test_suite_run_queued_subject.rs | 15 ++++ .../test_suite_run_started_subject.rs | 15 ++++ cdevents/src/lib.rs | 52 +++++++++++ 42 files changed, 745 insertions(+) create mode 100644 cdevents/Cargo.toml create mode 100644 cdevents/src/generated/artifact_packaged_subject.rs create mode 100644 cdevents/src/generated/artifact_published_subject.rs create mode 100644 cdevents/src/generated/artifact_signed_subject.rs create mode 100644 cdevents/src/generated/branch_created_subject.rs create mode 100644 cdevents/src/generated/branch_deleted_subject.rs create mode 100644 cdevents/src/generated/build_finished_subject.rs create mode 100644 cdevents/src/generated/build_queued_subject.rs create mode 100644 cdevents/src/generated/build_started_subject.rs create mode 100644 cdevents/src/generated/change_abandoned_subject.rs create mode 100644 cdevents/src/generated/change_created_subject.rs create mode 100644 cdevents/src/generated/change_merged_subject.rs create mode 100644 cdevents/src/generated/change_reviewed_subject.rs create mode 100644 cdevents/src/generated/change_updated_subject.rs create mode 100644 cdevents/src/generated/environment_created_subject.rs create mode 100644 cdevents/src/generated/environment_deleted_subject.rs create mode 100644 cdevents/src/generated/environment_modified_subject.rs create mode 100644 cdevents/src/generated/incident_detected_subject.rs create mode 100644 cdevents/src/generated/incident_reported_subject.rs create mode 100644 cdevents/src/generated/incident_resolved_subject.rs create mode 100644 cdevents/src/generated/mod.rs create mode 100644 cdevents/src/generated/pipeline_run_finished_subject.rs create mode 100644 cdevents/src/generated/pipeline_run_queued_subject.rs create mode 100644 cdevents/src/generated/pipeline_run_started_subject.rs create mode 100644 cdevents/src/generated/repository_created_subject.rs create mode 100644 cdevents/src/generated/repository_deleted_subject.rs create mode 100644 cdevents/src/generated/repository_modified_subject.rs create mode 100644 cdevents/src/generated/service_deployed_subject.rs create mode 100644 cdevents/src/generated/service_published_subject.rs create mode 100644 cdevents/src/generated/service_removed_subject.rs create mode 100644 cdevents/src/generated/service_rolledback_subject.rs create mode 100644 cdevents/src/generated/service_upgraded_subject.rs create mode 100644 cdevents/src/generated/task_run_finished_subject.rs create mode 100644 cdevents/src/generated/task_run_started_subject.rs create mode 100644 cdevents/src/generated/test_case_run_finished_subject.rs create mode 100644 cdevents/src/generated/test_case_run_queued_subject.rs create mode 100644 cdevents/src/generated/test_case_run_started_subject.rs create mode 100644 cdevents/src/generated/test_output_published_subject.rs create mode 100644 cdevents/src/generated/test_suite_finished_subject.rs create mode 100644 cdevents/src/generated/test_suite_run_queued_subject.rs create mode 100644 cdevents/src/generated/test_suite_run_started_subject.rs create mode 100644 cdevents/src/lib.rs diff --git a/cdevents/Cargo.toml b/cdevents/Cargo.toml new file mode 100644 index 0000000..e951b51 --- /dev/null +++ b/cdevents/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "cdevents" +edition.workspace = true +version.workspace = true +authors.workspace = true +license.workspace = true +repository.workspace = true +rust-version.workspace = true +publish = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +http = "1" +http-serde = "2" +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" +time = { version = "0.3", features = ["serde-human-readable"] } + +[dev-dependencies] +rstest = "0.18" +assert-json-diff = "2.0" diff --git a/cdevents/src/generated/artifact_packaged_subject.rs b/cdevents/src/generated/artifact_packaged_subject.rs new file mode 100644 index 0000000..a3e5b01 --- /dev/null +++ b/cdevents/src/generated/artifact_packaged_subject.rs @@ -0,0 +1,15 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ArtifactPackagedSubject { + + #[serde(rename = "content")] + pub content: serde_json::Map, + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source")] + pub source: String, + #[serde(rename = "type")] + pub tpe: String, +} diff --git a/cdevents/src/generated/artifact_published_subject.rs b/cdevents/src/generated/artifact_published_subject.rs new file mode 100644 index 0000000..735443c --- /dev/null +++ b/cdevents/src/generated/artifact_published_subject.rs @@ -0,0 +1,15 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ArtifactPublishedSubject { + + #[serde(rename = "content")] + pub content: serde_json::Map, + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source")] + pub source: String, + #[serde(rename = "type")] + pub tpe: String, +} diff --git a/cdevents/src/generated/artifact_signed_subject.rs b/cdevents/src/generated/artifact_signed_subject.rs new file mode 100644 index 0000000..7f0493a --- /dev/null +++ b/cdevents/src/generated/artifact_signed_subject.rs @@ -0,0 +1,15 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ArtifactSignedSubject { + + #[serde(rename = "content")] + pub content: serde_json::Map, + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source")] + pub source: String, + #[serde(rename = "type")] + pub tpe: String, +} diff --git a/cdevents/src/generated/branch_created_subject.rs b/cdevents/src/generated/branch_created_subject.rs new file mode 100644 index 0000000..e3cd2d3 --- /dev/null +++ b/cdevents/src/generated/branch_created_subject.rs @@ -0,0 +1,15 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct BranchCreatedSubject { + + #[serde(rename = "content")] + pub content: serde_json::Map, + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source")] + pub source: String, + #[serde(rename = "type")] + pub tpe: String, +} diff --git a/cdevents/src/generated/branch_deleted_subject.rs b/cdevents/src/generated/branch_deleted_subject.rs new file mode 100644 index 0000000..928b483 --- /dev/null +++ b/cdevents/src/generated/branch_deleted_subject.rs @@ -0,0 +1,15 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct BranchDeletedSubject { + + #[serde(rename = "content")] + pub content: serde_json::Map, + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source")] + pub source: String, + #[serde(rename = "type")] + pub tpe: String, +} diff --git a/cdevents/src/generated/build_finished_subject.rs b/cdevents/src/generated/build_finished_subject.rs new file mode 100644 index 0000000..29a98ec --- /dev/null +++ b/cdevents/src/generated/build_finished_subject.rs @@ -0,0 +1,15 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct BuildFinishedSubject { + + #[serde(rename = "content")] + pub content: serde_json::Map, + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source")] + pub source: String, + #[serde(rename = "type")] + pub tpe: String, +} diff --git a/cdevents/src/generated/build_queued_subject.rs b/cdevents/src/generated/build_queued_subject.rs new file mode 100644 index 0000000..4ff3d98 --- /dev/null +++ b/cdevents/src/generated/build_queued_subject.rs @@ -0,0 +1,15 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct BuildQueuedSubject { + + #[serde(rename = "content")] + pub content: serde_json::Map, + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source")] + pub source: String, + #[serde(rename = "type")] + pub tpe: String, +} diff --git a/cdevents/src/generated/build_started_subject.rs b/cdevents/src/generated/build_started_subject.rs new file mode 100644 index 0000000..623800e --- /dev/null +++ b/cdevents/src/generated/build_started_subject.rs @@ -0,0 +1,15 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct BuildStartedSubject { + + #[serde(rename = "content")] + pub content: serde_json::Map, + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source")] + pub source: String, + #[serde(rename = "type")] + pub tpe: String, +} diff --git a/cdevents/src/generated/change_abandoned_subject.rs b/cdevents/src/generated/change_abandoned_subject.rs new file mode 100644 index 0000000..f2e694d --- /dev/null +++ b/cdevents/src/generated/change_abandoned_subject.rs @@ -0,0 +1,15 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ChangeAbandonedSubject { + + #[serde(rename = "content")] + pub content: serde_json::Map, + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source")] + pub source: String, + #[serde(rename = "type")] + pub tpe: String, +} diff --git a/cdevents/src/generated/change_created_subject.rs b/cdevents/src/generated/change_created_subject.rs new file mode 100644 index 0000000..82de2e9 --- /dev/null +++ b/cdevents/src/generated/change_created_subject.rs @@ -0,0 +1,15 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ChangeCreatedSubject { + + #[serde(rename = "content")] + pub content: serde_json::Map, + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source")] + pub source: String, + #[serde(rename = "type")] + pub tpe: String, +} diff --git a/cdevents/src/generated/change_merged_subject.rs b/cdevents/src/generated/change_merged_subject.rs new file mode 100644 index 0000000..922a61b --- /dev/null +++ b/cdevents/src/generated/change_merged_subject.rs @@ -0,0 +1,15 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ChangeMergedSubject { + + #[serde(rename = "content")] + pub content: serde_json::Map, + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source")] + pub source: String, + #[serde(rename = "type")] + pub tpe: String, +} diff --git a/cdevents/src/generated/change_reviewed_subject.rs b/cdevents/src/generated/change_reviewed_subject.rs new file mode 100644 index 0000000..cc4c7d3 --- /dev/null +++ b/cdevents/src/generated/change_reviewed_subject.rs @@ -0,0 +1,15 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ChangeReviewedSubject { + + #[serde(rename = "content")] + pub content: serde_json::Map, + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source")] + pub source: String, + #[serde(rename = "type")] + pub tpe: String, +} diff --git a/cdevents/src/generated/change_updated_subject.rs b/cdevents/src/generated/change_updated_subject.rs new file mode 100644 index 0000000..98aac6e --- /dev/null +++ b/cdevents/src/generated/change_updated_subject.rs @@ -0,0 +1,15 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ChangeUpdatedSubject { + + #[serde(rename = "content")] + pub content: serde_json::Map, + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source")] + pub source: String, + #[serde(rename = "type")] + pub tpe: String, +} diff --git a/cdevents/src/generated/environment_created_subject.rs b/cdevents/src/generated/environment_created_subject.rs new file mode 100644 index 0000000..57de883 --- /dev/null +++ b/cdevents/src/generated/environment_created_subject.rs @@ -0,0 +1,15 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct EnvironmentCreatedSubject { + + #[serde(rename = "content")] + pub content: serde_json::Map, + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source")] + pub source: String, + #[serde(rename = "type")] + pub tpe: String, +} diff --git a/cdevents/src/generated/environment_deleted_subject.rs b/cdevents/src/generated/environment_deleted_subject.rs new file mode 100644 index 0000000..2e067ad --- /dev/null +++ b/cdevents/src/generated/environment_deleted_subject.rs @@ -0,0 +1,15 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct EnvironmentDeletedSubject { + + #[serde(rename = "content")] + pub content: serde_json::Map, + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source")] + pub source: String, + #[serde(rename = "type")] + pub tpe: String, +} diff --git a/cdevents/src/generated/environment_modified_subject.rs b/cdevents/src/generated/environment_modified_subject.rs new file mode 100644 index 0000000..ecc8a08 --- /dev/null +++ b/cdevents/src/generated/environment_modified_subject.rs @@ -0,0 +1,15 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct EnvironmentModifiedSubject { + + #[serde(rename = "content")] + pub content: serde_json::Map, + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source")] + pub source: String, + #[serde(rename = "type")] + pub tpe: String, +} diff --git a/cdevents/src/generated/incident_detected_subject.rs b/cdevents/src/generated/incident_detected_subject.rs new file mode 100644 index 0000000..91a2765 --- /dev/null +++ b/cdevents/src/generated/incident_detected_subject.rs @@ -0,0 +1,15 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct IncidentDetectedSubject { + + #[serde(rename = "content")] + pub content: serde_json::Map, + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source")] + pub source: String, + #[serde(rename = "type")] + pub tpe: String, +} diff --git a/cdevents/src/generated/incident_reported_subject.rs b/cdevents/src/generated/incident_reported_subject.rs new file mode 100644 index 0000000..3021b65 --- /dev/null +++ b/cdevents/src/generated/incident_reported_subject.rs @@ -0,0 +1,15 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct IncidentReportedSubject { + + #[serde(rename = "content")] + pub content: serde_json::Map, + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source")] + pub source: String, + #[serde(rename = "type")] + pub tpe: String, +} diff --git a/cdevents/src/generated/incident_resolved_subject.rs b/cdevents/src/generated/incident_resolved_subject.rs new file mode 100644 index 0000000..cf25f8c --- /dev/null +++ b/cdevents/src/generated/incident_resolved_subject.rs @@ -0,0 +1,15 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct IncidentResolvedSubject { + + #[serde(rename = "content")] + pub content: serde_json::Map, + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source")] + pub source: String, + #[serde(rename = "type")] + pub tpe: String, +} diff --git a/cdevents/src/generated/mod.rs b/cdevents/src/generated/mod.rs new file mode 100644 index 0000000..96c8688 --- /dev/null +++ b/cdevents/src/generated/mod.rs @@ -0,0 +1,86 @@ +// code generated by cdevents/sdk-rust/generator (mod.hbs) +mod artifact_packaged_subject; +mod artifact_published_subject; +mod artifact_signed_subject; +mod branch_created_subject; +mod branch_deleted_subject; +mod build_finished_subject; +mod build_queued_subject; +mod build_started_subject; +mod change_abandoned_subject; +mod change_created_subject; +mod change_merged_subject; +mod change_reviewed_subject; +mod change_updated_subject; +mod environment_created_subject; +mod environment_deleted_subject; +mod environment_modified_subject; +mod incident_detected_subject; +mod incident_reported_subject; +mod incident_resolved_subject; +mod pipeline_run_finished_subject; +mod pipeline_run_queued_subject; +mod pipeline_run_started_subject; +mod repository_created_subject; +mod repository_deleted_subject; +mod repository_modified_subject; +mod service_deployed_subject; +mod service_published_subject; +mod service_removed_subject; +mod service_rolledback_subject; +mod service_upgraded_subject; +mod task_run_finished_subject; +mod task_run_started_subject; +mod test_case_run_finished_subject; +mod test_case_run_queued_subject; +mod test_case_run_started_subject; +mod test_output_published_subject; +mod test_suite_finished_subject; +mod test_suite_run_queued_subject; +mod test_suite_run_started_subject; + +use serde::{Serialize, Deserialize}; + +#[derive(Debug,Clone,Serialize,Deserialize)] +#[serde(untagged)] // TODO how to use content of context.type as discriminator ? +pub enum Subject { + ArtifactPackagedSubject(artifact_packaged_subject::ArtifactPackagedSubject), + ArtifactPublishedSubject(artifact_published_subject::ArtifactPublishedSubject), + ArtifactSignedSubject(artifact_signed_subject::ArtifactSignedSubject), + BranchCreatedSubject(branch_created_subject::BranchCreatedSubject), + BranchDeletedSubject(branch_deleted_subject::BranchDeletedSubject), + BuildFinishedSubject(build_finished_subject::BuildFinishedSubject), + BuildQueuedSubject(build_queued_subject::BuildQueuedSubject), + BuildStartedSubject(build_started_subject::BuildStartedSubject), + ChangeAbandonedSubject(change_abandoned_subject::ChangeAbandonedSubject), + ChangeCreatedSubject(change_created_subject::ChangeCreatedSubject), + ChangeMergedSubject(change_merged_subject::ChangeMergedSubject), + ChangeReviewedSubject(change_reviewed_subject::ChangeReviewedSubject), + ChangeUpdatedSubject(change_updated_subject::ChangeUpdatedSubject), + EnvironmentCreatedSubject(environment_created_subject::EnvironmentCreatedSubject), + EnvironmentDeletedSubject(environment_deleted_subject::EnvironmentDeletedSubject), + EnvironmentModifiedSubject(environment_modified_subject::EnvironmentModifiedSubject), + IncidentDetectedSubject(incident_detected_subject::IncidentDetectedSubject), + IncidentReportedSubject(incident_reported_subject::IncidentReportedSubject), + IncidentResolvedSubject(incident_resolved_subject::IncidentResolvedSubject), + PipelineRunFinishedSubject(pipeline_run_finished_subject::PipelineRunFinishedSubject), + PipelineRunQueuedSubject(pipeline_run_queued_subject::PipelineRunQueuedSubject), + PipelineRunStartedSubject(pipeline_run_started_subject::PipelineRunStartedSubject), + RepositoryCreatedSubject(repository_created_subject::RepositoryCreatedSubject), + RepositoryDeletedSubject(repository_deleted_subject::RepositoryDeletedSubject), + RepositoryModifiedSubject(repository_modified_subject::RepositoryModifiedSubject), + ServiceDeployedSubject(service_deployed_subject::ServiceDeployedSubject), + ServicePublishedSubject(service_published_subject::ServicePublishedSubject), + ServiceRemovedSubject(service_removed_subject::ServiceRemovedSubject), + ServiceRolledbackSubject(service_rolledback_subject::ServiceRolledbackSubject), + ServiceUpgradedSubject(service_upgraded_subject::ServiceUpgradedSubject), + TaskRunFinishedSubject(task_run_finished_subject::TaskRunFinishedSubject), + TaskRunStartedSubject(task_run_started_subject::TaskRunStartedSubject), + TestCaseRunFinishedSubject(test_case_run_finished_subject::TestCaseRunFinishedSubject), + TestCaseRunQueuedSubject(test_case_run_queued_subject::TestCaseRunQueuedSubject), + TestCaseRunStartedSubject(test_case_run_started_subject::TestCaseRunStartedSubject), + TestOutputPublishedSubject(test_output_published_subject::TestOutputPublishedSubject), + TestSuiteFinishedSubject(test_suite_finished_subject::TestSuiteFinishedSubject), + TestSuiteRunQueuedSubject(test_suite_run_queued_subject::TestSuiteRunQueuedSubject), + TestSuiteRunStartedSubject(test_suite_run_started_subject::TestSuiteRunStartedSubject), +} diff --git a/cdevents/src/generated/pipeline_run_finished_subject.rs b/cdevents/src/generated/pipeline_run_finished_subject.rs new file mode 100644 index 0000000..33d7207 --- /dev/null +++ b/cdevents/src/generated/pipeline_run_finished_subject.rs @@ -0,0 +1,15 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct PipelineRunFinishedSubject { + + #[serde(rename = "content")] + pub content: serde_json::Map, + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source")] + pub source: String, + #[serde(rename = "type")] + pub tpe: String, +} diff --git a/cdevents/src/generated/pipeline_run_queued_subject.rs b/cdevents/src/generated/pipeline_run_queued_subject.rs new file mode 100644 index 0000000..4e66995 --- /dev/null +++ b/cdevents/src/generated/pipeline_run_queued_subject.rs @@ -0,0 +1,15 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct PipelineRunQueuedSubject { + + #[serde(rename = "content")] + pub content: serde_json::Map, + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source")] + pub source: String, + #[serde(rename = "type")] + pub tpe: String, +} diff --git a/cdevents/src/generated/pipeline_run_started_subject.rs b/cdevents/src/generated/pipeline_run_started_subject.rs new file mode 100644 index 0000000..3daa89b --- /dev/null +++ b/cdevents/src/generated/pipeline_run_started_subject.rs @@ -0,0 +1,15 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct PipelineRunStartedSubject { + + #[serde(rename = "content")] + pub content: serde_json::Map, + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source")] + pub source: String, + #[serde(rename = "type")] + pub tpe: String, +} diff --git a/cdevents/src/generated/repository_created_subject.rs b/cdevents/src/generated/repository_created_subject.rs new file mode 100644 index 0000000..2b65051 --- /dev/null +++ b/cdevents/src/generated/repository_created_subject.rs @@ -0,0 +1,15 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct RepositoryCreatedSubject { + + #[serde(rename = "content")] + pub content: serde_json::Map, + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source")] + pub source: String, + #[serde(rename = "type")] + pub tpe: String, +} diff --git a/cdevents/src/generated/repository_deleted_subject.rs b/cdevents/src/generated/repository_deleted_subject.rs new file mode 100644 index 0000000..8f8ebb2 --- /dev/null +++ b/cdevents/src/generated/repository_deleted_subject.rs @@ -0,0 +1,15 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct RepositoryDeletedSubject { + + #[serde(rename = "content")] + pub content: serde_json::Map, + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source")] + pub source: String, + #[serde(rename = "type")] + pub tpe: String, +} diff --git a/cdevents/src/generated/repository_modified_subject.rs b/cdevents/src/generated/repository_modified_subject.rs new file mode 100644 index 0000000..4567c9a --- /dev/null +++ b/cdevents/src/generated/repository_modified_subject.rs @@ -0,0 +1,15 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct RepositoryModifiedSubject { + + #[serde(rename = "content")] + pub content: serde_json::Map, + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source")] + pub source: String, + #[serde(rename = "type")] + pub tpe: String, +} diff --git a/cdevents/src/generated/service_deployed_subject.rs b/cdevents/src/generated/service_deployed_subject.rs new file mode 100644 index 0000000..455a71a --- /dev/null +++ b/cdevents/src/generated/service_deployed_subject.rs @@ -0,0 +1,15 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ServiceDeployedSubject { + + #[serde(rename = "content")] + pub content: serde_json::Map, + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source")] + pub source: String, + #[serde(rename = "type")] + pub tpe: String, +} diff --git a/cdevents/src/generated/service_published_subject.rs b/cdevents/src/generated/service_published_subject.rs new file mode 100644 index 0000000..4419626 --- /dev/null +++ b/cdevents/src/generated/service_published_subject.rs @@ -0,0 +1,15 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ServicePublishedSubject { + + #[serde(rename = "content")] + pub content: serde_json::Map, + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source")] + pub source: String, + #[serde(rename = "type")] + pub tpe: String, +} diff --git a/cdevents/src/generated/service_removed_subject.rs b/cdevents/src/generated/service_removed_subject.rs new file mode 100644 index 0000000..5794466 --- /dev/null +++ b/cdevents/src/generated/service_removed_subject.rs @@ -0,0 +1,15 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ServiceRemovedSubject { + + #[serde(rename = "content")] + pub content: serde_json::Map, + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source")] + pub source: String, + #[serde(rename = "type")] + pub tpe: String, +} diff --git a/cdevents/src/generated/service_rolledback_subject.rs b/cdevents/src/generated/service_rolledback_subject.rs new file mode 100644 index 0000000..8728934 --- /dev/null +++ b/cdevents/src/generated/service_rolledback_subject.rs @@ -0,0 +1,15 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ServiceRolledbackSubject { + + #[serde(rename = "content")] + pub content: serde_json::Map, + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source")] + pub source: String, + #[serde(rename = "type")] + pub tpe: String, +} diff --git a/cdevents/src/generated/service_upgraded_subject.rs b/cdevents/src/generated/service_upgraded_subject.rs new file mode 100644 index 0000000..dca6749 --- /dev/null +++ b/cdevents/src/generated/service_upgraded_subject.rs @@ -0,0 +1,15 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ServiceUpgradedSubject { + + #[serde(rename = "content")] + pub content: serde_json::Map, + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source")] + pub source: String, + #[serde(rename = "type")] + pub tpe: String, +} diff --git a/cdevents/src/generated/task_run_finished_subject.rs b/cdevents/src/generated/task_run_finished_subject.rs new file mode 100644 index 0000000..e61c3cb --- /dev/null +++ b/cdevents/src/generated/task_run_finished_subject.rs @@ -0,0 +1,15 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct TaskRunFinishedSubject { + + #[serde(rename = "content")] + pub content: serde_json::Map, + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source")] + pub source: String, + #[serde(rename = "type")] + pub tpe: String, +} diff --git a/cdevents/src/generated/task_run_started_subject.rs b/cdevents/src/generated/task_run_started_subject.rs new file mode 100644 index 0000000..28e70da --- /dev/null +++ b/cdevents/src/generated/task_run_started_subject.rs @@ -0,0 +1,15 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct TaskRunStartedSubject { + + #[serde(rename = "content")] + pub content: serde_json::Map, + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source")] + pub source: String, + #[serde(rename = "type")] + pub tpe: String, +} diff --git a/cdevents/src/generated/test_case_run_finished_subject.rs b/cdevents/src/generated/test_case_run_finished_subject.rs new file mode 100644 index 0000000..fdcd7b9 --- /dev/null +++ b/cdevents/src/generated/test_case_run_finished_subject.rs @@ -0,0 +1,15 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct TestCaseRunFinishedSubject { + + #[serde(rename = "content")] + pub content: serde_json::Map, + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source")] + pub source: String, + #[serde(rename = "type")] + pub tpe: String, +} diff --git a/cdevents/src/generated/test_case_run_queued_subject.rs b/cdevents/src/generated/test_case_run_queued_subject.rs new file mode 100644 index 0000000..3845e92 --- /dev/null +++ b/cdevents/src/generated/test_case_run_queued_subject.rs @@ -0,0 +1,15 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct TestCaseRunQueuedSubject { + + #[serde(rename = "content")] + pub content: serde_json::Map, + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source")] + pub source: String, + #[serde(rename = "type")] + pub tpe: String, +} diff --git a/cdevents/src/generated/test_case_run_started_subject.rs b/cdevents/src/generated/test_case_run_started_subject.rs new file mode 100644 index 0000000..848c009 --- /dev/null +++ b/cdevents/src/generated/test_case_run_started_subject.rs @@ -0,0 +1,15 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct TestCaseRunStartedSubject { + + #[serde(rename = "content")] + pub content: serde_json::Map, + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source")] + pub source: String, + #[serde(rename = "type")] + pub tpe: String, +} diff --git a/cdevents/src/generated/test_output_published_subject.rs b/cdevents/src/generated/test_output_published_subject.rs new file mode 100644 index 0000000..e68af43 --- /dev/null +++ b/cdevents/src/generated/test_output_published_subject.rs @@ -0,0 +1,15 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct TestOutputPublishedSubject { + + #[serde(rename = "content")] + pub content: serde_json::Map, + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source")] + pub source: String, + #[serde(rename = "type")] + pub tpe: String, +} diff --git a/cdevents/src/generated/test_suite_finished_subject.rs b/cdevents/src/generated/test_suite_finished_subject.rs new file mode 100644 index 0000000..08281b1 --- /dev/null +++ b/cdevents/src/generated/test_suite_finished_subject.rs @@ -0,0 +1,15 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct TestSuiteFinishedSubject { + + #[serde(rename = "content")] + pub content: serde_json::Map, + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source")] + pub source: String, + #[serde(rename = "type")] + pub tpe: String, +} diff --git a/cdevents/src/generated/test_suite_run_queued_subject.rs b/cdevents/src/generated/test_suite_run_queued_subject.rs new file mode 100644 index 0000000..2ed190f --- /dev/null +++ b/cdevents/src/generated/test_suite_run_queued_subject.rs @@ -0,0 +1,15 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct TestSuiteRunQueuedSubject { + + #[serde(rename = "content")] + pub content: serde_json::Map, + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source")] + pub source: String, + #[serde(rename = "type")] + pub tpe: String, +} diff --git a/cdevents/src/generated/test_suite_run_started_subject.rs b/cdevents/src/generated/test_suite_run_started_subject.rs new file mode 100644 index 0000000..2e2d386 --- /dev/null +++ b/cdevents/src/generated/test_suite_run_started_subject.rs @@ -0,0 +1,15 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct TestSuiteRunStartedSubject { + + #[serde(rename = "content")] + pub content: serde_json::Map, + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source")] + pub source: String, + #[serde(rename = "type")] + pub tpe: String, +} diff --git a/cdevents/src/lib.rs b/cdevents/src/lib.rs new file mode 100644 index 0000000..3040b41 --- /dev/null +++ b/cdevents/src/lib.rs @@ -0,0 +1,52 @@ +mod generated; + +pub use generated::*; +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct CDEvent { + pub context: Context, + pub subject: Subject, + #[serde(rename = "customData", skip_serializing_if = "Option::is_none")] + pub custom_data: Option, + #[serde( + rename = "customDataContentType", + skip_serializing_if = "Option::is_none" + )] + pub custom_data_content_type: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Context { + version: String, + id: String, + #[serde(with = "http_serde::uri")] + source: http::Uri, + #[serde(rename = "type")] + tpe: String, + #[serde(with = "time::serde::rfc3339")] + timestamp: time::OffsetDateTime, +} + +#[cfg(test)] +mod tests { + use super::*; + use assert_json_diff::assert_json_eq; + use rstest::rstest; + use std::fs; + use std::path::PathBuf; + + #[rstest] + fn for_each_example(#[files("../cdevents-spec/examples/*.json")] path: PathBuf) { + let example_json: serde_json::Value = serde_json::from_str( + fs::read_to_string(&path) + .expect("to read file as string") + .as_str(), + ) + .expect("to parse as json"); + let cdevent: CDEvent = + serde_json::from_value(example_json.clone()).expect("to parse as cdevent"); + let cdevent_json = serde_json::to_value(cdevent).expect("to convert into json"); + assert_json_eq!(example_json, cdevent_json); + } +} From ff776e4652e700bb62dd93c5e4eccc3e92ce722b Mon Sep 17 00:00:00 2001 From: David Bernard Date: Sat, 13 Jan 2024 11:51:22 +0100 Subject: [PATCH 04/34] refactor: rename crates `cdevents` into `cdevents-sdk` to aligned with java sdk and the crates `cloudevents-sdk` Signed-off-by: David Bernard --- Cargo.toml | 4 ++-- {cdevents => cdevents-sdk}/Cargo.toml | 2 +- .../src/generated/artifact_packaged_subject.rs | 0 .../src/generated/artifact_published_subject.rs | 0 .../src/generated/artifact_signed_subject.rs | 0 .../src/generated/branch_created_subject.rs | 0 .../src/generated/branch_deleted_subject.rs | 0 .../src/generated/build_finished_subject.rs | 0 .../src/generated/build_queued_subject.rs | 0 .../src/generated/build_started_subject.rs | 0 .../src/generated/change_abandoned_subject.rs | 0 .../src/generated/change_created_subject.rs | 0 .../src/generated/change_merged_subject.rs | 0 .../src/generated/change_reviewed_subject.rs | 0 .../src/generated/change_updated_subject.rs | 0 .../src/generated/environment_created_subject.rs | 0 .../src/generated/environment_deleted_subject.rs | 0 .../src/generated/environment_modified_subject.rs | 0 .../src/generated/incident_detected_subject.rs | 0 .../src/generated/incident_reported_subject.rs | 0 .../src/generated/incident_resolved_subject.rs | 0 {cdevents => cdevents-sdk}/src/generated/mod.rs | 0 .../src/generated/pipeline_run_finished_subject.rs | 0 .../src/generated/pipeline_run_queued_subject.rs | 0 .../src/generated/pipeline_run_started_subject.rs | 0 .../src/generated/repository_created_subject.rs | 0 .../src/generated/repository_deleted_subject.rs | 0 .../src/generated/repository_modified_subject.rs | 0 .../src/generated/service_deployed_subject.rs | 0 .../src/generated/service_published_subject.rs | 0 .../src/generated/service_removed_subject.rs | 0 .../src/generated/service_rolledback_subject.rs | 0 .../src/generated/service_upgraded_subject.rs | 0 .../src/generated/task_run_finished_subject.rs | 0 .../src/generated/task_run_started_subject.rs | 0 .../src/generated/test_case_run_finished_subject.rs | 0 .../src/generated/test_case_run_queued_subject.rs | 0 .../src/generated/test_case_run_started_subject.rs | 0 .../src/generated/test_output_published_subject.rs | 0 .../src/generated/test_suite_finished_subject.rs | 0 .../src/generated/test_suite_run_queued_subject.rs | 0 .../src/generated/test_suite_run_started_subject.rs | 0 {cdevents => cdevents-sdk}/src/lib.rs | 0 generator/src/main.rs | 2 +- 44 files changed, 4 insertions(+), 4 deletions(-) rename {cdevents => cdevents-sdk}/Cargo.toml (95%) rename {cdevents => cdevents-sdk}/src/generated/artifact_packaged_subject.rs (100%) rename {cdevents => cdevents-sdk}/src/generated/artifact_published_subject.rs (100%) rename {cdevents => cdevents-sdk}/src/generated/artifact_signed_subject.rs (100%) rename {cdevents => cdevents-sdk}/src/generated/branch_created_subject.rs (100%) rename {cdevents => cdevents-sdk}/src/generated/branch_deleted_subject.rs (100%) rename {cdevents => cdevents-sdk}/src/generated/build_finished_subject.rs (100%) rename {cdevents => cdevents-sdk}/src/generated/build_queued_subject.rs (100%) rename {cdevents => cdevents-sdk}/src/generated/build_started_subject.rs (100%) rename {cdevents => cdevents-sdk}/src/generated/change_abandoned_subject.rs (100%) rename {cdevents => cdevents-sdk}/src/generated/change_created_subject.rs (100%) rename {cdevents => cdevents-sdk}/src/generated/change_merged_subject.rs (100%) rename {cdevents => cdevents-sdk}/src/generated/change_reviewed_subject.rs (100%) rename {cdevents => cdevents-sdk}/src/generated/change_updated_subject.rs (100%) rename {cdevents => cdevents-sdk}/src/generated/environment_created_subject.rs (100%) rename {cdevents => cdevents-sdk}/src/generated/environment_deleted_subject.rs (100%) rename {cdevents => cdevents-sdk}/src/generated/environment_modified_subject.rs (100%) rename {cdevents => cdevents-sdk}/src/generated/incident_detected_subject.rs (100%) rename {cdevents => cdevents-sdk}/src/generated/incident_reported_subject.rs (100%) rename {cdevents => cdevents-sdk}/src/generated/incident_resolved_subject.rs (100%) rename {cdevents => cdevents-sdk}/src/generated/mod.rs (100%) rename {cdevents => cdevents-sdk}/src/generated/pipeline_run_finished_subject.rs (100%) rename {cdevents => cdevents-sdk}/src/generated/pipeline_run_queued_subject.rs (100%) rename {cdevents => cdevents-sdk}/src/generated/pipeline_run_started_subject.rs (100%) rename {cdevents => cdevents-sdk}/src/generated/repository_created_subject.rs (100%) rename {cdevents => cdevents-sdk}/src/generated/repository_deleted_subject.rs (100%) rename {cdevents => cdevents-sdk}/src/generated/repository_modified_subject.rs (100%) rename {cdevents => cdevents-sdk}/src/generated/service_deployed_subject.rs (100%) rename {cdevents => cdevents-sdk}/src/generated/service_published_subject.rs (100%) rename {cdevents => cdevents-sdk}/src/generated/service_removed_subject.rs (100%) rename {cdevents => cdevents-sdk}/src/generated/service_rolledback_subject.rs (100%) rename {cdevents => cdevents-sdk}/src/generated/service_upgraded_subject.rs (100%) rename {cdevents => cdevents-sdk}/src/generated/task_run_finished_subject.rs (100%) rename {cdevents => cdevents-sdk}/src/generated/task_run_started_subject.rs (100%) rename {cdevents => cdevents-sdk}/src/generated/test_case_run_finished_subject.rs (100%) rename {cdevents => cdevents-sdk}/src/generated/test_case_run_queued_subject.rs (100%) rename {cdevents => cdevents-sdk}/src/generated/test_case_run_started_subject.rs (100%) rename {cdevents => cdevents-sdk}/src/generated/test_output_published_subject.rs (100%) rename {cdevents => cdevents-sdk}/src/generated/test_suite_finished_subject.rs (100%) rename {cdevents => cdevents-sdk}/src/generated/test_suite_run_queued_subject.rs (100%) rename {cdevents => cdevents-sdk}/src/generated/test_suite_run_started_subject.rs (100%) rename {cdevents => cdevents-sdk}/src/lib.rs (100%) diff --git a/Cargo.toml b/Cargo.toml index eb5a335..cd66051 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,10 +1,10 @@ [workspace] resolver = "2" -members = ["cdevents", "generator"] +members = ["cdevents-sdk", "generator"] [workspace.package] edition = "2021" -version = "0.1.0" +version = "0.3.0" authors = ["David Bernard"] license = "ASL-2.0" repository = "https://github.com/cdevents/sdk-rust" diff --git a/cdevents/Cargo.toml b/cdevents-sdk/Cargo.toml similarity index 95% rename from cdevents/Cargo.toml rename to cdevents-sdk/Cargo.toml index e951b51..117cc99 100644 --- a/cdevents/Cargo.toml +++ b/cdevents-sdk/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "cdevents" +name = "cdevents-sdk" edition.workspace = true version.workspace = true authors.workspace = true diff --git a/cdevents/src/generated/artifact_packaged_subject.rs b/cdevents-sdk/src/generated/artifact_packaged_subject.rs similarity index 100% rename from cdevents/src/generated/artifact_packaged_subject.rs rename to cdevents-sdk/src/generated/artifact_packaged_subject.rs diff --git a/cdevents/src/generated/artifact_published_subject.rs b/cdevents-sdk/src/generated/artifact_published_subject.rs similarity index 100% rename from cdevents/src/generated/artifact_published_subject.rs rename to cdevents-sdk/src/generated/artifact_published_subject.rs diff --git a/cdevents/src/generated/artifact_signed_subject.rs b/cdevents-sdk/src/generated/artifact_signed_subject.rs similarity index 100% rename from cdevents/src/generated/artifact_signed_subject.rs rename to cdevents-sdk/src/generated/artifact_signed_subject.rs diff --git a/cdevents/src/generated/branch_created_subject.rs b/cdevents-sdk/src/generated/branch_created_subject.rs similarity index 100% rename from cdevents/src/generated/branch_created_subject.rs rename to cdevents-sdk/src/generated/branch_created_subject.rs diff --git a/cdevents/src/generated/branch_deleted_subject.rs b/cdevents-sdk/src/generated/branch_deleted_subject.rs similarity index 100% rename from cdevents/src/generated/branch_deleted_subject.rs rename to cdevents-sdk/src/generated/branch_deleted_subject.rs diff --git a/cdevents/src/generated/build_finished_subject.rs b/cdevents-sdk/src/generated/build_finished_subject.rs similarity index 100% rename from cdevents/src/generated/build_finished_subject.rs rename to cdevents-sdk/src/generated/build_finished_subject.rs diff --git a/cdevents/src/generated/build_queued_subject.rs b/cdevents-sdk/src/generated/build_queued_subject.rs similarity index 100% rename from cdevents/src/generated/build_queued_subject.rs rename to cdevents-sdk/src/generated/build_queued_subject.rs diff --git a/cdevents/src/generated/build_started_subject.rs b/cdevents-sdk/src/generated/build_started_subject.rs similarity index 100% rename from cdevents/src/generated/build_started_subject.rs rename to cdevents-sdk/src/generated/build_started_subject.rs diff --git a/cdevents/src/generated/change_abandoned_subject.rs b/cdevents-sdk/src/generated/change_abandoned_subject.rs similarity index 100% rename from cdevents/src/generated/change_abandoned_subject.rs rename to cdevents-sdk/src/generated/change_abandoned_subject.rs diff --git a/cdevents/src/generated/change_created_subject.rs b/cdevents-sdk/src/generated/change_created_subject.rs similarity index 100% rename from cdevents/src/generated/change_created_subject.rs rename to cdevents-sdk/src/generated/change_created_subject.rs diff --git a/cdevents/src/generated/change_merged_subject.rs b/cdevents-sdk/src/generated/change_merged_subject.rs similarity index 100% rename from cdevents/src/generated/change_merged_subject.rs rename to cdevents-sdk/src/generated/change_merged_subject.rs diff --git a/cdevents/src/generated/change_reviewed_subject.rs b/cdevents-sdk/src/generated/change_reviewed_subject.rs similarity index 100% rename from cdevents/src/generated/change_reviewed_subject.rs rename to cdevents-sdk/src/generated/change_reviewed_subject.rs diff --git a/cdevents/src/generated/change_updated_subject.rs b/cdevents-sdk/src/generated/change_updated_subject.rs similarity index 100% rename from cdevents/src/generated/change_updated_subject.rs rename to cdevents-sdk/src/generated/change_updated_subject.rs diff --git a/cdevents/src/generated/environment_created_subject.rs b/cdevents-sdk/src/generated/environment_created_subject.rs similarity index 100% rename from cdevents/src/generated/environment_created_subject.rs rename to cdevents-sdk/src/generated/environment_created_subject.rs diff --git a/cdevents/src/generated/environment_deleted_subject.rs b/cdevents-sdk/src/generated/environment_deleted_subject.rs similarity index 100% rename from cdevents/src/generated/environment_deleted_subject.rs rename to cdevents-sdk/src/generated/environment_deleted_subject.rs diff --git a/cdevents/src/generated/environment_modified_subject.rs b/cdevents-sdk/src/generated/environment_modified_subject.rs similarity index 100% rename from cdevents/src/generated/environment_modified_subject.rs rename to cdevents-sdk/src/generated/environment_modified_subject.rs diff --git a/cdevents/src/generated/incident_detected_subject.rs b/cdevents-sdk/src/generated/incident_detected_subject.rs similarity index 100% rename from cdevents/src/generated/incident_detected_subject.rs rename to cdevents-sdk/src/generated/incident_detected_subject.rs diff --git a/cdevents/src/generated/incident_reported_subject.rs b/cdevents-sdk/src/generated/incident_reported_subject.rs similarity index 100% rename from cdevents/src/generated/incident_reported_subject.rs rename to cdevents-sdk/src/generated/incident_reported_subject.rs diff --git a/cdevents/src/generated/incident_resolved_subject.rs b/cdevents-sdk/src/generated/incident_resolved_subject.rs similarity index 100% rename from cdevents/src/generated/incident_resolved_subject.rs rename to cdevents-sdk/src/generated/incident_resolved_subject.rs diff --git a/cdevents/src/generated/mod.rs b/cdevents-sdk/src/generated/mod.rs similarity index 100% rename from cdevents/src/generated/mod.rs rename to cdevents-sdk/src/generated/mod.rs diff --git a/cdevents/src/generated/pipeline_run_finished_subject.rs b/cdevents-sdk/src/generated/pipeline_run_finished_subject.rs similarity index 100% rename from cdevents/src/generated/pipeline_run_finished_subject.rs rename to cdevents-sdk/src/generated/pipeline_run_finished_subject.rs diff --git a/cdevents/src/generated/pipeline_run_queued_subject.rs b/cdevents-sdk/src/generated/pipeline_run_queued_subject.rs similarity index 100% rename from cdevents/src/generated/pipeline_run_queued_subject.rs rename to cdevents-sdk/src/generated/pipeline_run_queued_subject.rs diff --git a/cdevents/src/generated/pipeline_run_started_subject.rs b/cdevents-sdk/src/generated/pipeline_run_started_subject.rs similarity index 100% rename from cdevents/src/generated/pipeline_run_started_subject.rs rename to cdevents-sdk/src/generated/pipeline_run_started_subject.rs diff --git a/cdevents/src/generated/repository_created_subject.rs b/cdevents-sdk/src/generated/repository_created_subject.rs similarity index 100% rename from cdevents/src/generated/repository_created_subject.rs rename to cdevents-sdk/src/generated/repository_created_subject.rs diff --git a/cdevents/src/generated/repository_deleted_subject.rs b/cdevents-sdk/src/generated/repository_deleted_subject.rs similarity index 100% rename from cdevents/src/generated/repository_deleted_subject.rs rename to cdevents-sdk/src/generated/repository_deleted_subject.rs diff --git a/cdevents/src/generated/repository_modified_subject.rs b/cdevents-sdk/src/generated/repository_modified_subject.rs similarity index 100% rename from cdevents/src/generated/repository_modified_subject.rs rename to cdevents-sdk/src/generated/repository_modified_subject.rs diff --git a/cdevents/src/generated/service_deployed_subject.rs b/cdevents-sdk/src/generated/service_deployed_subject.rs similarity index 100% rename from cdevents/src/generated/service_deployed_subject.rs rename to cdevents-sdk/src/generated/service_deployed_subject.rs diff --git a/cdevents/src/generated/service_published_subject.rs b/cdevents-sdk/src/generated/service_published_subject.rs similarity index 100% rename from cdevents/src/generated/service_published_subject.rs rename to cdevents-sdk/src/generated/service_published_subject.rs diff --git a/cdevents/src/generated/service_removed_subject.rs b/cdevents-sdk/src/generated/service_removed_subject.rs similarity index 100% rename from cdevents/src/generated/service_removed_subject.rs rename to cdevents-sdk/src/generated/service_removed_subject.rs diff --git a/cdevents/src/generated/service_rolledback_subject.rs b/cdevents-sdk/src/generated/service_rolledback_subject.rs similarity index 100% rename from cdevents/src/generated/service_rolledback_subject.rs rename to cdevents-sdk/src/generated/service_rolledback_subject.rs diff --git a/cdevents/src/generated/service_upgraded_subject.rs b/cdevents-sdk/src/generated/service_upgraded_subject.rs similarity index 100% rename from cdevents/src/generated/service_upgraded_subject.rs rename to cdevents-sdk/src/generated/service_upgraded_subject.rs diff --git a/cdevents/src/generated/task_run_finished_subject.rs b/cdevents-sdk/src/generated/task_run_finished_subject.rs similarity index 100% rename from cdevents/src/generated/task_run_finished_subject.rs rename to cdevents-sdk/src/generated/task_run_finished_subject.rs diff --git a/cdevents/src/generated/task_run_started_subject.rs b/cdevents-sdk/src/generated/task_run_started_subject.rs similarity index 100% rename from cdevents/src/generated/task_run_started_subject.rs rename to cdevents-sdk/src/generated/task_run_started_subject.rs diff --git a/cdevents/src/generated/test_case_run_finished_subject.rs b/cdevents-sdk/src/generated/test_case_run_finished_subject.rs similarity index 100% rename from cdevents/src/generated/test_case_run_finished_subject.rs rename to cdevents-sdk/src/generated/test_case_run_finished_subject.rs diff --git a/cdevents/src/generated/test_case_run_queued_subject.rs b/cdevents-sdk/src/generated/test_case_run_queued_subject.rs similarity index 100% rename from cdevents/src/generated/test_case_run_queued_subject.rs rename to cdevents-sdk/src/generated/test_case_run_queued_subject.rs diff --git a/cdevents/src/generated/test_case_run_started_subject.rs b/cdevents-sdk/src/generated/test_case_run_started_subject.rs similarity index 100% rename from cdevents/src/generated/test_case_run_started_subject.rs rename to cdevents-sdk/src/generated/test_case_run_started_subject.rs diff --git a/cdevents/src/generated/test_output_published_subject.rs b/cdevents-sdk/src/generated/test_output_published_subject.rs similarity index 100% rename from cdevents/src/generated/test_output_published_subject.rs rename to cdevents-sdk/src/generated/test_output_published_subject.rs diff --git a/cdevents/src/generated/test_suite_finished_subject.rs b/cdevents-sdk/src/generated/test_suite_finished_subject.rs similarity index 100% rename from cdevents/src/generated/test_suite_finished_subject.rs rename to cdevents-sdk/src/generated/test_suite_finished_subject.rs diff --git a/cdevents/src/generated/test_suite_run_queued_subject.rs b/cdevents-sdk/src/generated/test_suite_run_queued_subject.rs similarity index 100% rename from cdevents/src/generated/test_suite_run_queued_subject.rs rename to cdevents-sdk/src/generated/test_suite_run_queued_subject.rs diff --git a/cdevents/src/generated/test_suite_run_started_subject.rs b/cdevents-sdk/src/generated/test_suite_run_started_subject.rs similarity index 100% rename from cdevents/src/generated/test_suite_run_started_subject.rs rename to cdevents-sdk/src/generated/test_suite_run_started_subject.rs diff --git a/cdevents/src/lib.rs b/cdevents-sdk/src/lib.rs similarity index 100% rename from cdevents/src/lib.rs rename to cdevents-sdk/src/lib.rs diff --git a/generator/src/main.rs b/generator/src/main.rs index 3dba149..4d16dbb 100644 --- a/generator/src/main.rs +++ b/generator/src/main.rs @@ -16,7 +16,7 @@ struct Settings { jsonschema_dir: PathBuf, /// destination directory where to generate code - #[arg(long, default_value = "../cdevents/src/generated")] + #[arg(long, default_value = "../cdevents-sdk/src/generated")] dest: PathBuf, } From a25f15082adbdbe6419cebb4b4b86fe2b54f7982 Mon Sep 17 00:00:00 2001 From: David Bernard Date: Sun, 14 Jan 2024 01:30:03 +0100 Subject: [PATCH 05/34] refactor: replace generation of json object by named types for Subjects content Signed-off-by: David Bernard --- .../generated/artifact_packaged_subject.rs | 28 +- .../generated/artifact_published_subject.rs | 18 +- .../src/generated/artifact_signed_subject.rs | 20 +- .../src/generated/branch_created_subject.rs | 28 +- .../src/generated/branch_deleted_subject.rs | 28 +- .../src/generated/build_finished_subject.rs | 20 +- .../src/generated/build_queued_subject.rs | 18 +- .../src/generated/build_started_subject.rs | 18 +- .../src/generated/change_abandoned_subject.rs | 28 +- .../src/generated/change_created_subject.rs | 28 +- .../src/generated/change_merged_subject.rs | 28 +- .../src/generated/change_reviewed_subject.rs | 28 +- .../src/generated/change_updated_subject.rs | 28 +- .../generated/environment_created_subject.rs | 22 +- .../generated/environment_deleted_subject.rs | 20 +- .../generated/environment_modified_subject.rs | 22 +- .../generated/incident_detected_subject.rs | 42 ++- .../generated/incident_reported_subject.rs | 44 ++- .../generated/incident_resolved_subject.rs | 42 ++- cdevents-sdk/src/generated/mod.rs | 322 +++++++++++++----- .../pipeline_run_finished_subject.rs | 26 +- .../generated/pipeline_run_queued_subject.rs | 22 +- .../generated/pipeline_run_started_subject.rs | 22 +- .../generated/repository_created_subject.rs | 26 +- .../generated/repository_deleted_subject.rs | 26 +- .../generated/repository_modified_subject.rs | 26 +- .../src/generated/service_deployed_subject.rs | 30 +- .../generated/service_published_subject.rs | 28 +- .../src/generated/service_removed_subject.rs | 28 +- .../generated/service_rolledback_subject.rs | 30 +- .../src/generated/service_upgraded_subject.rs | 30 +- .../generated/task_run_finished_subject.rs | 36 +- .../src/generated/task_run_started_subject.rs | 32 +- .../test_case_run_finished_subject.rs | 60 +++- .../generated/test_case_run_queued_subject.rs | 64 +++- .../test_case_run_started_subject.rs | 64 +++- .../test_output_published_subject.rs | 34 +- .../generated/test_suite_finished_subject.rs | 48 ++- .../test_suite_run_queued_subject.rs | 52 ++- .../test_suite_run_started_subject.rs | 52 ++- cdevents-sdk/src/lib.rs | 130 ++++++- generator/Cargo.toml | 3 +- generator/README.md | 3 +- generator/src/main.rs | 152 ++++++--- generator/templates/mod.hbs | 20 +- generator/templates/subject.hbs | 14 +- 46 files changed, 1478 insertions(+), 412 deletions(-) diff --git a/cdevents-sdk/src/generated/artifact_packaged_subject.rs b/cdevents-sdk/src/generated/artifact_packaged_subject.rs index a3e5b01..37b4210 100644 --- a/cdevents-sdk/src/generated/artifact_packaged_subject.rs +++ b/cdevents-sdk/src/generated/artifact_packaged_subject.rs @@ -1,15 +1,29 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct ArtifactPackagedSubject { - +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Subject { #[serde(rename = "content")] - pub content: serde_json::Map, + pub content: Content, #[serde(rename = "id")] pub id: String, - #[serde(rename = "source")] - pub source: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, #[serde(rename = "type")] - pub tpe: String, + pub r#type: String, } + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { + #[serde(rename = "change")] + pub change: Change, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Change { + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, +} + diff --git a/cdevents-sdk/src/generated/artifact_published_subject.rs b/cdevents-sdk/src/generated/artifact_published_subject.rs index 735443c..8504d81 100644 --- a/cdevents-sdk/src/generated/artifact_published_subject.rs +++ b/cdevents-sdk/src/generated/artifact_published_subject.rs @@ -1,15 +1,19 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct ArtifactPublishedSubject { - +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Subject { #[serde(rename = "content")] - pub content: serde_json::Map, + pub content: Content, #[serde(rename = "id")] pub id: String, - #[serde(rename = "source")] - pub source: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, #[serde(rename = "type")] - pub tpe: String, + pub r#type: String, } + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { +} + diff --git a/cdevents-sdk/src/generated/artifact_signed_subject.rs b/cdevents-sdk/src/generated/artifact_signed_subject.rs index 7f0493a..9984005 100644 --- a/cdevents-sdk/src/generated/artifact_signed_subject.rs +++ b/cdevents-sdk/src/generated/artifact_signed_subject.rs @@ -1,15 +1,21 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct ArtifactSignedSubject { - +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Subject { #[serde(rename = "content")] - pub content: serde_json::Map, + pub content: Content, #[serde(rename = "id")] pub id: String, - #[serde(rename = "source")] - pub source: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, #[serde(rename = "type")] - pub tpe: String, + pub r#type: String, } + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { + #[serde(rename = "signature")] + pub signature: String, +} + diff --git a/cdevents-sdk/src/generated/branch_created_subject.rs b/cdevents-sdk/src/generated/branch_created_subject.rs index e3cd2d3..20f7b4d 100644 --- a/cdevents-sdk/src/generated/branch_created_subject.rs +++ b/cdevents-sdk/src/generated/branch_created_subject.rs @@ -1,15 +1,29 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct BranchCreatedSubject { - +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Subject { #[serde(rename = "content")] - pub content: serde_json::Map, + pub content: Content, #[serde(rename = "id")] pub id: String, - #[serde(rename = "source")] - pub source: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, #[serde(rename = "type")] - pub tpe: String, + pub r#type: String, } + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { + #[serde(rename = "repository", skip_serializing_if = "Option::is_none")] + pub repository: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Repository { + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, +} + diff --git a/cdevents-sdk/src/generated/branch_deleted_subject.rs b/cdevents-sdk/src/generated/branch_deleted_subject.rs index 928b483..20f7b4d 100644 --- a/cdevents-sdk/src/generated/branch_deleted_subject.rs +++ b/cdevents-sdk/src/generated/branch_deleted_subject.rs @@ -1,15 +1,29 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct BranchDeletedSubject { - +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Subject { #[serde(rename = "content")] - pub content: serde_json::Map, + pub content: Content, #[serde(rename = "id")] pub id: String, - #[serde(rename = "source")] - pub source: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, #[serde(rename = "type")] - pub tpe: String, + pub r#type: String, } + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { + #[serde(rename = "repository", skip_serializing_if = "Option::is_none")] + pub repository: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Repository { + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, +} + diff --git a/cdevents-sdk/src/generated/build_finished_subject.rs b/cdevents-sdk/src/generated/build_finished_subject.rs index 29a98ec..861d935 100644 --- a/cdevents-sdk/src/generated/build_finished_subject.rs +++ b/cdevents-sdk/src/generated/build_finished_subject.rs @@ -1,15 +1,21 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct BuildFinishedSubject { - +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Subject { #[serde(rename = "content")] - pub content: serde_json::Map, + pub content: Content, #[serde(rename = "id")] pub id: String, - #[serde(rename = "source")] - pub source: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, #[serde(rename = "type")] - pub tpe: String, + pub r#type: String, } + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { + #[serde(rename = "artifactId", skip_serializing_if = "Option::is_none")] + pub artifact_id: Option, +} + diff --git a/cdevents-sdk/src/generated/build_queued_subject.rs b/cdevents-sdk/src/generated/build_queued_subject.rs index 4ff3d98..8504d81 100644 --- a/cdevents-sdk/src/generated/build_queued_subject.rs +++ b/cdevents-sdk/src/generated/build_queued_subject.rs @@ -1,15 +1,19 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct BuildQueuedSubject { - +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Subject { #[serde(rename = "content")] - pub content: serde_json::Map, + pub content: Content, #[serde(rename = "id")] pub id: String, - #[serde(rename = "source")] - pub source: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, #[serde(rename = "type")] - pub tpe: String, + pub r#type: String, } + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { +} + diff --git a/cdevents-sdk/src/generated/build_started_subject.rs b/cdevents-sdk/src/generated/build_started_subject.rs index 623800e..8504d81 100644 --- a/cdevents-sdk/src/generated/build_started_subject.rs +++ b/cdevents-sdk/src/generated/build_started_subject.rs @@ -1,15 +1,19 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct BuildStartedSubject { - +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Subject { #[serde(rename = "content")] - pub content: serde_json::Map, + pub content: Content, #[serde(rename = "id")] pub id: String, - #[serde(rename = "source")] - pub source: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, #[serde(rename = "type")] - pub tpe: String, + pub r#type: String, } + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { +} + diff --git a/cdevents-sdk/src/generated/change_abandoned_subject.rs b/cdevents-sdk/src/generated/change_abandoned_subject.rs index f2e694d..20f7b4d 100644 --- a/cdevents-sdk/src/generated/change_abandoned_subject.rs +++ b/cdevents-sdk/src/generated/change_abandoned_subject.rs @@ -1,15 +1,29 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct ChangeAbandonedSubject { - +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Subject { #[serde(rename = "content")] - pub content: serde_json::Map, + pub content: Content, #[serde(rename = "id")] pub id: String, - #[serde(rename = "source")] - pub source: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, #[serde(rename = "type")] - pub tpe: String, + pub r#type: String, } + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { + #[serde(rename = "repository", skip_serializing_if = "Option::is_none")] + pub repository: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Repository { + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, +} + diff --git a/cdevents-sdk/src/generated/change_created_subject.rs b/cdevents-sdk/src/generated/change_created_subject.rs index 82de2e9..20f7b4d 100644 --- a/cdevents-sdk/src/generated/change_created_subject.rs +++ b/cdevents-sdk/src/generated/change_created_subject.rs @@ -1,15 +1,29 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct ChangeCreatedSubject { - +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Subject { #[serde(rename = "content")] - pub content: serde_json::Map, + pub content: Content, #[serde(rename = "id")] pub id: String, - #[serde(rename = "source")] - pub source: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, #[serde(rename = "type")] - pub tpe: String, + pub r#type: String, } + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { + #[serde(rename = "repository", skip_serializing_if = "Option::is_none")] + pub repository: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Repository { + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, +} + diff --git a/cdevents-sdk/src/generated/change_merged_subject.rs b/cdevents-sdk/src/generated/change_merged_subject.rs index 922a61b..20f7b4d 100644 --- a/cdevents-sdk/src/generated/change_merged_subject.rs +++ b/cdevents-sdk/src/generated/change_merged_subject.rs @@ -1,15 +1,29 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct ChangeMergedSubject { - +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Subject { #[serde(rename = "content")] - pub content: serde_json::Map, + pub content: Content, #[serde(rename = "id")] pub id: String, - #[serde(rename = "source")] - pub source: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, #[serde(rename = "type")] - pub tpe: String, + pub r#type: String, } + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { + #[serde(rename = "repository", skip_serializing_if = "Option::is_none")] + pub repository: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Repository { + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, +} + diff --git a/cdevents-sdk/src/generated/change_reviewed_subject.rs b/cdevents-sdk/src/generated/change_reviewed_subject.rs index cc4c7d3..20f7b4d 100644 --- a/cdevents-sdk/src/generated/change_reviewed_subject.rs +++ b/cdevents-sdk/src/generated/change_reviewed_subject.rs @@ -1,15 +1,29 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct ChangeReviewedSubject { - +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Subject { #[serde(rename = "content")] - pub content: serde_json::Map, + pub content: Content, #[serde(rename = "id")] pub id: String, - #[serde(rename = "source")] - pub source: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, #[serde(rename = "type")] - pub tpe: String, + pub r#type: String, } + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { + #[serde(rename = "repository", skip_serializing_if = "Option::is_none")] + pub repository: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Repository { + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, +} + diff --git a/cdevents-sdk/src/generated/change_updated_subject.rs b/cdevents-sdk/src/generated/change_updated_subject.rs index 98aac6e..20f7b4d 100644 --- a/cdevents-sdk/src/generated/change_updated_subject.rs +++ b/cdevents-sdk/src/generated/change_updated_subject.rs @@ -1,15 +1,29 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct ChangeUpdatedSubject { - +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Subject { #[serde(rename = "content")] - pub content: serde_json::Map, + pub content: Content, #[serde(rename = "id")] pub id: String, - #[serde(rename = "source")] - pub source: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, #[serde(rename = "type")] - pub tpe: String, + pub r#type: String, } + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { + #[serde(rename = "repository", skip_serializing_if = "Option::is_none")] + pub repository: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Repository { + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, +} + diff --git a/cdevents-sdk/src/generated/environment_created_subject.rs b/cdevents-sdk/src/generated/environment_created_subject.rs index 57de883..f69765d 100644 --- a/cdevents-sdk/src/generated/environment_created_subject.rs +++ b/cdevents-sdk/src/generated/environment_created_subject.rs @@ -1,15 +1,23 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct EnvironmentCreatedSubject { - +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Subject { #[serde(rename = "content")] - pub content: serde_json::Map, + pub content: Content, #[serde(rename = "id")] pub id: String, - #[serde(rename = "source")] - pub source: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, #[serde(rename = "type")] - pub tpe: String, + pub r#type: String, } + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { + #[serde(rename = "name", skip_serializing_if = "Option::is_none")] + pub name: Option, + #[serde(rename = "url", skip_serializing_if = "Option::is_none")] + pub url: Option, +} + diff --git a/cdevents-sdk/src/generated/environment_deleted_subject.rs b/cdevents-sdk/src/generated/environment_deleted_subject.rs index 2e067ad..b34d527 100644 --- a/cdevents-sdk/src/generated/environment_deleted_subject.rs +++ b/cdevents-sdk/src/generated/environment_deleted_subject.rs @@ -1,15 +1,21 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct EnvironmentDeletedSubject { - +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Subject { #[serde(rename = "content")] - pub content: serde_json::Map, + pub content: Content, #[serde(rename = "id")] pub id: String, - #[serde(rename = "source")] - pub source: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, #[serde(rename = "type")] - pub tpe: String, + pub r#type: String, } + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { + #[serde(rename = "name", skip_serializing_if = "Option::is_none")] + pub name: Option, +} + diff --git a/cdevents-sdk/src/generated/environment_modified_subject.rs b/cdevents-sdk/src/generated/environment_modified_subject.rs index ecc8a08..f69765d 100644 --- a/cdevents-sdk/src/generated/environment_modified_subject.rs +++ b/cdevents-sdk/src/generated/environment_modified_subject.rs @@ -1,15 +1,23 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct EnvironmentModifiedSubject { - +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Subject { #[serde(rename = "content")] - pub content: serde_json::Map, + pub content: Content, #[serde(rename = "id")] pub id: String, - #[serde(rename = "source")] - pub source: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, #[serde(rename = "type")] - pub tpe: String, + pub r#type: String, } + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { + #[serde(rename = "name", skip_serializing_if = "Option::is_none")] + pub name: Option, + #[serde(rename = "url", skip_serializing_if = "Option::is_none")] + pub url: Option, +} + diff --git a/cdevents-sdk/src/generated/incident_detected_subject.rs b/cdevents-sdk/src/generated/incident_detected_subject.rs index 91a2765..b6a1219 100644 --- a/cdevents-sdk/src/generated/incident_detected_subject.rs +++ b/cdevents-sdk/src/generated/incident_detected_subject.rs @@ -1,15 +1,43 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct IncidentDetectedSubject { - +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Subject { #[serde(rename = "content")] - pub content: serde_json::Map, + pub content: Content, #[serde(rename = "id")] pub id: String, - #[serde(rename = "source")] - pub source: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, #[serde(rename = "type")] - pub tpe: String, + pub r#type: String, } + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { + #[serde(rename = "artifactId", skip_serializing_if = "Option::is_none")] + pub artifact_id: Option, + #[serde(rename = "description", skip_serializing_if = "Option::is_none")] + pub description: Option, + #[serde(rename = "environment")] + pub environment: Environment, + #[serde(rename = "service", skip_serializing_if = "Option::is_none")] + pub service: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Service { + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Environment { + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, +} + diff --git a/cdevents-sdk/src/generated/incident_reported_subject.rs b/cdevents-sdk/src/generated/incident_reported_subject.rs index 3021b65..f923b5f 100644 --- a/cdevents-sdk/src/generated/incident_reported_subject.rs +++ b/cdevents-sdk/src/generated/incident_reported_subject.rs @@ -1,15 +1,45 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct IncidentReportedSubject { - +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Subject { #[serde(rename = "content")] - pub content: serde_json::Map, + pub content: Content, #[serde(rename = "id")] pub id: String, - #[serde(rename = "source")] - pub source: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, #[serde(rename = "type")] - pub tpe: String, + pub r#type: String, } + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { + #[serde(rename = "artifactId", skip_serializing_if = "Option::is_none")] + pub artifact_id: Option, + #[serde(rename = "description", skip_serializing_if = "Option::is_none")] + pub description: Option, + #[serde(rename = "environment")] + pub environment: Environment, + #[serde(rename = "service", skip_serializing_if = "Option::is_none")] + pub service: Option, + #[serde(rename = "ticketURI")] + pub ticket_uri: String, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Service { + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Environment { + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, +} + diff --git a/cdevents-sdk/src/generated/incident_resolved_subject.rs b/cdevents-sdk/src/generated/incident_resolved_subject.rs index cf25f8c..b6a1219 100644 --- a/cdevents-sdk/src/generated/incident_resolved_subject.rs +++ b/cdevents-sdk/src/generated/incident_resolved_subject.rs @@ -1,15 +1,43 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct IncidentResolvedSubject { - +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Subject { #[serde(rename = "content")] - pub content: serde_json::Map, + pub content: Content, #[serde(rename = "id")] pub id: String, - #[serde(rename = "source")] - pub source: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, #[serde(rename = "type")] - pub tpe: String, + pub r#type: String, } + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { + #[serde(rename = "artifactId", skip_serializing_if = "Option::is_none")] + pub artifact_id: Option, + #[serde(rename = "description", skip_serializing_if = "Option::is_none")] + pub description: Option, + #[serde(rename = "environment")] + pub environment: Environment, + #[serde(rename = "service", skip_serializing_if = "Option::is_none")] + pub service: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Service { + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Environment { + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, +} + diff --git a/cdevents-sdk/src/generated/mod.rs b/cdevents-sdk/src/generated/mod.rs index 96c8688..53bc2ad 100644 --- a/cdevents-sdk/src/generated/mod.rs +++ b/cdevents-sdk/src/generated/mod.rs @@ -1,86 +1,250 @@ // code generated by cdevents/sdk-rust/generator (mod.hbs) -mod artifact_packaged_subject; -mod artifact_published_subject; -mod artifact_signed_subject; -mod branch_created_subject; -mod branch_deleted_subject; -mod build_finished_subject; -mod build_queued_subject; -mod build_started_subject; -mod change_abandoned_subject; -mod change_created_subject; -mod change_merged_subject; -mod change_reviewed_subject; -mod change_updated_subject; -mod environment_created_subject; -mod environment_deleted_subject; -mod environment_modified_subject; -mod incident_detected_subject; -mod incident_reported_subject; -mod incident_resolved_subject; -mod pipeline_run_finished_subject; -mod pipeline_run_queued_subject; -mod pipeline_run_started_subject; -mod repository_created_subject; -mod repository_deleted_subject; -mod repository_modified_subject; -mod service_deployed_subject; -mod service_published_subject; -mod service_removed_subject; -mod service_rolledback_subject; -mod service_upgraded_subject; -mod task_run_finished_subject; -mod task_run_started_subject; -mod test_case_run_finished_subject; -mod test_case_run_queued_subject; -mod test_case_run_started_subject; -mod test_output_published_subject; -mod test_suite_finished_subject; -mod test_suite_run_queued_subject; -mod test_suite_run_started_subject; +pub mod artifact_packaged_subject; +pub mod artifact_published_subject; +pub mod artifact_signed_subject; +pub mod branch_created_subject; +pub mod branch_deleted_subject; +pub mod build_finished_subject; +pub mod build_queued_subject; +pub mod build_started_subject; +pub mod change_abandoned_subject; +pub mod change_created_subject; +pub mod change_merged_subject; +pub mod change_reviewed_subject; +pub mod change_updated_subject; +pub mod environment_created_subject; +pub mod environment_deleted_subject; +pub mod environment_modified_subject; +pub mod incident_detected_subject; +pub mod incident_reported_subject; +pub mod incident_resolved_subject; +pub mod pipeline_run_finished_subject; +pub mod pipeline_run_queued_subject; +pub mod pipeline_run_started_subject; +pub mod repository_created_subject; +pub mod repository_deleted_subject; +pub mod repository_modified_subject; +pub mod service_deployed_subject; +pub mod service_published_subject; +pub mod service_removed_subject; +pub mod service_rolledback_subject; +pub mod service_upgraded_subject; +pub mod task_run_finished_subject; +pub mod task_run_started_subject; +pub mod test_case_run_finished_subject; +pub mod test_case_run_queued_subject; +pub mod test_case_run_started_subject; +pub mod test_output_published_subject; +pub mod test_suite_finished_subject; +pub mod test_suite_run_queued_subject; +pub mod test_suite_run_started_subject; use serde::{Serialize, Deserialize}; -#[derive(Debug,Clone,Serialize,Deserialize)] +#[derive(Debug,Clone,Serialize,Deserialize, PartialEq, Eq)] #[serde(untagged)] // TODO how to use content of context.type as discriminator ? pub enum Subject { - ArtifactPackagedSubject(artifact_packaged_subject::ArtifactPackagedSubject), - ArtifactPublishedSubject(artifact_published_subject::ArtifactPublishedSubject), - ArtifactSignedSubject(artifact_signed_subject::ArtifactSignedSubject), - BranchCreatedSubject(branch_created_subject::BranchCreatedSubject), - BranchDeletedSubject(branch_deleted_subject::BranchDeletedSubject), - BuildFinishedSubject(build_finished_subject::BuildFinishedSubject), - BuildQueuedSubject(build_queued_subject::BuildQueuedSubject), - BuildStartedSubject(build_started_subject::BuildStartedSubject), - ChangeAbandonedSubject(change_abandoned_subject::ChangeAbandonedSubject), - ChangeCreatedSubject(change_created_subject::ChangeCreatedSubject), - ChangeMergedSubject(change_merged_subject::ChangeMergedSubject), - ChangeReviewedSubject(change_reviewed_subject::ChangeReviewedSubject), - ChangeUpdatedSubject(change_updated_subject::ChangeUpdatedSubject), - EnvironmentCreatedSubject(environment_created_subject::EnvironmentCreatedSubject), - EnvironmentDeletedSubject(environment_deleted_subject::EnvironmentDeletedSubject), - EnvironmentModifiedSubject(environment_modified_subject::EnvironmentModifiedSubject), - IncidentDetectedSubject(incident_detected_subject::IncidentDetectedSubject), - IncidentReportedSubject(incident_reported_subject::IncidentReportedSubject), - IncidentResolvedSubject(incident_resolved_subject::IncidentResolvedSubject), - PipelineRunFinishedSubject(pipeline_run_finished_subject::PipelineRunFinishedSubject), - PipelineRunQueuedSubject(pipeline_run_queued_subject::PipelineRunQueuedSubject), - PipelineRunStartedSubject(pipeline_run_started_subject::PipelineRunStartedSubject), - RepositoryCreatedSubject(repository_created_subject::RepositoryCreatedSubject), - RepositoryDeletedSubject(repository_deleted_subject::RepositoryDeletedSubject), - RepositoryModifiedSubject(repository_modified_subject::RepositoryModifiedSubject), - ServiceDeployedSubject(service_deployed_subject::ServiceDeployedSubject), - ServicePublishedSubject(service_published_subject::ServicePublishedSubject), - ServiceRemovedSubject(service_removed_subject::ServiceRemovedSubject), - ServiceRolledbackSubject(service_rolledback_subject::ServiceRolledbackSubject), - ServiceUpgradedSubject(service_upgraded_subject::ServiceUpgradedSubject), - TaskRunFinishedSubject(task_run_finished_subject::TaskRunFinishedSubject), - TaskRunStartedSubject(task_run_started_subject::TaskRunStartedSubject), - TestCaseRunFinishedSubject(test_case_run_finished_subject::TestCaseRunFinishedSubject), - TestCaseRunQueuedSubject(test_case_run_queued_subject::TestCaseRunQueuedSubject), - TestCaseRunStartedSubject(test_case_run_started_subject::TestCaseRunStartedSubject), - TestOutputPublishedSubject(test_output_published_subject::TestOutputPublishedSubject), - TestSuiteFinishedSubject(test_suite_finished_subject::TestSuiteFinishedSubject), - TestSuiteRunQueuedSubject(test_suite_run_queued_subject::TestSuiteRunQueuedSubject), - TestSuiteRunStartedSubject(test_suite_run_started_subject::TestSuiteRunStartedSubject), + ArtifactPackagedSubject(artifact_packaged_subject::Subject), + ArtifactPublishedSubject(artifact_published_subject::Subject), + ArtifactSignedSubject(artifact_signed_subject::Subject), + BranchCreatedSubject(branch_created_subject::Subject), + BranchDeletedSubject(branch_deleted_subject::Subject), + BuildFinishedSubject(build_finished_subject::Subject), + BuildQueuedSubject(build_queued_subject::Subject), + BuildStartedSubject(build_started_subject::Subject), + ChangeAbandonedSubject(change_abandoned_subject::Subject), + ChangeCreatedSubject(change_created_subject::Subject), + ChangeMergedSubject(change_merged_subject::Subject), + ChangeReviewedSubject(change_reviewed_subject::Subject), + ChangeUpdatedSubject(change_updated_subject::Subject), + EnvironmentCreatedSubject(environment_created_subject::Subject), + EnvironmentDeletedSubject(environment_deleted_subject::Subject), + EnvironmentModifiedSubject(environment_modified_subject::Subject), + IncidentDetectedSubject(incident_detected_subject::Subject), + IncidentReportedSubject(incident_reported_subject::Subject), + IncidentResolvedSubject(incident_resolved_subject::Subject), + PipelineRunFinishedSubject(pipeline_run_finished_subject::Subject), + PipelineRunQueuedSubject(pipeline_run_queued_subject::Subject), + PipelineRunStartedSubject(pipeline_run_started_subject::Subject), + RepositoryCreatedSubject(repository_created_subject::Subject), + RepositoryDeletedSubject(repository_deleted_subject::Subject), + RepositoryModifiedSubject(repository_modified_subject::Subject), + ServiceDeployedSubject(service_deployed_subject::Subject), + ServicePublishedSubject(service_published_subject::Subject), + ServiceRemovedSubject(service_removed_subject::Subject), + ServiceRolledbackSubject(service_rolledback_subject::Subject), + ServiceUpgradedSubject(service_upgraded_subject::Subject), + TaskRunFinishedSubject(task_run_finished_subject::Subject), + TaskRunStartedSubject(task_run_started_subject::Subject), + TestCaseRunFinishedSubject(test_case_run_finished_subject::Subject), + TestCaseRunQueuedSubject(test_case_run_queued_subject::Subject), + TestCaseRunStartedSubject(test_case_run_started_subject::Subject), + TestOutputPublishedSubject(test_output_published_subject::Subject), + TestSuiteFinishedSubject(test_suite_finished_subject::Subject), + TestSuiteRunQueuedSubject(test_suite_run_queued_subject::Subject), + TestSuiteRunStartedSubject(test_suite_run_started_subject::Subject), } + +impl Subject { + pub fn from_json(ty: &str, json: serde_json::Value) -> Self{ + match ty { + "dev.cdevents.artifact.packaged.0.1.1" => { + let subject: artifact_packaged_subject::Subject = serde_json::from_value(json).unwrap(); + Self::ArtifactPackagedSubject(subject) + }, + "dev.cdevents.artifact.published.0.1.1" => { + let subject: artifact_published_subject::Subject = serde_json::from_value(json).unwrap(); + Self::ArtifactPublishedSubject(subject) + }, + "dev.cdevents.artifact.signed.0.1.0" => { + let subject: artifact_signed_subject::Subject = serde_json::from_value(json).unwrap(); + Self::ArtifactSignedSubject(subject) + }, + "dev.cdevents.branch.created.0.1.2" => { + let subject: branch_created_subject::Subject = serde_json::from_value(json).unwrap(); + Self::BranchCreatedSubject(subject) + }, + "dev.cdevents.branch.deleted.0.1.2" => { + let subject: branch_deleted_subject::Subject = serde_json::from_value(json).unwrap(); + Self::BranchDeletedSubject(subject) + }, + "dev.cdevents.build.finished.0.1.1" => { + let subject: build_finished_subject::Subject = serde_json::from_value(json).unwrap(); + Self::BuildFinishedSubject(subject) + }, + "dev.cdevents.build.queued.0.1.1" => { + let subject: build_queued_subject::Subject = serde_json::from_value(json).unwrap(); + Self::BuildQueuedSubject(subject) + }, + "dev.cdevents.build.started.0.1.1" => { + let subject: build_started_subject::Subject = serde_json::from_value(json).unwrap(); + Self::BuildStartedSubject(subject) + }, + "dev.cdevents.change.abandoned.0.1.2" => { + let subject: change_abandoned_subject::Subject = serde_json::from_value(json).unwrap(); + Self::ChangeAbandonedSubject(subject) + }, + "dev.cdevents.change.created.0.1.2" => { + let subject: change_created_subject::Subject = serde_json::from_value(json).unwrap(); + Self::ChangeCreatedSubject(subject) + }, + "dev.cdevents.change.merged.0.1.2" => { + let subject: change_merged_subject::Subject = serde_json::from_value(json).unwrap(); + Self::ChangeMergedSubject(subject) + }, + "dev.cdevents.change.reviewed.0.1.2" => { + let subject: change_reviewed_subject::Subject = serde_json::from_value(json).unwrap(); + Self::ChangeReviewedSubject(subject) + }, + "dev.cdevents.change.updated.0.1.2" => { + let subject: change_updated_subject::Subject = serde_json::from_value(json).unwrap(); + Self::ChangeUpdatedSubject(subject) + }, + "dev.cdevents.environment.created.0.1.1" => { + let subject: environment_created_subject::Subject = serde_json::from_value(json).unwrap(); + Self::EnvironmentCreatedSubject(subject) + }, + "dev.cdevents.environment.deleted.0.1.1" => { + let subject: environment_deleted_subject::Subject = serde_json::from_value(json).unwrap(); + Self::EnvironmentDeletedSubject(subject) + }, + "dev.cdevents.environment.modified.0.1.1" => { + let subject: environment_modified_subject::Subject = serde_json::from_value(json).unwrap(); + Self::EnvironmentModifiedSubject(subject) + }, + "dev.cdevents.incident.detected.0.1.0" => { + let subject: incident_detected_subject::Subject = serde_json::from_value(json).unwrap(); + Self::IncidentDetectedSubject(subject) + }, + "dev.cdevents.incident.reported.0.1.0" => { + let subject: incident_reported_subject::Subject = serde_json::from_value(json).unwrap(); + Self::IncidentReportedSubject(subject) + }, + "dev.cdevents.incident.resolved.0.1.0" => { + let subject: incident_resolved_subject::Subject = serde_json::from_value(json).unwrap(); + Self::IncidentResolvedSubject(subject) + }, + "dev.cdevents.pipelinerun.finished.0.1.1" => { + let subject: pipeline_run_finished_subject::Subject = serde_json::from_value(json).unwrap(); + Self::PipelineRunFinishedSubject(subject) + }, + "dev.cdevents.pipelinerun.queued.0.1.1" => { + let subject: pipeline_run_queued_subject::Subject = serde_json::from_value(json).unwrap(); + Self::PipelineRunQueuedSubject(subject) + }, + "dev.cdevents.pipelinerun.started.0.1.1" => { + let subject: pipeline_run_started_subject::Subject = serde_json::from_value(json).unwrap(); + Self::PipelineRunStartedSubject(subject) + }, + "dev.cdevents.repository.created.0.1.1" => { + let subject: repository_created_subject::Subject = serde_json::from_value(json).unwrap(); + Self::RepositoryCreatedSubject(subject) + }, + "dev.cdevents.repository.deleted.0.1.1" => { + let subject: repository_deleted_subject::Subject = serde_json::from_value(json).unwrap(); + Self::RepositoryDeletedSubject(subject) + }, + "dev.cdevents.repository.modified.0.1.1" => { + let subject: repository_modified_subject::Subject = serde_json::from_value(json).unwrap(); + Self::RepositoryModifiedSubject(subject) + }, + "dev.cdevents.service.deployed.0.1.1" => { + let subject: service_deployed_subject::Subject = serde_json::from_value(json).unwrap(); + Self::ServiceDeployedSubject(subject) + }, + "dev.cdevents.service.published.0.1.1" => { + let subject: service_published_subject::Subject = serde_json::from_value(json).unwrap(); + Self::ServicePublishedSubject(subject) + }, + "dev.cdevents.service.removed.0.1.1" => { + let subject: service_removed_subject::Subject = serde_json::from_value(json).unwrap(); + Self::ServiceRemovedSubject(subject) + }, + "dev.cdevents.service.rolledback.0.1.1" => { + let subject: service_rolledback_subject::Subject = serde_json::from_value(json).unwrap(); + Self::ServiceRolledbackSubject(subject) + }, + "dev.cdevents.service.upgraded.0.1.1" => { + let subject: service_upgraded_subject::Subject = serde_json::from_value(json).unwrap(); + Self::ServiceUpgradedSubject(subject) + }, + "dev.cdevents.taskrun.finished.0.1.1" => { + let subject: task_run_finished_subject::Subject = serde_json::from_value(json).unwrap(); + Self::TaskRunFinishedSubject(subject) + }, + "dev.cdevents.taskrun.started.0.1.1" => { + let subject: task_run_started_subject::Subject = serde_json::from_value(json).unwrap(); + Self::TaskRunStartedSubject(subject) + }, + "dev.cdevents.testcaserun.finished.0.1.0" => { + let subject: test_case_run_finished_subject::Subject = serde_json::from_value(json).unwrap(); + Self::TestCaseRunFinishedSubject(subject) + }, + "dev.cdevents.testcaserun.queued.0.1.0" => { + let subject: test_case_run_queued_subject::Subject = serde_json::from_value(json).unwrap(); + Self::TestCaseRunQueuedSubject(subject) + }, + "dev.cdevents.testcaserun.started.0.1.0" => { + let subject: test_case_run_started_subject::Subject = serde_json::from_value(json).unwrap(); + Self::TestCaseRunStartedSubject(subject) + }, + "dev.cdevents.testoutput.published.0.1.0" => { + let subject: test_output_published_subject::Subject = serde_json::from_value(json).unwrap(); + Self::TestOutputPublishedSubject(subject) + }, + "dev.cdevents.testsuiterun.finished.0.1.0" => { + let subject: test_suite_finished_subject::Subject = serde_json::from_value(json).unwrap(); + Self::TestSuiteFinishedSubject(subject) + }, + "dev.cdevents.testsuiterun.queued.0.1.0" => { + let subject: test_suite_run_queued_subject::Subject = serde_json::from_value(json).unwrap(); + Self::TestSuiteRunQueuedSubject(subject) + }, + "dev.cdevents.testsuiterun.started.0.1.0" => { + let subject: test_suite_run_started_subject::Subject = serde_json::from_value(json).unwrap(); + Self::TestSuiteRunStartedSubject(subject) + }, + x => todo!("no implementation for type '{}', please open an issue", x), + } + } +} \ No newline at end of file diff --git a/cdevents-sdk/src/generated/pipeline_run_finished_subject.rs b/cdevents-sdk/src/generated/pipeline_run_finished_subject.rs index 33d7207..0eb0e2c 100644 --- a/cdevents-sdk/src/generated/pipeline_run_finished_subject.rs +++ b/cdevents-sdk/src/generated/pipeline_run_finished_subject.rs @@ -1,15 +1,27 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct PipelineRunFinishedSubject { - +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Subject { #[serde(rename = "content")] - pub content: serde_json::Map, + pub content: Content, #[serde(rename = "id")] pub id: String, - #[serde(rename = "source")] - pub source: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, #[serde(rename = "type")] - pub tpe: String, + pub r#type: String, } + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { + #[serde(rename = "errors", skip_serializing_if = "Option::is_none")] + pub errors: Option, + #[serde(rename = "outcome", skip_serializing_if = "Option::is_none")] + pub outcome: Option, + #[serde(rename = "pipelineName", skip_serializing_if = "Option::is_none")] + pub pipeline_name: Option, + #[serde(rename = "url", skip_serializing_if = "Option::is_none")] + pub url: Option, +} + diff --git a/cdevents-sdk/src/generated/pipeline_run_queued_subject.rs b/cdevents-sdk/src/generated/pipeline_run_queued_subject.rs index 4e66995..269157c 100644 --- a/cdevents-sdk/src/generated/pipeline_run_queued_subject.rs +++ b/cdevents-sdk/src/generated/pipeline_run_queued_subject.rs @@ -1,15 +1,23 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct PipelineRunQueuedSubject { - +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Subject { #[serde(rename = "content")] - pub content: serde_json::Map, + pub content: Content, #[serde(rename = "id")] pub id: String, - #[serde(rename = "source")] - pub source: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, #[serde(rename = "type")] - pub tpe: String, + pub r#type: String, } + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { + #[serde(rename = "pipelineName", skip_serializing_if = "Option::is_none")] + pub pipeline_name: Option, + #[serde(rename = "url", skip_serializing_if = "Option::is_none")] + pub url: Option, +} + diff --git a/cdevents-sdk/src/generated/pipeline_run_started_subject.rs b/cdevents-sdk/src/generated/pipeline_run_started_subject.rs index 3daa89b..1962fff 100644 --- a/cdevents-sdk/src/generated/pipeline_run_started_subject.rs +++ b/cdevents-sdk/src/generated/pipeline_run_started_subject.rs @@ -1,15 +1,23 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct PipelineRunStartedSubject { - +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Subject { #[serde(rename = "content")] - pub content: serde_json::Map, + pub content: Content, #[serde(rename = "id")] pub id: String, - #[serde(rename = "source")] - pub source: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, #[serde(rename = "type")] - pub tpe: String, + pub r#type: String, } + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { + #[serde(rename = "pipelineName")] + pub pipeline_name: String, + #[serde(rename = "url")] + pub url: String, +} + diff --git a/cdevents-sdk/src/generated/repository_created_subject.rs b/cdevents-sdk/src/generated/repository_created_subject.rs index 2b65051..3f6fe9c 100644 --- a/cdevents-sdk/src/generated/repository_created_subject.rs +++ b/cdevents-sdk/src/generated/repository_created_subject.rs @@ -1,15 +1,27 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct RepositoryCreatedSubject { - +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Subject { #[serde(rename = "content")] - pub content: serde_json::Map, + pub content: Content, #[serde(rename = "id")] pub id: String, - #[serde(rename = "source")] - pub source: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, #[serde(rename = "type")] - pub tpe: String, + pub r#type: String, } + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { + #[serde(rename = "name")] + pub name: String, + #[serde(rename = "owner", skip_serializing_if = "Option::is_none")] + pub owner: Option, + #[serde(rename = "url")] + pub url: String, + #[serde(rename = "viewUrl", skip_serializing_if = "Option::is_none")] + pub view_url: Option, +} + diff --git a/cdevents-sdk/src/generated/repository_deleted_subject.rs b/cdevents-sdk/src/generated/repository_deleted_subject.rs index 8f8ebb2..8274fd8 100644 --- a/cdevents-sdk/src/generated/repository_deleted_subject.rs +++ b/cdevents-sdk/src/generated/repository_deleted_subject.rs @@ -1,15 +1,27 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct RepositoryDeletedSubject { - +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Subject { #[serde(rename = "content")] - pub content: serde_json::Map, + pub content: Content, #[serde(rename = "id")] pub id: String, - #[serde(rename = "source")] - pub source: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, #[serde(rename = "type")] - pub tpe: String, + pub r#type: String, } + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { + #[serde(rename = "name", skip_serializing_if = "Option::is_none")] + pub name: Option, + #[serde(rename = "owner", skip_serializing_if = "Option::is_none")] + pub owner: Option, + #[serde(rename = "url", skip_serializing_if = "Option::is_none")] + pub url: Option, + #[serde(rename = "viewUrl", skip_serializing_if = "Option::is_none")] + pub view_url: Option, +} + diff --git a/cdevents-sdk/src/generated/repository_modified_subject.rs b/cdevents-sdk/src/generated/repository_modified_subject.rs index 4567c9a..8274fd8 100644 --- a/cdevents-sdk/src/generated/repository_modified_subject.rs +++ b/cdevents-sdk/src/generated/repository_modified_subject.rs @@ -1,15 +1,27 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct RepositoryModifiedSubject { - +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Subject { #[serde(rename = "content")] - pub content: serde_json::Map, + pub content: Content, #[serde(rename = "id")] pub id: String, - #[serde(rename = "source")] - pub source: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, #[serde(rename = "type")] - pub tpe: String, + pub r#type: String, } + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { + #[serde(rename = "name", skip_serializing_if = "Option::is_none")] + pub name: Option, + #[serde(rename = "owner", skip_serializing_if = "Option::is_none")] + pub owner: Option, + #[serde(rename = "url", skip_serializing_if = "Option::is_none")] + pub url: Option, + #[serde(rename = "viewUrl", skip_serializing_if = "Option::is_none")] + pub view_url: Option, +} + diff --git a/cdevents-sdk/src/generated/service_deployed_subject.rs b/cdevents-sdk/src/generated/service_deployed_subject.rs index 455a71a..299b77b 100644 --- a/cdevents-sdk/src/generated/service_deployed_subject.rs +++ b/cdevents-sdk/src/generated/service_deployed_subject.rs @@ -1,15 +1,31 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct ServiceDeployedSubject { - +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Subject { #[serde(rename = "content")] - pub content: serde_json::Map, + pub content: Content, #[serde(rename = "id")] pub id: String, - #[serde(rename = "source")] - pub source: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, #[serde(rename = "type")] - pub tpe: String, + pub r#type: String, } + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { + #[serde(rename = "artifactId")] + pub artifact_id: String, + #[serde(rename = "environment")] + pub environment: Environment, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Environment { + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, +} + diff --git a/cdevents-sdk/src/generated/service_published_subject.rs b/cdevents-sdk/src/generated/service_published_subject.rs index 4419626..d480fbc 100644 --- a/cdevents-sdk/src/generated/service_published_subject.rs +++ b/cdevents-sdk/src/generated/service_published_subject.rs @@ -1,15 +1,29 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct ServicePublishedSubject { - +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Subject { #[serde(rename = "content")] - pub content: serde_json::Map, + pub content: Content, #[serde(rename = "id")] pub id: String, - #[serde(rename = "source")] - pub source: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, #[serde(rename = "type")] - pub tpe: String, + pub r#type: String, } + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { + #[serde(rename = "environment", skip_serializing_if = "Option::is_none")] + pub environment: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Environment { + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, +} + diff --git a/cdevents-sdk/src/generated/service_removed_subject.rs b/cdevents-sdk/src/generated/service_removed_subject.rs index 5794466..d480fbc 100644 --- a/cdevents-sdk/src/generated/service_removed_subject.rs +++ b/cdevents-sdk/src/generated/service_removed_subject.rs @@ -1,15 +1,29 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct ServiceRemovedSubject { - +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Subject { #[serde(rename = "content")] - pub content: serde_json::Map, + pub content: Content, #[serde(rename = "id")] pub id: String, - #[serde(rename = "source")] - pub source: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, #[serde(rename = "type")] - pub tpe: String, + pub r#type: String, } + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { + #[serde(rename = "environment", skip_serializing_if = "Option::is_none")] + pub environment: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Environment { + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, +} + diff --git a/cdevents-sdk/src/generated/service_rolledback_subject.rs b/cdevents-sdk/src/generated/service_rolledback_subject.rs index 8728934..299b77b 100644 --- a/cdevents-sdk/src/generated/service_rolledback_subject.rs +++ b/cdevents-sdk/src/generated/service_rolledback_subject.rs @@ -1,15 +1,31 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct ServiceRolledbackSubject { - +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Subject { #[serde(rename = "content")] - pub content: serde_json::Map, + pub content: Content, #[serde(rename = "id")] pub id: String, - #[serde(rename = "source")] - pub source: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, #[serde(rename = "type")] - pub tpe: String, + pub r#type: String, } + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { + #[serde(rename = "artifactId")] + pub artifact_id: String, + #[serde(rename = "environment")] + pub environment: Environment, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Environment { + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, +} + diff --git a/cdevents-sdk/src/generated/service_upgraded_subject.rs b/cdevents-sdk/src/generated/service_upgraded_subject.rs index dca6749..299b77b 100644 --- a/cdevents-sdk/src/generated/service_upgraded_subject.rs +++ b/cdevents-sdk/src/generated/service_upgraded_subject.rs @@ -1,15 +1,31 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct ServiceUpgradedSubject { - +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Subject { #[serde(rename = "content")] - pub content: serde_json::Map, + pub content: Content, #[serde(rename = "id")] pub id: String, - #[serde(rename = "source")] - pub source: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, #[serde(rename = "type")] - pub tpe: String, + pub r#type: String, } + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { + #[serde(rename = "artifactId")] + pub artifact_id: String, + #[serde(rename = "environment")] + pub environment: Environment, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Environment { + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, +} + diff --git a/cdevents-sdk/src/generated/task_run_finished_subject.rs b/cdevents-sdk/src/generated/task_run_finished_subject.rs index e61c3cb..3f81e24 100644 --- a/cdevents-sdk/src/generated/task_run_finished_subject.rs +++ b/cdevents-sdk/src/generated/task_run_finished_subject.rs @@ -1,15 +1,37 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct TaskRunFinishedSubject { - +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Subject { #[serde(rename = "content")] - pub content: serde_json::Map, + pub content: Content, #[serde(rename = "id")] pub id: String, - #[serde(rename = "source")] - pub source: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, #[serde(rename = "type")] - pub tpe: String, + pub r#type: String, } + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { + #[serde(rename = "errors", skip_serializing_if = "Option::is_none")] + pub errors: Option, + #[serde(rename = "outcome", skip_serializing_if = "Option::is_none")] + pub outcome: Option, + #[serde(rename = "pipelineRun", skip_serializing_if = "Option::is_none")] + pub pipeline_run: Option, + #[serde(rename = "taskName", skip_serializing_if = "Option::is_none")] + pub task_name: Option, + #[serde(rename = "url", skip_serializing_if = "Option::is_none")] + pub url: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct PipelineRun { + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, +} + diff --git a/cdevents-sdk/src/generated/task_run_started_subject.rs b/cdevents-sdk/src/generated/task_run_started_subject.rs index 28e70da..0b7ef17 100644 --- a/cdevents-sdk/src/generated/task_run_started_subject.rs +++ b/cdevents-sdk/src/generated/task_run_started_subject.rs @@ -1,15 +1,33 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct TaskRunStartedSubject { - +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Subject { #[serde(rename = "content")] - pub content: serde_json::Map, + pub content: Content, #[serde(rename = "id")] pub id: String, - #[serde(rename = "source")] - pub source: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, #[serde(rename = "type")] - pub tpe: String, + pub r#type: String, } + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { + #[serde(rename = "pipelineRun", skip_serializing_if = "Option::is_none")] + pub pipeline_run: Option, + #[serde(rename = "taskName", skip_serializing_if = "Option::is_none")] + pub task_name: Option, + #[serde(rename = "url", skip_serializing_if = "Option::is_none")] + pub url: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct PipelineRun { + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, +} + diff --git a/cdevents-sdk/src/generated/test_case_run_finished_subject.rs b/cdevents-sdk/src/generated/test_case_run_finished_subject.rs index fdcd7b9..fdf8b97 100644 --- a/cdevents-sdk/src/generated/test_case_run_finished_subject.rs +++ b/cdevents-sdk/src/generated/test_case_run_finished_subject.rs @@ -1,15 +1,61 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct TestCaseRunFinishedSubject { - +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Subject { #[serde(rename = "content")] - pub content: serde_json::Map, + pub content: Content, #[serde(rename = "id")] pub id: String, - #[serde(rename = "source")] - pub source: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, #[serde(rename = "type")] - pub tpe: String, + pub r#type: String, } + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { + #[serde(rename = "environment")] + pub environment: Environment, + #[serde(rename = "outcome")] + pub outcome: String, + #[serde(rename = "reason", skip_serializing_if = "Option::is_none")] + pub reason: Option, + #[serde(rename = "severity", skip_serializing_if = "Option::is_none")] + pub severity: Option, + #[serde(rename = "testCase", skip_serializing_if = "Option::is_none")] + pub test_case: Option, + #[serde(rename = "testSuiteRun", skip_serializing_if = "Option::is_none")] + pub test_suite_run: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct TestSuiteRun { + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct TestCase { + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "name", skip_serializing_if = "Option::is_none")] + pub name: Option, + #[serde(rename = "type", skip_serializing_if = "Option::is_none")] + pub r#type: Option, + #[serde(rename = "uri", skip_serializing_if = "Option::is_none")] + pub uri: Option, + #[serde(rename = "version", skip_serializing_if = "Option::is_none")] + pub version: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Environment { + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, +} + diff --git a/cdevents-sdk/src/generated/test_case_run_queued_subject.rs b/cdevents-sdk/src/generated/test_case_run_queued_subject.rs index 3845e92..f64d3f2 100644 --- a/cdevents-sdk/src/generated/test_case_run_queued_subject.rs +++ b/cdevents-sdk/src/generated/test_case_run_queued_subject.rs @@ -1,15 +1,65 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct TestCaseRunQueuedSubject { - +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Subject { #[serde(rename = "content")] - pub content: serde_json::Map, + pub content: Content, #[serde(rename = "id")] pub id: String, - #[serde(rename = "source")] - pub source: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, #[serde(rename = "type")] - pub tpe: String, + pub r#type: String, } + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { + #[serde(rename = "environment")] + pub environment: Environment, + #[serde(rename = "testCase", skip_serializing_if = "Option::is_none")] + pub test_case: Option, + #[serde(rename = "testSuiteRun", skip_serializing_if = "Option::is_none")] + pub test_suite_run: Option, + #[serde(rename = "trigger", skip_serializing_if = "Option::is_none")] + pub trigger: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Trigger { + #[serde(rename = "type", skip_serializing_if = "Option::is_none")] + pub r#type: Option, + #[serde(rename = "uri", skip_serializing_if = "Option::is_none")] + pub uri: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct TestSuiteRun { + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct TestCase { + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "name", skip_serializing_if = "Option::is_none")] + pub name: Option, + #[serde(rename = "type", skip_serializing_if = "Option::is_none")] + pub r#type: Option, + #[serde(rename = "uri", skip_serializing_if = "Option::is_none")] + pub uri: Option, + #[serde(rename = "version", skip_serializing_if = "Option::is_none")] + pub version: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Environment { + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, +} + diff --git a/cdevents-sdk/src/generated/test_case_run_started_subject.rs b/cdevents-sdk/src/generated/test_case_run_started_subject.rs index 848c009..f64d3f2 100644 --- a/cdevents-sdk/src/generated/test_case_run_started_subject.rs +++ b/cdevents-sdk/src/generated/test_case_run_started_subject.rs @@ -1,15 +1,65 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct TestCaseRunStartedSubject { - +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Subject { #[serde(rename = "content")] - pub content: serde_json::Map, + pub content: Content, #[serde(rename = "id")] pub id: String, - #[serde(rename = "source")] - pub source: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, #[serde(rename = "type")] - pub tpe: String, + pub r#type: String, } + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { + #[serde(rename = "environment")] + pub environment: Environment, + #[serde(rename = "testCase", skip_serializing_if = "Option::is_none")] + pub test_case: Option, + #[serde(rename = "testSuiteRun", skip_serializing_if = "Option::is_none")] + pub test_suite_run: Option, + #[serde(rename = "trigger", skip_serializing_if = "Option::is_none")] + pub trigger: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Trigger { + #[serde(rename = "type", skip_serializing_if = "Option::is_none")] + pub r#type: Option, + #[serde(rename = "uri", skip_serializing_if = "Option::is_none")] + pub uri: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct TestSuiteRun { + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct TestCase { + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "name", skip_serializing_if = "Option::is_none")] + pub name: Option, + #[serde(rename = "type", skip_serializing_if = "Option::is_none")] + pub r#type: Option, + #[serde(rename = "uri", skip_serializing_if = "Option::is_none")] + pub uri: Option, + #[serde(rename = "version", skip_serializing_if = "Option::is_none")] + pub version: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Environment { + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, +} + diff --git a/cdevents-sdk/src/generated/test_output_published_subject.rs b/cdevents-sdk/src/generated/test_output_published_subject.rs index e68af43..9ccc5ab 100644 --- a/cdevents-sdk/src/generated/test_output_published_subject.rs +++ b/cdevents-sdk/src/generated/test_output_published_subject.rs @@ -1,15 +1,35 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct TestOutputPublishedSubject { - +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Subject { #[serde(rename = "content")] - pub content: serde_json::Map, + pub content: Content, #[serde(rename = "id")] pub id: String, - #[serde(rename = "source")] - pub source: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, #[serde(rename = "type")] - pub tpe: String, + pub r#type: String, } + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { + #[serde(rename = "format")] + pub format: String, + #[serde(rename = "outputType")] + pub output_type: String, + #[serde(rename = "testCaseRun", skip_serializing_if = "Option::is_none")] + pub test_case_run: Option, + #[serde(rename = "uri", skip_serializing_if = "Option::is_none")] + pub uri: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct TestCaseRun { + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, +} + diff --git a/cdevents-sdk/src/generated/test_suite_finished_subject.rs b/cdevents-sdk/src/generated/test_suite_finished_subject.rs index 08281b1..cae6ee1 100644 --- a/cdevents-sdk/src/generated/test_suite_finished_subject.rs +++ b/cdevents-sdk/src/generated/test_suite_finished_subject.rs @@ -1,15 +1,49 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct TestSuiteFinishedSubject { - +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Subject { #[serde(rename = "content")] - pub content: serde_json::Map, + pub content: Content, #[serde(rename = "id")] pub id: String, - #[serde(rename = "source")] - pub source: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, #[serde(rename = "type")] - pub tpe: String, + pub r#type: String, } + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { + #[serde(rename = "environment")] + pub environment: Environment, + #[serde(rename = "outcome")] + pub outcome: String, + #[serde(rename = "reason", skip_serializing_if = "Option::is_none")] + pub reason: Option, + #[serde(rename = "severity", skip_serializing_if = "Option::is_none")] + pub severity: Option, + #[serde(rename = "testSuite", skip_serializing_if = "Option::is_none")] + pub test_suite: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct TestSuite { + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "name", skip_serializing_if = "Option::is_none")] + pub name: Option, + #[serde(rename = "uri", skip_serializing_if = "Option::is_none")] + pub uri: Option, + #[serde(rename = "version", skip_serializing_if = "Option::is_none")] + pub version: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Environment { + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, +} + diff --git a/cdevents-sdk/src/generated/test_suite_run_queued_subject.rs b/cdevents-sdk/src/generated/test_suite_run_queued_subject.rs index 2ed190f..a2a20f7 100644 --- a/cdevents-sdk/src/generated/test_suite_run_queued_subject.rs +++ b/cdevents-sdk/src/generated/test_suite_run_queued_subject.rs @@ -1,15 +1,53 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct TestSuiteRunQueuedSubject { - +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Subject { #[serde(rename = "content")] - pub content: serde_json::Map, + pub content: Content, #[serde(rename = "id")] pub id: String, - #[serde(rename = "source")] - pub source: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, #[serde(rename = "type")] - pub tpe: String, + pub r#type: String, } + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { + #[serde(rename = "environment")] + pub environment: Environment, + #[serde(rename = "testSuite", skip_serializing_if = "Option::is_none")] + pub test_suite: Option, + #[serde(rename = "trigger", skip_serializing_if = "Option::is_none")] + pub trigger: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Trigger { + #[serde(rename = "type", skip_serializing_if = "Option::is_none")] + pub r#type: Option, + #[serde(rename = "uri", skip_serializing_if = "Option::is_none")] + pub uri: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct TestSuite { + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "name", skip_serializing_if = "Option::is_none")] + pub name: Option, + #[serde(rename = "url", skip_serializing_if = "Option::is_none")] + pub url: Option, + #[serde(rename = "version", skip_serializing_if = "Option::is_none")] + pub version: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Environment { + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, +} + diff --git a/cdevents-sdk/src/generated/test_suite_run_started_subject.rs b/cdevents-sdk/src/generated/test_suite_run_started_subject.rs index 2e2d386..ac0d61a 100644 --- a/cdevents-sdk/src/generated/test_suite_run_started_subject.rs +++ b/cdevents-sdk/src/generated/test_suite_run_started_subject.rs @@ -1,15 +1,53 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct TestSuiteRunStartedSubject { - +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Subject { #[serde(rename = "content")] - pub content: serde_json::Map, + pub content: Content, #[serde(rename = "id")] pub id: String, - #[serde(rename = "source")] - pub source: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, #[serde(rename = "type")] - pub tpe: String, + pub r#type: String, } + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { + #[serde(rename = "environment")] + pub environment: Environment, + #[serde(rename = "testSuite", skip_serializing_if = "Option::is_none")] + pub test_suite: Option, + #[serde(rename = "trigger", skip_serializing_if = "Option::is_none")] + pub trigger: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Trigger { + #[serde(rename = "type", skip_serializing_if = "Option::is_none")] + pub r#type: Option, + #[serde(rename = "uri", skip_serializing_if = "Option::is_none")] + pub uri: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct TestSuite { + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "name", skip_serializing_if = "Option::is_none")] + pub name: Option, + #[serde(rename = "uri", skip_serializing_if = "Option::is_none")] + pub uri: Option, + #[serde(rename = "version", skip_serializing_if = "Option::is_none")] + pub version: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Environment { + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, +} + diff --git a/cdevents-sdk/src/lib.rs b/cdevents-sdk/src/lib.rs index 3040b41..ddb6cae 100644 --- a/cdevents-sdk/src/lib.rs +++ b/cdevents-sdk/src/lib.rs @@ -1,9 +1,13 @@ mod generated; pub use generated::*; -use serde::{Deserialize, Serialize}; +use serde::{ + de::{self, Deserializer, MapAccess, Visitor}, + Deserialize, Serialize, +}; +use std::fmt; -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, PartialEq, Eq)] pub struct CDEvent { pub context: Context, pub subject: Subject, @@ -16,18 +20,129 @@ pub struct CDEvent { pub custom_data_content_type: Option, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] pub struct Context { version: String, id: String, #[serde(with = "http_serde::uri")] source: http::Uri, #[serde(rename = "type")] - tpe: String, + r#type: String, #[serde(with = "time::serde::rfc3339")] timestamp: time::OffsetDateTime, } +impl<'de> Deserialize<'de> for CDEvent { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + enum Field { + Context, + Subject, + CustomData, + CustomDataContentType, + } + + // This part could also be generated independently by: + // + // #[derive(Deserialize)] + // #[serde(field_identifier, rename_all = "lowercase")] + // enum Field { { Context, Subject, CustomData, CustomDataContentType } } + impl<'de> Deserialize<'de> for Field { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct FieldVisitor; + + impl<'de> Visitor<'de> for FieldVisitor { + type Value = Field; + + fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + formatter.write_str("`context` and `subject`") + } + + fn visit_str(self, value: &str) -> Result + where + E: de::Error, + { + match value { + "context" => Ok(Field::Context), + "subject" => Ok(Field::Subject), + "customData" => Ok(Field::CustomData), + "customDataContentType" => Ok(Field::CustomDataContentType), + _ => Err(de::Error::unknown_field(value, FIELDS)), + } + } + } + + deserializer.deserialize_identifier(FieldVisitor) + } + } + + struct CDEventVisitor; + + impl<'de> Visitor<'de> for CDEventVisitor { + type Value = CDEvent; + + fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + formatter.write_str("struct CDEvent") + } + + fn visit_map(self, mut map: V) -> Result + where + V: MapAccess<'de>, + { + let mut context: Option = None; + let mut subject_json: Option = None; + let mut custom_data = None; + let mut custom_data_content_type = None; + while let Some(key) = map.next_key()? { + match key { + Field::Context => { + if context.is_some() { + return Err(de::Error::duplicate_field("context")); + } + context = Some(map.next_value()?); + } + Field::Subject => { + if subject_json.is_some() { + return Err(de::Error::duplicate_field("subject")); + } + subject_json = Some(map.next_value()?); + } + Field::CustomData => { + if custom_data.is_some() { + return Err(de::Error::duplicate_field("customData")); + } + custom_data = Some(map.next_value()?); + } + Field::CustomDataContentType => { + if custom_data_content_type.is_some() { + return Err(de::Error::duplicate_field("customDataContentType")); + } + custom_data_content_type = Some(map.next_value()?); + } + } + } + let context = context.ok_or_else(|| de::Error::missing_field("context"))?; + let subject = Subject::from_json(&context.r#type, subject_json.unwrap()); + //let subject = subject.ok_or_else(|| de::Error::missing_field("subject"))?; + Ok(CDEvent { + context, + subject, + custom_data, + custom_data_content_type, + }) + } + } + + const FIELDS: &'static [&'static str] = &["context", "subject"]; + deserializer.deserialize_struct("CDEvent", FIELDS, CDEventVisitor) + } +} + #[cfg(test)] mod tests { use super::*; @@ -44,9 +159,16 @@ mod tests { .as_str(), ) .expect("to parse as json"); + dbg!(&example_json); let cdevent: CDEvent = serde_json::from_value(example_json.clone()).expect("to parse as cdevent"); + // let cdevent: CDEvent = + // deserialize::(example_json.clone()) + // .expect("to parse as cdevent"); + + dbg!(&cdevent); let cdevent_json = serde_json::to_value(cdevent).expect("to convert into json"); + dbg!(&cdevent_json); assert_json_eq!(example_json, cdevent_json); } } diff --git a/generator/Cargo.toml b/generator/Cargo.toml index 831dc1e..f2b8cf3 100644 --- a/generator/Cargo.toml +++ b/generator/Cargo.toml @@ -14,7 +14,8 @@ anyhow = "1.0" clap = { version = "4", features = ["derive"] } cruet = "0.14" handlebars = { version = "5", features = ["dir_source"] } -serde_json = "*" +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" url = "2.5" handlebars_misc_helpers = { version = "0.15", default-features = false, features = [ "string", diff --git a/generator/README.md b/generator/README.md index 9a1b3ee..6938a84 100644 --- a/generator/README.md +++ b/generator/README.md @@ -17,6 +17,5 @@ To generate the `subjects` into sibling crate `cdevents/src/generated` from cont ```sh cargo run -p generator -- --help -cargo run -p generator -- --templates-dir "generator/templates" --jsonschema-dir "cdevents-spec/schemas" --dest -"cdevents/src/generated" +cargo run -p generator -- --templates-dir "generator/templates" --jsonschema-dir "cdevents-spec/schemas" --dest "cdevents-sdk/src/generated" ``` \ No newline at end of file diff --git a/generator/src/main.rs b/generator/src/main.rs index 4d16dbb..40d75d1 100644 --- a/generator/src/main.rs +++ b/generator/src/main.rs @@ -1,6 +1,8 @@ use anyhow::{anyhow, Context, Result}; use clap::Parser; -use handlebars::{handlebars_helper, DirectorySourceOptions, Handlebars}; +use cruet::{to_class_case, Inflector}; +use handlebars::{DirectorySourceOptions, Handlebars}; +use serde::{Deserialize, Serialize}; use serde_json::{json, Value}; use std::{fs, path::PathBuf}; @@ -27,8 +29,6 @@ fn main() -> Result<()> { hbs.set_strict_mode(true); hbs.register_escape_fn(handlebars::no_escape); //hbs.unregister_escape_fn(); - hbs.register_helper("type_of", Box::new(type_of)); - hbs.register_helper("normalize_ident", Box::new(normalize_ident)); handlebars_misc_helpers::register(&mut hbs); hbs.register_templates_directory(settings.templates_dir, DirectorySourceOptions::default())?; @@ -42,25 +42,29 @@ fn main() -> Result<()> { let path = entry.path(); if let Some(extension) = path.extension() { if extension == "json" { - let json = serde_json::from_str(&std::fs::read_to_string(&path)?)?; - let (type_name, code) = generate_subject(&hbs, json) + let json: Value = serde_json::from_str(&std::fs::read_to_string(&path)?)?; + let context_type = json["properties"]["context"]["properties"]["type"]["default"] + .as_str() + .unwrap_or_default() + .to_string(); + let (rust_module, code) = generate_subject(&hbs, json) .with_context(|| format!("failed to generate subject on {:?}", &path))?; let file = settings .dest - .join(cruet::to_snake_case(&type_name)) + .join(cruet::to_snake_case(&rust_module)) .with_extension("rs"); fs::write(file, code)?; - subjects.push(type_name); + subjects.push(SubjectInfo { + context_type, + rust_module, + }); } } } - let (type_name, code) = + let (module_name, code) = generate_module(&hbs, &subjects).with_context(|| "failed to generate module")?; - let file = settings - .dest - .join(cruet::to_snake_case(&type_name)) - .with_extension("rs"); + let file = settings.dest.join(&module_name).with_extension("rs"); fs::write(file, code)?; Ok(()) @@ -71,24 +75,19 @@ fn generate_subject(hbs: &Handlebars, jsonschema: Value) -> Result<(String, Stri .as_str() .ok_or(anyhow!("$id not found or not a string")) .and_then(|s| url::Url::parse(s).with_context(|| format!("failed to parse: {}", s)))?; - let type_name = id + let module_name = id .path_segments() .and_then(|v| v.last()) - .map(cruet::to_class_case) + .map(cruet::to_snake_case) .ok_or(anyhow!("no path in $id"))? - .replace("Event", "Subject"); - let mut data = jsonschema.clone(); - data.as_object_mut().and_then(|m| { - m.insert( - "type_name".to_string(), - serde_json::to_value(&type_name).unwrap(), - ) - }); + .replace("_event", "_subject"); + + let data = build_data_for_subjects(jsonschema); let code = hbs.render("subject", &data)?; - Ok((type_name.to_string(), code)) + Ok((module_name.to_string(), code)) } -fn generate_module(hbs: &Handlebars, subjects: &[String]) -> Result<(String, String)> { +fn generate_module(hbs: &Handlebars, subjects: &[SubjectInfo]) -> Result<(String, String)> { let data = json!({ "subjects": subjects }); @@ -96,24 +95,89 @@ fn generate_module(hbs: &Handlebars, subjects: &[String]) -> Result<(String, Str Ok(("mod".to_string(), code)) } -//TODO helper to convert into type -//TODO helper to check if optionnal -handlebars_helper!(type_of: |field_name: Value, def: Value, required: Value| { - let mut t = match def["type"].as_str() { - Some("string") => "String", - Some("object") => "serde_json::Map", - x => todo!("impl type {:?}", x), - }.to_string(); - if required.as_array().map(|a| a.contains(&field_name)).unwrap_or(false) { - t = format!("Option<{}>", t); - } - t -}); - -handlebars_helper!(normalize_ident: |v: Value| { - match v.as_str() { - Some("type") => "tpe", - Some(x) => x, - None => unimplemented!(), +fn build_data_for_subjects(jsonschema: Value) -> Value { + let mut structs = vec![]; + collect_structs( + &mut structs, + "subject", + &jsonschema["properties"]["subject"], + ); + structs.reverse(); + + json!({ + "structs": structs, + "jsonschema": jsonschema, + }) +} + +type RustTypeName = String; + +#[derive(Debug, Clone, Serialize, Deserialize)] +struct SubjectInfo { + context_type: String, + rust_module: String, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +struct StructDef { + type_name: RustTypeName, + json_definition: Value, + fields: Vec, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +struct FieldDef { + rust_name: String, + serde_name: String, + type_name: RustTypeName, + is_optional: bool, +} + +fn collect_structs( + structs: &mut Vec, + field_name: &str, + json_definition: &Value, +) -> RustTypeName { + match json_definition["type"].as_str() { + Some("string") => "String".to_string(), + Some("object") => match json_definition["properties"].as_object() { + None => "serde_json::Map".to_string(), + Some(fields_kv) => { + let required = json_definition["required"].as_array(); + let fields = fields_kv + .into_iter() + .map(|field| { + let serde_name = field.0.to_string(); + let rust_name = if serde_name == "type" { + "r#type".to_string() + } else { + serde_name.to_snake_case() + }; + let mut type_name = collect_structs(structs, &serde_name, field.1); + let field_name = json!(&serde_name); + let is_optional = + required.map(|a| !a.contains(&field_name)).unwrap_or(true); + if is_optional { + type_name = format!("Option<{}>", type_name); + } + FieldDef { + rust_name, + serde_name, + type_name, + is_optional, + } + }) + .collect::>(); + let type_name = to_class_case(field_name); + structs.push(StructDef { + type_name: type_name.clone(), + fields, + json_definition: json_definition.clone(), + }); + type_name + } + }, + Some(x) => todo!("impl for type='{}'", x), + None => unimplemented!("expected key 'type' in field '{}'", field_name), } -}); +} diff --git a/generator/templates/mod.hbs b/generator/templates/mod.hbs index 2df24c6..4f0feea 100644 --- a/generator/templates/mod.hbs +++ b/generator/templates/mod.hbs @@ -1,14 +1,28 @@ // code generated by cdevents/sdk-rust/generator (mod.hbs) {{#each subjects }} -mod {{to_snake_case this}}; +pub mod {{this.rust_module}}; {{/each}} use serde::{Serialize, Deserialize}; -#[derive(Debug,Clone,Serialize,Deserialize)] +#[derive(Debug,Clone,Serialize,Deserialize, PartialEq, Eq)] #[serde(untagged)] // TODO how to use content of context.type as discriminator ? pub enum Subject { {{#each subjects }} - {{this}}({{to_snake_case this}}::{{this}}), + {{to_class_case this.rust_module}}({{this.rust_module}}::Subject), {{/each}} } + +impl Subject { + pub fn from_json(ty: &str, json: serde_json::Value) -> Self{ + match ty { + {{#each subjects }} + "{{ this.context_type }}" => { + let subject: {{this.rust_module}}::Subject = serde_json::from_value(json).unwrap(); + Self::{{to_class_case this.rust_module}}(subject) + }, + {{/each}} + x => todo!("no implementation for type '{}', please open an issue", x), + } + } +} \ No newline at end of file diff --git a/generator/templates/subject.hbs b/generator/templates/subject.hbs index b66e4a2..6854e7d 100644 --- a/generator/templates/subject.hbs +++ b/generator/templates/subject.hbs @@ -1,11 +1,13 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct {{ type_name }} { - {{assign "required" properties.subject.required }} - {{#each properties.subject.properties }} - #[serde(rename = "{{ @key }}")] - pub {{normalize_ident @key }}: {{type_of @key this required }}, +{{#each structs }} +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct {{ this.type_name }} { + {{#each this.fields }} + #[serde(rename = "{{ this.serde_name }}"{{#if this.is_optional }}, skip_serializing_if = "Option::is_none"{{/if}})] + pub {{ this.rust_name }}: {{this.type_name }}, {{/each}} } + +{{/each}} \ No newline at end of file From f727547b25d3c83c0c0b174a49eb11650c66efd4 Mon Sep 17 00:00:00 2001 From: David Bernard Date: Sun, 14 Jan 2024 13:04:41 +0100 Subject: [PATCH 06/34] feat: use the same Subject struct for every event and an enum on Content Signed-off-by: David Bernard --- ...queued_subject.rs => artifact_packaged.rs} | 16 +- .../generated/artifact_packaged_subject.rs | 29 -- .../src/generated/artifact_published.rs | 7 + cdevents-sdk/src/generated/artifact_signed.rs | 9 + ...d_started_subject.rs => branch_created.rs} | 16 +- .../src/generated/branch_created_subject.rs | 29 -- ...published_subject.rs => branch_deleted.rs} | 16 +- .../src/generated/branch_deleted_subject.rs | 29 -- cdevents-sdk/src/generated/build_finished.rs | 9 + .../src/generated/build_finished_subject.rs | 21 - cdevents-sdk/src/generated/build_queued.rs | 7 + cdevents-sdk/src/generated/build_started.rs | 7 + ..._signed_subject.rs => change_abandoned.rs} | 18 +- .../src/generated/change_abandoned_subject.rs | 29 -- cdevents-sdk/src/generated/change_created.rs | 17 + .../src/generated/change_created_subject.rs | 29 -- cdevents-sdk/src/generated/change_merged.rs | 17 + .../src/generated/change_merged_subject.rs | 29 -- cdevents-sdk/src/generated/change_reviewed.rs | 17 + .../src/generated/change_reviewed_subject.rs | 29 -- cdevents-sdk/src/generated/change_updated.rs | 17 + .../src/generated/change_updated_subject.rs | 29 -- ...fied_subject.rs => environment_created.rs} | 12 - .../src/generated/environment_deleted.rs | 9 + .../generated/environment_deleted_subject.rs | 21 - ...ted_subject.rs => environment_modified.rs} | 12 - ...tected_subject.rs => incident_detected.rs} | 12 - ...ported_subject.rs => incident_reported.rs} | 12 - ...solved_subject.rs => incident_resolved.rs} | 12 - cdevents-sdk/src/generated/mod.rs | 468 ++++++++++-------- ...ed_subject.rs => pipeline_run_finished.rs} | 16 +- .../src/generated/pipeline_run_queued.rs | 11 + .../src/generated/pipeline_run_started.rs | 11 + .../generated/pipeline_run_started_subject.rs | 23 - ...eated_subject.rs => repository_created.rs} | 12 - ...leted_subject.rs => repository_deleted.rs} | 12 - ...fied_subject.rs => repository_modified.rs} | 12 - .../src/generated/service_deployed.rs | 19 + .../src/generated/service_deployed_subject.rs | 31 -- .../src/generated/service_published.rs | 17 + .../generated/service_published_subject.rs | 29 -- cdevents-sdk/src/generated/service_removed.rs | 17 + .../src/generated/service_removed_subject.rs | 29 -- .../src/generated/service_rolledback.rs | 19 + .../generated/service_rolledback_subject.rs | 31 -- .../src/generated/service_upgraded.rs | 19 + .../src/generated/service_upgraded_subject.rs | 31 -- ...nished_subject.rs => task_run_finished.rs} | 26 +- .../generated/task_run_finished_subject.rs | 37 -- ...started_subject.rs => task_run_started.rs} | 12 - ...d_subject.rs => test_case_run_finished.rs} | 12 - ...ued_subject.rs => test_case_run_queued.rs} | 12 - ...ed_subject.rs => test_case_run_started.rs} | 12 - ...ed_subject.rs => test_output_published.rs} | 12 - ...shed_subject.rs => test_suite_finished.rs} | 12 - ...ed_subject.rs => test_suite_run_queued.rs} | 12 - ...d_subject.rs => test_suite_run_started.rs} | 12 - cdevents-sdk/src/lib.rs | 105 ++-- generator/src/main.rs | 33 +- generator/templates/mod.hbs | 34 +- .../templates/{subject.hbs => variant.hbs} | 0 61 files changed, 620 insertions(+), 1034 deletions(-) rename cdevents-sdk/src/generated/{build_queued_subject.rs => artifact_packaged.rs} (75%) delete mode 100644 cdevents-sdk/src/generated/artifact_packaged_subject.rs create mode 100644 cdevents-sdk/src/generated/artifact_published.rs create mode 100644 cdevents-sdk/src/generated/artifact_signed.rs rename cdevents-sdk/src/generated/{build_started_subject.rs => branch_created.rs} (74%) delete mode 100644 cdevents-sdk/src/generated/branch_created_subject.rs rename cdevents-sdk/src/generated/{artifact_published_subject.rs => branch_deleted.rs} (74%) delete mode 100644 cdevents-sdk/src/generated/branch_deleted_subject.rs create mode 100644 cdevents-sdk/src/generated/build_finished.rs delete mode 100644 cdevents-sdk/src/generated/build_finished_subject.rs create mode 100644 cdevents-sdk/src/generated/build_queued.rs create mode 100644 cdevents-sdk/src/generated/build_started.rs rename cdevents-sdk/src/generated/{artifact_signed_subject.rs => change_abandoned.rs} (67%) delete mode 100644 cdevents-sdk/src/generated/change_abandoned_subject.rs create mode 100644 cdevents-sdk/src/generated/change_created.rs delete mode 100644 cdevents-sdk/src/generated/change_created_subject.rs create mode 100644 cdevents-sdk/src/generated/change_merged.rs delete mode 100644 cdevents-sdk/src/generated/change_merged_subject.rs create mode 100644 cdevents-sdk/src/generated/change_reviewed.rs delete mode 100644 cdevents-sdk/src/generated/change_reviewed_subject.rs create mode 100644 cdevents-sdk/src/generated/change_updated.rs delete mode 100644 cdevents-sdk/src/generated/change_updated_subject.rs rename cdevents-sdk/src/generated/{environment_modified_subject.rs => environment_created.rs} (52%) create mode 100644 cdevents-sdk/src/generated/environment_deleted.rs delete mode 100644 cdevents-sdk/src/generated/environment_deleted_subject.rs rename cdevents-sdk/src/generated/{environment_created_subject.rs => environment_modified.rs} (52%) rename cdevents-sdk/src/generated/{incident_detected_subject.rs => incident_detected.rs} (75%) rename cdevents-sdk/src/generated/{incident_reported_subject.rs => incident_reported.rs} (76%) rename cdevents-sdk/src/generated/{incident_resolved_subject.rs => incident_resolved.rs} (75%) rename cdevents-sdk/src/generated/{pipeline_run_queued_subject.rs => pipeline_run_finished.rs} (54%) create mode 100644 cdevents-sdk/src/generated/pipeline_run_queued.rs create mode 100644 cdevents-sdk/src/generated/pipeline_run_started.rs delete mode 100644 cdevents-sdk/src/generated/pipeline_run_started_subject.rs rename cdevents-sdk/src/generated/{repository_created_subject.rs => repository_created.rs} (58%) rename cdevents-sdk/src/generated/{repository_deleted_subject.rs => repository_deleted.rs} (62%) rename cdevents-sdk/src/generated/{repository_modified_subject.rs => repository_modified.rs} (62%) create mode 100644 cdevents-sdk/src/generated/service_deployed.rs delete mode 100644 cdevents-sdk/src/generated/service_deployed_subject.rs create mode 100644 cdevents-sdk/src/generated/service_published.rs delete mode 100644 cdevents-sdk/src/generated/service_published_subject.rs create mode 100644 cdevents-sdk/src/generated/service_removed.rs delete mode 100644 cdevents-sdk/src/generated/service_removed_subject.rs create mode 100644 cdevents-sdk/src/generated/service_rolledback.rs delete mode 100644 cdevents-sdk/src/generated/service_rolledback_subject.rs create mode 100644 cdevents-sdk/src/generated/service_upgraded.rs delete mode 100644 cdevents-sdk/src/generated/service_upgraded_subject.rs rename cdevents-sdk/src/generated/{pipeline_run_finished_subject.rs => task_run_finished.rs} (73%) delete mode 100644 cdevents-sdk/src/generated/task_run_finished_subject.rs rename cdevents-sdk/src/generated/{task_run_started_subject.rs => task_run_started.rs} (68%) rename cdevents-sdk/src/generated/{test_case_run_finished_subject.rs => test_case_run_finished.rs} (83%) rename cdevents-sdk/src/generated/{test_case_run_queued_subject.rs => test_case_run_queued.rs} (84%) rename cdevents-sdk/src/generated/{test_case_run_started_subject.rs => test_case_run_started.rs} (84%) rename cdevents-sdk/src/generated/{test_output_published_subject.rs => test_output_published.rs} (68%) rename cdevents-sdk/src/generated/{test_suite_finished_subject.rs => test_suite_finished.rs} (79%) rename cdevents-sdk/src/generated/{test_suite_run_queued_subject.rs => test_suite_run_queued.rs} (80%) rename cdevents-sdk/src/generated/{test_suite_run_started_subject.rs => test_suite_run_started.rs} (80%) rename generator/templates/{subject.hbs => variant.hbs} (100%) diff --git a/cdevents-sdk/src/generated/build_queued_subject.rs b/cdevents-sdk/src/generated/artifact_packaged.rs similarity index 75% rename from cdevents-sdk/src/generated/build_queued_subject.rs rename to cdevents-sdk/src/generated/artifact_packaged.rs index 8504d81..460a266 100644 --- a/cdevents-sdk/src/generated/build_queued_subject.rs +++ b/cdevents-sdk/src/generated/artifact_packaged.rs @@ -2,18 +2,16 @@ use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Subject { - #[serde(rename = "content")] - pub content: Content, +pub struct Content { + #[serde(rename = "change")] + pub change: Change, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Change { #[serde(rename = "id")] pub id: String, #[serde(rename = "source", skip_serializing_if = "Option::is_none")] pub source: Option, - #[serde(rename = "type")] - pub r#type: String, -} - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Content { } diff --git a/cdevents-sdk/src/generated/artifact_packaged_subject.rs b/cdevents-sdk/src/generated/artifact_packaged_subject.rs deleted file mode 100644 index 37b4210..0000000 --- a/cdevents-sdk/src/generated/artifact_packaged_subject.rs +++ /dev/null @@ -1,29 +0,0 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) -use serde::{Serialize, Deserialize}; - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Subject { - #[serde(rename = "content")] - pub content: Content, - #[serde(rename = "id")] - pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, - #[serde(rename = "type")] - pub r#type: String, -} - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Content { - #[serde(rename = "change")] - pub change: Change, -} - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Change { - #[serde(rename = "id")] - pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, -} - diff --git a/cdevents-sdk/src/generated/artifact_published.rs b/cdevents-sdk/src/generated/artifact_published.rs new file mode 100644 index 0000000..4367d0a --- /dev/null +++ b/cdevents-sdk/src/generated/artifact_published.rs @@ -0,0 +1,7 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { +} + diff --git a/cdevents-sdk/src/generated/artifact_signed.rs b/cdevents-sdk/src/generated/artifact_signed.rs new file mode 100644 index 0000000..0876c99 --- /dev/null +++ b/cdevents-sdk/src/generated/artifact_signed.rs @@ -0,0 +1,9 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { + #[serde(rename = "signature")] + pub signature: String, +} + diff --git a/cdevents-sdk/src/generated/build_started_subject.rs b/cdevents-sdk/src/generated/branch_created.rs similarity index 74% rename from cdevents-sdk/src/generated/build_started_subject.rs rename to cdevents-sdk/src/generated/branch_created.rs index 8504d81..6a21b4d 100644 --- a/cdevents-sdk/src/generated/build_started_subject.rs +++ b/cdevents-sdk/src/generated/branch_created.rs @@ -2,18 +2,16 @@ use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Subject { - #[serde(rename = "content")] - pub content: Content, +pub struct Content { + #[serde(rename = "repository", skip_serializing_if = "Option::is_none")] + pub repository: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Repository { #[serde(rename = "id")] pub id: String, #[serde(rename = "source", skip_serializing_if = "Option::is_none")] pub source: Option, - #[serde(rename = "type")] - pub r#type: String, -} - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Content { } diff --git a/cdevents-sdk/src/generated/branch_created_subject.rs b/cdevents-sdk/src/generated/branch_created_subject.rs deleted file mode 100644 index 20f7b4d..0000000 --- a/cdevents-sdk/src/generated/branch_created_subject.rs +++ /dev/null @@ -1,29 +0,0 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) -use serde::{Serialize, Deserialize}; - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Subject { - #[serde(rename = "content")] - pub content: Content, - #[serde(rename = "id")] - pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, - #[serde(rename = "type")] - pub r#type: String, -} - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Content { - #[serde(rename = "repository", skip_serializing_if = "Option::is_none")] - pub repository: Option, -} - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Repository { - #[serde(rename = "id")] - pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, -} - diff --git a/cdevents-sdk/src/generated/artifact_published_subject.rs b/cdevents-sdk/src/generated/branch_deleted.rs similarity index 74% rename from cdevents-sdk/src/generated/artifact_published_subject.rs rename to cdevents-sdk/src/generated/branch_deleted.rs index 8504d81..6a21b4d 100644 --- a/cdevents-sdk/src/generated/artifact_published_subject.rs +++ b/cdevents-sdk/src/generated/branch_deleted.rs @@ -2,18 +2,16 @@ use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Subject { - #[serde(rename = "content")] - pub content: Content, +pub struct Content { + #[serde(rename = "repository", skip_serializing_if = "Option::is_none")] + pub repository: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Repository { #[serde(rename = "id")] pub id: String, #[serde(rename = "source", skip_serializing_if = "Option::is_none")] pub source: Option, - #[serde(rename = "type")] - pub r#type: String, -} - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Content { } diff --git a/cdevents-sdk/src/generated/branch_deleted_subject.rs b/cdevents-sdk/src/generated/branch_deleted_subject.rs deleted file mode 100644 index 20f7b4d..0000000 --- a/cdevents-sdk/src/generated/branch_deleted_subject.rs +++ /dev/null @@ -1,29 +0,0 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) -use serde::{Serialize, Deserialize}; - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Subject { - #[serde(rename = "content")] - pub content: Content, - #[serde(rename = "id")] - pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, - #[serde(rename = "type")] - pub r#type: String, -} - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Content { - #[serde(rename = "repository", skip_serializing_if = "Option::is_none")] - pub repository: Option, -} - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Repository { - #[serde(rename = "id")] - pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, -} - diff --git a/cdevents-sdk/src/generated/build_finished.rs b/cdevents-sdk/src/generated/build_finished.rs new file mode 100644 index 0000000..6a27785 --- /dev/null +++ b/cdevents-sdk/src/generated/build_finished.rs @@ -0,0 +1,9 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { + #[serde(rename = "artifactId", skip_serializing_if = "Option::is_none")] + pub artifact_id: Option, +} + diff --git a/cdevents-sdk/src/generated/build_finished_subject.rs b/cdevents-sdk/src/generated/build_finished_subject.rs deleted file mode 100644 index 861d935..0000000 --- a/cdevents-sdk/src/generated/build_finished_subject.rs +++ /dev/null @@ -1,21 +0,0 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) -use serde::{Serialize, Deserialize}; - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Subject { - #[serde(rename = "content")] - pub content: Content, - #[serde(rename = "id")] - pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, - #[serde(rename = "type")] - pub r#type: String, -} - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Content { - #[serde(rename = "artifactId", skip_serializing_if = "Option::is_none")] - pub artifact_id: Option, -} - diff --git a/cdevents-sdk/src/generated/build_queued.rs b/cdevents-sdk/src/generated/build_queued.rs new file mode 100644 index 0000000..4367d0a --- /dev/null +++ b/cdevents-sdk/src/generated/build_queued.rs @@ -0,0 +1,7 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { +} + diff --git a/cdevents-sdk/src/generated/build_started.rs b/cdevents-sdk/src/generated/build_started.rs new file mode 100644 index 0000000..4367d0a --- /dev/null +++ b/cdevents-sdk/src/generated/build_started.rs @@ -0,0 +1,7 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { +} + diff --git a/cdevents-sdk/src/generated/artifact_signed_subject.rs b/cdevents-sdk/src/generated/change_abandoned.rs similarity index 67% rename from cdevents-sdk/src/generated/artifact_signed_subject.rs rename to cdevents-sdk/src/generated/change_abandoned.rs index 9984005..6a21b4d 100644 --- a/cdevents-sdk/src/generated/artifact_signed_subject.rs +++ b/cdevents-sdk/src/generated/change_abandoned.rs @@ -2,20 +2,16 @@ use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Subject { - #[serde(rename = "content")] - pub content: Content, +pub struct Content { + #[serde(rename = "repository", skip_serializing_if = "Option::is_none")] + pub repository: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Repository { #[serde(rename = "id")] pub id: String, #[serde(rename = "source", skip_serializing_if = "Option::is_none")] pub source: Option, - #[serde(rename = "type")] - pub r#type: String, -} - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Content { - #[serde(rename = "signature")] - pub signature: String, } diff --git a/cdevents-sdk/src/generated/change_abandoned_subject.rs b/cdevents-sdk/src/generated/change_abandoned_subject.rs deleted file mode 100644 index 20f7b4d..0000000 --- a/cdevents-sdk/src/generated/change_abandoned_subject.rs +++ /dev/null @@ -1,29 +0,0 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) -use serde::{Serialize, Deserialize}; - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Subject { - #[serde(rename = "content")] - pub content: Content, - #[serde(rename = "id")] - pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, - #[serde(rename = "type")] - pub r#type: String, -} - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Content { - #[serde(rename = "repository", skip_serializing_if = "Option::is_none")] - pub repository: Option, -} - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Repository { - #[serde(rename = "id")] - pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, -} - diff --git a/cdevents-sdk/src/generated/change_created.rs b/cdevents-sdk/src/generated/change_created.rs new file mode 100644 index 0000000..6a21b4d --- /dev/null +++ b/cdevents-sdk/src/generated/change_created.rs @@ -0,0 +1,17 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { + #[serde(rename = "repository", skip_serializing_if = "Option::is_none")] + pub repository: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Repository { + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, +} + diff --git a/cdevents-sdk/src/generated/change_created_subject.rs b/cdevents-sdk/src/generated/change_created_subject.rs deleted file mode 100644 index 20f7b4d..0000000 --- a/cdevents-sdk/src/generated/change_created_subject.rs +++ /dev/null @@ -1,29 +0,0 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) -use serde::{Serialize, Deserialize}; - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Subject { - #[serde(rename = "content")] - pub content: Content, - #[serde(rename = "id")] - pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, - #[serde(rename = "type")] - pub r#type: String, -} - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Content { - #[serde(rename = "repository", skip_serializing_if = "Option::is_none")] - pub repository: Option, -} - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Repository { - #[serde(rename = "id")] - pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, -} - diff --git a/cdevents-sdk/src/generated/change_merged.rs b/cdevents-sdk/src/generated/change_merged.rs new file mode 100644 index 0000000..6a21b4d --- /dev/null +++ b/cdevents-sdk/src/generated/change_merged.rs @@ -0,0 +1,17 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { + #[serde(rename = "repository", skip_serializing_if = "Option::is_none")] + pub repository: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Repository { + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, +} + diff --git a/cdevents-sdk/src/generated/change_merged_subject.rs b/cdevents-sdk/src/generated/change_merged_subject.rs deleted file mode 100644 index 20f7b4d..0000000 --- a/cdevents-sdk/src/generated/change_merged_subject.rs +++ /dev/null @@ -1,29 +0,0 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) -use serde::{Serialize, Deserialize}; - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Subject { - #[serde(rename = "content")] - pub content: Content, - #[serde(rename = "id")] - pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, - #[serde(rename = "type")] - pub r#type: String, -} - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Content { - #[serde(rename = "repository", skip_serializing_if = "Option::is_none")] - pub repository: Option, -} - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Repository { - #[serde(rename = "id")] - pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, -} - diff --git a/cdevents-sdk/src/generated/change_reviewed.rs b/cdevents-sdk/src/generated/change_reviewed.rs new file mode 100644 index 0000000..6a21b4d --- /dev/null +++ b/cdevents-sdk/src/generated/change_reviewed.rs @@ -0,0 +1,17 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { + #[serde(rename = "repository", skip_serializing_if = "Option::is_none")] + pub repository: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Repository { + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, +} + diff --git a/cdevents-sdk/src/generated/change_reviewed_subject.rs b/cdevents-sdk/src/generated/change_reviewed_subject.rs deleted file mode 100644 index 20f7b4d..0000000 --- a/cdevents-sdk/src/generated/change_reviewed_subject.rs +++ /dev/null @@ -1,29 +0,0 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) -use serde::{Serialize, Deserialize}; - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Subject { - #[serde(rename = "content")] - pub content: Content, - #[serde(rename = "id")] - pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, - #[serde(rename = "type")] - pub r#type: String, -} - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Content { - #[serde(rename = "repository", skip_serializing_if = "Option::is_none")] - pub repository: Option, -} - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Repository { - #[serde(rename = "id")] - pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, -} - diff --git a/cdevents-sdk/src/generated/change_updated.rs b/cdevents-sdk/src/generated/change_updated.rs new file mode 100644 index 0000000..6a21b4d --- /dev/null +++ b/cdevents-sdk/src/generated/change_updated.rs @@ -0,0 +1,17 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { + #[serde(rename = "repository", skip_serializing_if = "Option::is_none")] + pub repository: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Repository { + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, +} + diff --git a/cdevents-sdk/src/generated/change_updated_subject.rs b/cdevents-sdk/src/generated/change_updated_subject.rs deleted file mode 100644 index 20f7b4d..0000000 --- a/cdevents-sdk/src/generated/change_updated_subject.rs +++ /dev/null @@ -1,29 +0,0 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) -use serde::{Serialize, Deserialize}; - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Subject { - #[serde(rename = "content")] - pub content: Content, - #[serde(rename = "id")] - pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, - #[serde(rename = "type")] - pub r#type: String, -} - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Content { - #[serde(rename = "repository", skip_serializing_if = "Option::is_none")] - pub repository: Option, -} - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Repository { - #[serde(rename = "id")] - pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, -} - diff --git a/cdevents-sdk/src/generated/environment_modified_subject.rs b/cdevents-sdk/src/generated/environment_created.rs similarity index 52% rename from cdevents-sdk/src/generated/environment_modified_subject.rs rename to cdevents-sdk/src/generated/environment_created.rs index f69765d..5efe460 100644 --- a/cdevents-sdk/src/generated/environment_modified_subject.rs +++ b/cdevents-sdk/src/generated/environment_created.rs @@ -1,18 +1,6 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Subject { - #[serde(rename = "content")] - pub content: Content, - #[serde(rename = "id")] - pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, - #[serde(rename = "type")] - pub r#type: String, -} - #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] pub struct Content { #[serde(rename = "name", skip_serializing_if = "Option::is_none")] diff --git a/cdevents-sdk/src/generated/environment_deleted.rs b/cdevents-sdk/src/generated/environment_deleted.rs new file mode 100644 index 0000000..1e25b81 --- /dev/null +++ b/cdevents-sdk/src/generated/environment_deleted.rs @@ -0,0 +1,9 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { + #[serde(rename = "name", skip_serializing_if = "Option::is_none")] + pub name: Option, +} + diff --git a/cdevents-sdk/src/generated/environment_deleted_subject.rs b/cdevents-sdk/src/generated/environment_deleted_subject.rs deleted file mode 100644 index b34d527..0000000 --- a/cdevents-sdk/src/generated/environment_deleted_subject.rs +++ /dev/null @@ -1,21 +0,0 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) -use serde::{Serialize, Deserialize}; - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Subject { - #[serde(rename = "content")] - pub content: Content, - #[serde(rename = "id")] - pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, - #[serde(rename = "type")] - pub r#type: String, -} - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Content { - #[serde(rename = "name", skip_serializing_if = "Option::is_none")] - pub name: Option, -} - diff --git a/cdevents-sdk/src/generated/environment_created_subject.rs b/cdevents-sdk/src/generated/environment_modified.rs similarity index 52% rename from cdevents-sdk/src/generated/environment_created_subject.rs rename to cdevents-sdk/src/generated/environment_modified.rs index f69765d..5efe460 100644 --- a/cdevents-sdk/src/generated/environment_created_subject.rs +++ b/cdevents-sdk/src/generated/environment_modified.rs @@ -1,18 +1,6 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Subject { - #[serde(rename = "content")] - pub content: Content, - #[serde(rename = "id")] - pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, - #[serde(rename = "type")] - pub r#type: String, -} - #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] pub struct Content { #[serde(rename = "name", skip_serializing_if = "Option::is_none")] diff --git a/cdevents-sdk/src/generated/incident_detected_subject.rs b/cdevents-sdk/src/generated/incident_detected.rs similarity index 75% rename from cdevents-sdk/src/generated/incident_detected_subject.rs rename to cdevents-sdk/src/generated/incident_detected.rs index b6a1219..a444e59 100644 --- a/cdevents-sdk/src/generated/incident_detected_subject.rs +++ b/cdevents-sdk/src/generated/incident_detected.rs @@ -1,18 +1,6 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Subject { - #[serde(rename = "content")] - pub content: Content, - #[serde(rename = "id")] - pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, - #[serde(rename = "type")] - pub r#type: String, -} - #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] pub struct Content { #[serde(rename = "artifactId", skip_serializing_if = "Option::is_none")] diff --git a/cdevents-sdk/src/generated/incident_reported_subject.rs b/cdevents-sdk/src/generated/incident_reported.rs similarity index 76% rename from cdevents-sdk/src/generated/incident_reported_subject.rs rename to cdevents-sdk/src/generated/incident_reported.rs index f923b5f..43ed85d 100644 --- a/cdevents-sdk/src/generated/incident_reported_subject.rs +++ b/cdevents-sdk/src/generated/incident_reported.rs @@ -1,18 +1,6 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Subject { - #[serde(rename = "content")] - pub content: Content, - #[serde(rename = "id")] - pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, - #[serde(rename = "type")] - pub r#type: String, -} - #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] pub struct Content { #[serde(rename = "artifactId", skip_serializing_if = "Option::is_none")] diff --git a/cdevents-sdk/src/generated/incident_resolved_subject.rs b/cdevents-sdk/src/generated/incident_resolved.rs similarity index 75% rename from cdevents-sdk/src/generated/incident_resolved_subject.rs rename to cdevents-sdk/src/generated/incident_resolved.rs index b6a1219..a444e59 100644 --- a/cdevents-sdk/src/generated/incident_resolved_subject.rs +++ b/cdevents-sdk/src/generated/incident_resolved.rs @@ -1,18 +1,6 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Subject { - #[serde(rename = "content")] - pub content: Content, - #[serde(rename = "id")] - pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, - #[serde(rename = "type")] - pub r#type: String, -} - #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] pub struct Content { #[serde(rename = "artifactId", skip_serializing_if = "Option::is_none")] diff --git a/cdevents-sdk/src/generated/mod.rs b/cdevents-sdk/src/generated/mod.rs index 53bc2ad..50bd19c 100644 --- a/cdevents-sdk/src/generated/mod.rs +++ b/cdevents-sdk/src/generated/mod.rs @@ -1,250 +1,296 @@ // code generated by cdevents/sdk-rust/generator (mod.hbs) -pub mod artifact_packaged_subject; -pub mod artifact_published_subject; -pub mod artifact_signed_subject; -pub mod branch_created_subject; -pub mod branch_deleted_subject; -pub mod build_finished_subject; -pub mod build_queued_subject; -pub mod build_started_subject; -pub mod change_abandoned_subject; -pub mod change_created_subject; -pub mod change_merged_subject; -pub mod change_reviewed_subject; -pub mod change_updated_subject; -pub mod environment_created_subject; -pub mod environment_deleted_subject; -pub mod environment_modified_subject; -pub mod incident_detected_subject; -pub mod incident_reported_subject; -pub mod incident_resolved_subject; -pub mod pipeline_run_finished_subject; -pub mod pipeline_run_queued_subject; -pub mod pipeline_run_started_subject; -pub mod repository_created_subject; -pub mod repository_deleted_subject; -pub mod repository_modified_subject; -pub mod service_deployed_subject; -pub mod service_published_subject; -pub mod service_removed_subject; -pub mod service_rolledback_subject; -pub mod service_upgraded_subject; -pub mod task_run_finished_subject; -pub mod task_run_started_subject; -pub mod test_case_run_finished_subject; -pub mod test_case_run_queued_subject; -pub mod test_case_run_started_subject; -pub mod test_output_published_subject; -pub mod test_suite_finished_subject; -pub mod test_suite_run_queued_subject; -pub mod test_suite_run_started_subject; + +use serde::de::Error; + +pub mod artifact_packaged; +pub mod artifact_published; +pub mod artifact_signed; +pub mod branch_created; +pub mod branch_deleted; +pub mod build_finished; +pub mod build_queued; +pub mod build_started; +pub mod change_abandoned; +pub mod change_created; +pub mod change_merged; +pub mod change_reviewed; +pub mod change_updated; +pub mod environment_created; +pub mod environment_deleted; +pub mod environment_modified; +pub mod incident_detected; +pub mod incident_reported; +pub mod incident_resolved; +pub mod pipeline_run_finished; +pub mod pipeline_run_queued; +pub mod pipeline_run_started; +pub mod repository_created; +pub mod repository_deleted; +pub mod repository_modified; +pub mod service_deployed; +pub mod service_published; +pub mod service_removed; +pub mod service_rolledback; +pub mod service_upgraded; +pub mod task_run_finished; +pub mod task_run_started; +pub mod test_case_run_finished; +pub mod test_case_run_queued; +pub mod test_case_run_started; +pub mod test_output_published; +pub mod test_suite_finished; +pub mod test_suite_run_queued; +pub mod test_suite_run_started; use serde::{Serialize, Deserialize}; +pub const ARTIFACT_PACKAGED: &str = "dev.cdevents.artifact.packaged.0.1.1"; +pub const ARTIFACT_PUBLISHED: &str = "dev.cdevents.artifact.published.0.1.1"; +pub const ARTIFACT_SIGNED: &str = "dev.cdevents.artifact.signed.0.1.0"; +pub const BRANCH_CREATED: &str = "dev.cdevents.branch.created.0.1.2"; +pub const BRANCH_DELETED: &str = "dev.cdevents.branch.deleted.0.1.2"; +pub const BUILD_FINISHED: &str = "dev.cdevents.build.finished.0.1.1"; +pub const BUILD_QUEUED: &str = "dev.cdevents.build.queued.0.1.1"; +pub const BUILD_STARTED: &str = "dev.cdevents.build.started.0.1.1"; +pub const CHANGE_ABANDONED: &str = "dev.cdevents.change.abandoned.0.1.2"; +pub const CHANGE_CREATED: &str = "dev.cdevents.change.created.0.1.2"; +pub const CHANGE_MERGED: &str = "dev.cdevents.change.merged.0.1.2"; +pub const CHANGE_REVIEWED: &str = "dev.cdevents.change.reviewed.0.1.2"; +pub const CHANGE_UPDATED: &str = "dev.cdevents.change.updated.0.1.2"; +pub const ENVIRONMENT_CREATED: &str = "dev.cdevents.environment.created.0.1.1"; +pub const ENVIRONMENT_DELETED: &str = "dev.cdevents.environment.deleted.0.1.1"; +pub const ENVIRONMENT_MODIFIED: &str = "dev.cdevents.environment.modified.0.1.1"; +pub const INCIDENT_DETECTED: &str = "dev.cdevents.incident.detected.0.1.0"; +pub const INCIDENT_REPORTED: &str = "dev.cdevents.incident.reported.0.1.0"; +pub const INCIDENT_RESOLVED: &str = "dev.cdevents.incident.resolved.0.1.0"; +pub const PIPELINE_RUN_FINISHED: &str = "dev.cdevents.pipelinerun.finished.0.1.1"; +pub const PIPELINE_RUN_QUEUED: &str = "dev.cdevents.pipelinerun.queued.0.1.1"; +pub const PIPELINE_RUN_STARTED: &str = "dev.cdevents.pipelinerun.started.0.1.1"; +pub const REPOSITORY_CREATED: &str = "dev.cdevents.repository.created.0.1.1"; +pub const REPOSITORY_DELETED: &str = "dev.cdevents.repository.deleted.0.1.1"; +pub const REPOSITORY_MODIFIED: &str = "dev.cdevents.repository.modified.0.1.1"; +pub const SERVICE_DEPLOYED: &str = "dev.cdevents.service.deployed.0.1.1"; +pub const SERVICE_PUBLISHED: &str = "dev.cdevents.service.published.0.1.1"; +pub const SERVICE_REMOVED: &str = "dev.cdevents.service.removed.0.1.1"; +pub const SERVICE_ROLLEDBACK: &str = "dev.cdevents.service.rolledback.0.1.1"; +pub const SERVICE_UPGRADED: &str = "dev.cdevents.service.upgraded.0.1.1"; +pub const TASK_RUN_FINISHED: &str = "dev.cdevents.taskrun.finished.0.1.1"; +pub const TASK_RUN_STARTED: &str = "dev.cdevents.taskrun.started.0.1.1"; +pub const TEST_CASE_RUN_FINISHED: &str = "dev.cdevents.testcaserun.finished.0.1.0"; +pub const TEST_CASE_RUN_QUEUED: &str = "dev.cdevents.testcaserun.queued.0.1.0"; +pub const TEST_CASE_RUN_STARTED: &str = "dev.cdevents.testcaserun.started.0.1.0"; +pub const TEST_OUTPUT_PUBLISHED: &str = "dev.cdevents.testoutput.published.0.1.0"; +pub const TEST_SUITE_FINISHED: &str = "dev.cdevents.testsuiterun.finished.0.1.0"; +pub const TEST_SUITE_RUN_QUEUED: &str = "dev.cdevents.testsuiterun.queued.0.1.0"; +pub const TEST_SUITE_RUN_STARTED: &str = "dev.cdevents.testsuiterun.started.0.1.0"; + #[derive(Debug,Clone,Serialize,Deserialize, PartialEq, Eq)] #[serde(untagged)] // TODO how to use content of context.type as discriminator ? -pub enum Subject { - ArtifactPackagedSubject(artifact_packaged_subject::Subject), - ArtifactPublishedSubject(artifact_published_subject::Subject), - ArtifactSignedSubject(artifact_signed_subject::Subject), - BranchCreatedSubject(branch_created_subject::Subject), - BranchDeletedSubject(branch_deleted_subject::Subject), - BuildFinishedSubject(build_finished_subject::Subject), - BuildQueuedSubject(build_queued_subject::Subject), - BuildStartedSubject(build_started_subject::Subject), - ChangeAbandonedSubject(change_abandoned_subject::Subject), - ChangeCreatedSubject(change_created_subject::Subject), - ChangeMergedSubject(change_merged_subject::Subject), - ChangeReviewedSubject(change_reviewed_subject::Subject), - ChangeUpdatedSubject(change_updated_subject::Subject), - EnvironmentCreatedSubject(environment_created_subject::Subject), - EnvironmentDeletedSubject(environment_deleted_subject::Subject), - EnvironmentModifiedSubject(environment_modified_subject::Subject), - IncidentDetectedSubject(incident_detected_subject::Subject), - IncidentReportedSubject(incident_reported_subject::Subject), - IncidentResolvedSubject(incident_resolved_subject::Subject), - PipelineRunFinishedSubject(pipeline_run_finished_subject::Subject), - PipelineRunQueuedSubject(pipeline_run_queued_subject::Subject), - PipelineRunStartedSubject(pipeline_run_started_subject::Subject), - RepositoryCreatedSubject(repository_created_subject::Subject), - RepositoryDeletedSubject(repository_deleted_subject::Subject), - RepositoryModifiedSubject(repository_modified_subject::Subject), - ServiceDeployedSubject(service_deployed_subject::Subject), - ServicePublishedSubject(service_published_subject::Subject), - ServiceRemovedSubject(service_removed_subject::Subject), - ServiceRolledbackSubject(service_rolledback_subject::Subject), - ServiceUpgradedSubject(service_upgraded_subject::Subject), - TaskRunFinishedSubject(task_run_finished_subject::Subject), - TaskRunStartedSubject(task_run_started_subject::Subject), - TestCaseRunFinishedSubject(test_case_run_finished_subject::Subject), - TestCaseRunQueuedSubject(test_case_run_queued_subject::Subject), - TestCaseRunStartedSubject(test_case_run_started_subject::Subject), - TestOutputPublishedSubject(test_output_published_subject::Subject), - TestSuiteFinishedSubject(test_suite_finished_subject::Subject), - TestSuiteRunQueuedSubject(test_suite_run_queued_subject::Subject), - TestSuiteRunStartedSubject(test_suite_run_started_subject::Subject), +pub enum Content { + ArtifactPackaged(artifact_packaged::Content), + ArtifactPublished(artifact_published::Content), + ArtifactSigned(artifact_signed::Content), + BranchCreated(branch_created::Content), + BranchDeleted(branch_deleted::Content), + BuildFinished(build_finished::Content), + BuildQueued(build_queued::Content), + BuildStarted(build_started::Content), + ChangeAbandoned(change_abandoned::Content), + ChangeCreated(change_created::Content), + ChangeMerged(change_merged::Content), + ChangeReviewed(change_reviewed::Content), + ChangeUpdated(change_updated::Content), + EnvironmentCreated(environment_created::Content), + EnvironmentDeleted(environment_deleted::Content), + EnvironmentModified(environment_modified::Content), + IncidentDetected(incident_detected::Content), + IncidentReported(incident_reported::Content), + IncidentResolved(incident_resolved::Content), + PipelineRunFinished(pipeline_run_finished::Content), + PipelineRunQueued(pipeline_run_queued::Content), + PipelineRunStarted(pipeline_run_started::Content), + RepositoryCreated(repository_created::Content), + RepositoryDeleted(repository_deleted::Content), + RepositoryModified(repository_modified::Content), + ServiceDeployed(service_deployed::Content), + ServicePublished(service_published::Content), + ServiceRemoved(service_removed::Content), + ServiceRolledback(service_rolledback::Content), + ServiceUpgraded(service_upgraded::Content), + TaskRunFinished(task_run_finished::Content), + TaskRunStarted(task_run_started::Content), + TestCaseRunFinished(test_case_run_finished::Content), + TestCaseRunQueued(test_case_run_queued::Content), + TestCaseRunStarted(test_case_run_started::Content), + TestOutputPublished(test_output_published::Content), + TestSuiteFinished(test_suite_finished::Content), + TestSuiteRunQueued(test_suite_run_queued::Content), + TestSuiteRunStarted(test_suite_run_started::Content), } -impl Subject { - pub fn from_json(ty: &str, json: serde_json::Value) -> Self{ +impl Content { + pub fn from_json(ty: &str, json: serde_json::Value) -> Result{ match ty { - "dev.cdevents.artifact.packaged.0.1.1" => { - let subject: artifact_packaged_subject::Subject = serde_json::from_value(json).unwrap(); - Self::ArtifactPackagedSubject(subject) - }, - "dev.cdevents.artifact.published.0.1.1" => { - let subject: artifact_published_subject::Subject = serde_json::from_value(json).unwrap(); - Self::ArtifactPublishedSubject(subject) - }, - "dev.cdevents.artifact.signed.0.1.0" => { - let subject: artifact_signed_subject::Subject = serde_json::from_value(json).unwrap(); - Self::ArtifactSignedSubject(subject) - }, - "dev.cdevents.branch.created.0.1.2" => { - let subject: branch_created_subject::Subject = serde_json::from_value(json).unwrap(); - Self::BranchCreatedSubject(subject) - }, - "dev.cdevents.branch.deleted.0.1.2" => { - let subject: branch_deleted_subject::Subject = serde_json::from_value(json).unwrap(); - Self::BranchDeletedSubject(subject) - }, - "dev.cdevents.build.finished.0.1.1" => { - let subject: build_finished_subject::Subject = serde_json::from_value(json).unwrap(); - Self::BuildFinishedSubject(subject) + ARTIFACT_PACKAGED => { + let variant: artifact_packaged::Content = serde_json::from_value(json)?; + Ok(Self::ArtifactPackaged(variant)) }, - "dev.cdevents.build.queued.0.1.1" => { - let subject: build_queued_subject::Subject = serde_json::from_value(json).unwrap(); - Self::BuildQueuedSubject(subject) + ARTIFACT_PUBLISHED => { + let variant: artifact_published::Content = serde_json::from_value(json)?; + Ok(Self::ArtifactPublished(variant)) }, - "dev.cdevents.build.started.0.1.1" => { - let subject: build_started_subject::Subject = serde_json::from_value(json).unwrap(); - Self::BuildStartedSubject(subject) + ARTIFACT_SIGNED => { + let variant: artifact_signed::Content = serde_json::from_value(json)?; + Ok(Self::ArtifactSigned(variant)) }, - "dev.cdevents.change.abandoned.0.1.2" => { - let subject: change_abandoned_subject::Subject = serde_json::from_value(json).unwrap(); - Self::ChangeAbandonedSubject(subject) + BRANCH_CREATED => { + let variant: branch_created::Content = serde_json::from_value(json)?; + Ok(Self::BranchCreated(variant)) }, - "dev.cdevents.change.created.0.1.2" => { - let subject: change_created_subject::Subject = serde_json::from_value(json).unwrap(); - Self::ChangeCreatedSubject(subject) + BRANCH_DELETED => { + let variant: branch_deleted::Content = serde_json::from_value(json)?; + Ok(Self::BranchDeleted(variant)) }, - "dev.cdevents.change.merged.0.1.2" => { - let subject: change_merged_subject::Subject = serde_json::from_value(json).unwrap(); - Self::ChangeMergedSubject(subject) + BUILD_FINISHED => { + let variant: build_finished::Content = serde_json::from_value(json)?; + Ok(Self::BuildFinished(variant)) }, - "dev.cdevents.change.reviewed.0.1.2" => { - let subject: change_reviewed_subject::Subject = serde_json::from_value(json).unwrap(); - Self::ChangeReviewedSubject(subject) + BUILD_QUEUED => { + let variant: build_queued::Content = serde_json::from_value(json)?; + Ok(Self::BuildQueued(variant)) }, - "dev.cdevents.change.updated.0.1.2" => { - let subject: change_updated_subject::Subject = serde_json::from_value(json).unwrap(); - Self::ChangeUpdatedSubject(subject) + BUILD_STARTED => { + let variant: build_started::Content = serde_json::from_value(json)?; + Ok(Self::BuildStarted(variant)) }, - "dev.cdevents.environment.created.0.1.1" => { - let subject: environment_created_subject::Subject = serde_json::from_value(json).unwrap(); - Self::EnvironmentCreatedSubject(subject) + CHANGE_ABANDONED => { + let variant: change_abandoned::Content = serde_json::from_value(json)?; + Ok(Self::ChangeAbandoned(variant)) }, - "dev.cdevents.environment.deleted.0.1.1" => { - let subject: environment_deleted_subject::Subject = serde_json::from_value(json).unwrap(); - Self::EnvironmentDeletedSubject(subject) + CHANGE_CREATED => { + let variant: change_created::Content = serde_json::from_value(json)?; + Ok(Self::ChangeCreated(variant)) }, - "dev.cdevents.environment.modified.0.1.1" => { - let subject: environment_modified_subject::Subject = serde_json::from_value(json).unwrap(); - Self::EnvironmentModifiedSubject(subject) + CHANGE_MERGED => { + let variant: change_merged::Content = serde_json::from_value(json)?; + Ok(Self::ChangeMerged(variant)) }, - "dev.cdevents.incident.detected.0.1.0" => { - let subject: incident_detected_subject::Subject = serde_json::from_value(json).unwrap(); - Self::IncidentDetectedSubject(subject) + CHANGE_REVIEWED => { + let variant: change_reviewed::Content = serde_json::from_value(json)?; + Ok(Self::ChangeReviewed(variant)) }, - "dev.cdevents.incident.reported.0.1.0" => { - let subject: incident_reported_subject::Subject = serde_json::from_value(json).unwrap(); - Self::IncidentReportedSubject(subject) + CHANGE_UPDATED => { + let variant: change_updated::Content = serde_json::from_value(json)?; + Ok(Self::ChangeUpdated(variant)) }, - "dev.cdevents.incident.resolved.0.1.0" => { - let subject: incident_resolved_subject::Subject = serde_json::from_value(json).unwrap(); - Self::IncidentResolvedSubject(subject) + ENVIRONMENT_CREATED => { + let variant: environment_created::Content = serde_json::from_value(json)?; + Ok(Self::EnvironmentCreated(variant)) }, - "dev.cdevents.pipelinerun.finished.0.1.1" => { - let subject: pipeline_run_finished_subject::Subject = serde_json::from_value(json).unwrap(); - Self::PipelineRunFinishedSubject(subject) + ENVIRONMENT_DELETED => { + let variant: environment_deleted::Content = serde_json::from_value(json)?; + Ok(Self::EnvironmentDeleted(variant)) + }, + ENVIRONMENT_MODIFIED => { + let variant: environment_modified::Content = serde_json::from_value(json)?; + Ok(Self::EnvironmentModified(variant)) + }, + INCIDENT_DETECTED => { + let variant: incident_detected::Content = serde_json::from_value(json)?; + Ok(Self::IncidentDetected(variant)) + }, + INCIDENT_REPORTED => { + let variant: incident_reported::Content = serde_json::from_value(json)?; + Ok(Self::IncidentReported(variant)) + }, + INCIDENT_RESOLVED => { + let variant: incident_resolved::Content = serde_json::from_value(json)?; + Ok(Self::IncidentResolved(variant)) + }, + PIPELINE_RUN_FINISHED => { + let variant: pipeline_run_finished::Content = serde_json::from_value(json)?; + Ok(Self::PipelineRunFinished(variant)) + }, + PIPELINE_RUN_QUEUED => { + let variant: pipeline_run_queued::Content = serde_json::from_value(json)?; + Ok(Self::PipelineRunQueued(variant)) + }, + PIPELINE_RUN_STARTED => { + let variant: pipeline_run_started::Content = serde_json::from_value(json)?; + Ok(Self::PipelineRunStarted(variant)) + }, + REPOSITORY_CREATED => { + let variant: repository_created::Content = serde_json::from_value(json)?; + Ok(Self::RepositoryCreated(variant)) + }, + REPOSITORY_DELETED => { + let variant: repository_deleted::Content = serde_json::from_value(json)?; + Ok(Self::RepositoryDeleted(variant)) + }, + REPOSITORY_MODIFIED => { + let variant: repository_modified::Content = serde_json::from_value(json)?; + Ok(Self::RepositoryModified(variant)) + }, + SERVICE_DEPLOYED => { + let variant: service_deployed::Content = serde_json::from_value(json)?; + Ok(Self::ServiceDeployed(variant)) }, - "dev.cdevents.pipelinerun.queued.0.1.1" => { - let subject: pipeline_run_queued_subject::Subject = serde_json::from_value(json).unwrap(); - Self::PipelineRunQueuedSubject(subject) + SERVICE_PUBLISHED => { + let variant: service_published::Content = serde_json::from_value(json)?; + Ok(Self::ServicePublished(variant)) }, - "dev.cdevents.pipelinerun.started.0.1.1" => { - let subject: pipeline_run_started_subject::Subject = serde_json::from_value(json).unwrap(); - Self::PipelineRunStartedSubject(subject) + SERVICE_REMOVED => { + let variant: service_removed::Content = serde_json::from_value(json)?; + Ok(Self::ServiceRemoved(variant)) }, - "dev.cdevents.repository.created.0.1.1" => { - let subject: repository_created_subject::Subject = serde_json::from_value(json).unwrap(); - Self::RepositoryCreatedSubject(subject) + SERVICE_ROLLEDBACK => { + let variant: service_rolledback::Content = serde_json::from_value(json)?; + Ok(Self::ServiceRolledback(variant)) }, - "dev.cdevents.repository.deleted.0.1.1" => { - let subject: repository_deleted_subject::Subject = serde_json::from_value(json).unwrap(); - Self::RepositoryDeletedSubject(subject) + SERVICE_UPGRADED => { + let variant: service_upgraded::Content = serde_json::from_value(json)?; + Ok(Self::ServiceUpgraded(variant)) }, - "dev.cdevents.repository.modified.0.1.1" => { - let subject: repository_modified_subject::Subject = serde_json::from_value(json).unwrap(); - Self::RepositoryModifiedSubject(subject) + TASK_RUN_FINISHED => { + let variant: task_run_finished::Content = serde_json::from_value(json)?; + Ok(Self::TaskRunFinished(variant)) }, - "dev.cdevents.service.deployed.0.1.1" => { - let subject: service_deployed_subject::Subject = serde_json::from_value(json).unwrap(); - Self::ServiceDeployedSubject(subject) + TASK_RUN_STARTED => { + let variant: task_run_started::Content = serde_json::from_value(json)?; + Ok(Self::TaskRunStarted(variant)) }, - "dev.cdevents.service.published.0.1.1" => { - let subject: service_published_subject::Subject = serde_json::from_value(json).unwrap(); - Self::ServicePublishedSubject(subject) + TEST_CASE_RUN_FINISHED => { + let variant: test_case_run_finished::Content = serde_json::from_value(json)?; + Ok(Self::TestCaseRunFinished(variant)) }, - "dev.cdevents.service.removed.0.1.1" => { - let subject: service_removed_subject::Subject = serde_json::from_value(json).unwrap(); - Self::ServiceRemovedSubject(subject) + TEST_CASE_RUN_QUEUED => { + let variant: test_case_run_queued::Content = serde_json::from_value(json)?; + Ok(Self::TestCaseRunQueued(variant)) }, - "dev.cdevents.service.rolledback.0.1.1" => { - let subject: service_rolledback_subject::Subject = serde_json::from_value(json).unwrap(); - Self::ServiceRolledbackSubject(subject) + TEST_CASE_RUN_STARTED => { + let variant: test_case_run_started::Content = serde_json::from_value(json)?; + Ok(Self::TestCaseRunStarted(variant)) }, - "dev.cdevents.service.upgraded.0.1.1" => { - let subject: service_upgraded_subject::Subject = serde_json::from_value(json).unwrap(); - Self::ServiceUpgradedSubject(subject) + TEST_OUTPUT_PUBLISHED => { + let variant: test_output_published::Content = serde_json::from_value(json)?; + Ok(Self::TestOutputPublished(variant)) }, - "dev.cdevents.taskrun.finished.0.1.1" => { - let subject: task_run_finished_subject::Subject = serde_json::from_value(json).unwrap(); - Self::TaskRunFinishedSubject(subject) + TEST_SUITE_FINISHED => { + let variant: test_suite_finished::Content = serde_json::from_value(json)?; + Ok(Self::TestSuiteFinished(variant)) }, - "dev.cdevents.taskrun.started.0.1.1" => { - let subject: task_run_started_subject::Subject = serde_json::from_value(json).unwrap(); - Self::TaskRunStartedSubject(subject) + TEST_SUITE_RUN_QUEUED => { + let variant: test_suite_run_queued::Content = serde_json::from_value(json)?; + Ok(Self::TestSuiteRunQueued(variant)) }, - "dev.cdevents.testcaserun.finished.0.1.0" => { - let subject: test_case_run_finished_subject::Subject = serde_json::from_value(json).unwrap(); - Self::TestCaseRunFinishedSubject(subject) + TEST_SUITE_RUN_STARTED => { + let variant: test_suite_run_started::Content = serde_json::from_value(json)?; + Ok(Self::TestSuiteRunStarted(variant)) }, - "dev.cdevents.testcaserun.queued.0.1.0" => { - let subject: test_case_run_queued_subject::Subject = serde_json::from_value(json).unwrap(); - Self::TestCaseRunQueuedSubject(subject) - }, - "dev.cdevents.testcaserun.started.0.1.0" => { - let subject: test_case_run_started_subject::Subject = serde_json::from_value(json).unwrap(); - Self::TestCaseRunStartedSubject(subject) - }, - "dev.cdevents.testoutput.published.0.1.0" => { - let subject: test_output_published_subject::Subject = serde_json::from_value(json).unwrap(); - Self::TestOutputPublishedSubject(subject) - }, - "dev.cdevents.testsuiterun.finished.0.1.0" => { - let subject: test_suite_finished_subject::Subject = serde_json::from_value(json).unwrap(); - Self::TestSuiteFinishedSubject(subject) - }, - "dev.cdevents.testsuiterun.queued.0.1.0" => { - let subject: test_suite_run_queued_subject::Subject = serde_json::from_value(json).unwrap(); - Self::TestSuiteRunQueuedSubject(subject) - }, - "dev.cdevents.testsuiterun.started.0.1.0" => { - let subject: test_suite_run_started_subject::Subject = serde_json::from_value(json).unwrap(); - Self::TestSuiteRunStartedSubject(subject) - }, - x => todo!("no implementation for type '{}', please open an issue", x), + variant => Err(serde_json::Error::custom(format_args!( + "unknown variant `{}`, expected 'dev.cdevents.{{subject}}.{{predicate}}.{{version}}'", + variant, + ))), } } -} \ No newline at end of file +} diff --git a/cdevents-sdk/src/generated/pipeline_run_queued_subject.rs b/cdevents-sdk/src/generated/pipeline_run_finished.rs similarity index 54% rename from cdevents-sdk/src/generated/pipeline_run_queued_subject.rs rename to cdevents-sdk/src/generated/pipeline_run_finished.rs index 269157c..56c979f 100644 --- a/cdevents-sdk/src/generated/pipeline_run_queued_subject.rs +++ b/cdevents-sdk/src/generated/pipeline_run_finished.rs @@ -1,20 +1,12 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Subject { - #[serde(rename = "content")] - pub content: Content, - #[serde(rename = "id")] - pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, - #[serde(rename = "type")] - pub r#type: String, -} - #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] pub struct Content { + #[serde(rename = "errors", skip_serializing_if = "Option::is_none")] + pub errors: Option, + #[serde(rename = "outcome", skip_serializing_if = "Option::is_none")] + pub outcome: Option, #[serde(rename = "pipelineName", skip_serializing_if = "Option::is_none")] pub pipeline_name: Option, #[serde(rename = "url", skip_serializing_if = "Option::is_none")] diff --git a/cdevents-sdk/src/generated/pipeline_run_queued.rs b/cdevents-sdk/src/generated/pipeline_run_queued.rs new file mode 100644 index 0000000..1885da8 --- /dev/null +++ b/cdevents-sdk/src/generated/pipeline_run_queued.rs @@ -0,0 +1,11 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { + #[serde(rename = "pipelineName", skip_serializing_if = "Option::is_none")] + pub pipeline_name: Option, + #[serde(rename = "url", skip_serializing_if = "Option::is_none")] + pub url: Option, +} + diff --git a/cdevents-sdk/src/generated/pipeline_run_started.rs b/cdevents-sdk/src/generated/pipeline_run_started.rs new file mode 100644 index 0000000..d832d1b --- /dev/null +++ b/cdevents-sdk/src/generated/pipeline_run_started.rs @@ -0,0 +1,11 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { + #[serde(rename = "pipelineName")] + pub pipeline_name: String, + #[serde(rename = "url")] + pub url: String, +} + diff --git a/cdevents-sdk/src/generated/pipeline_run_started_subject.rs b/cdevents-sdk/src/generated/pipeline_run_started_subject.rs deleted file mode 100644 index 1962fff..0000000 --- a/cdevents-sdk/src/generated/pipeline_run_started_subject.rs +++ /dev/null @@ -1,23 +0,0 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) -use serde::{Serialize, Deserialize}; - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Subject { - #[serde(rename = "content")] - pub content: Content, - #[serde(rename = "id")] - pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, - #[serde(rename = "type")] - pub r#type: String, -} - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Content { - #[serde(rename = "pipelineName")] - pub pipeline_name: String, - #[serde(rename = "url")] - pub url: String, -} - diff --git a/cdevents-sdk/src/generated/repository_created_subject.rs b/cdevents-sdk/src/generated/repository_created.rs similarity index 58% rename from cdevents-sdk/src/generated/repository_created_subject.rs rename to cdevents-sdk/src/generated/repository_created.rs index 3f6fe9c..9ca92ef 100644 --- a/cdevents-sdk/src/generated/repository_created_subject.rs +++ b/cdevents-sdk/src/generated/repository_created.rs @@ -1,18 +1,6 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Subject { - #[serde(rename = "content")] - pub content: Content, - #[serde(rename = "id")] - pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, - #[serde(rename = "type")] - pub r#type: String, -} - #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] pub struct Content { #[serde(rename = "name")] diff --git a/cdevents-sdk/src/generated/repository_deleted_subject.rs b/cdevents-sdk/src/generated/repository_deleted.rs similarity index 62% rename from cdevents-sdk/src/generated/repository_deleted_subject.rs rename to cdevents-sdk/src/generated/repository_deleted.rs index 8274fd8..faac696 100644 --- a/cdevents-sdk/src/generated/repository_deleted_subject.rs +++ b/cdevents-sdk/src/generated/repository_deleted.rs @@ -1,18 +1,6 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Subject { - #[serde(rename = "content")] - pub content: Content, - #[serde(rename = "id")] - pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, - #[serde(rename = "type")] - pub r#type: String, -} - #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] pub struct Content { #[serde(rename = "name", skip_serializing_if = "Option::is_none")] diff --git a/cdevents-sdk/src/generated/repository_modified_subject.rs b/cdevents-sdk/src/generated/repository_modified.rs similarity index 62% rename from cdevents-sdk/src/generated/repository_modified_subject.rs rename to cdevents-sdk/src/generated/repository_modified.rs index 8274fd8..faac696 100644 --- a/cdevents-sdk/src/generated/repository_modified_subject.rs +++ b/cdevents-sdk/src/generated/repository_modified.rs @@ -1,18 +1,6 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Subject { - #[serde(rename = "content")] - pub content: Content, - #[serde(rename = "id")] - pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, - #[serde(rename = "type")] - pub r#type: String, -} - #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] pub struct Content { #[serde(rename = "name", skip_serializing_if = "Option::is_none")] diff --git a/cdevents-sdk/src/generated/service_deployed.rs b/cdevents-sdk/src/generated/service_deployed.rs new file mode 100644 index 0000000..11ac67f --- /dev/null +++ b/cdevents-sdk/src/generated/service_deployed.rs @@ -0,0 +1,19 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { + #[serde(rename = "artifactId")] + pub artifact_id: String, + #[serde(rename = "environment")] + pub environment: Environment, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Environment { + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, +} + diff --git a/cdevents-sdk/src/generated/service_deployed_subject.rs b/cdevents-sdk/src/generated/service_deployed_subject.rs deleted file mode 100644 index 299b77b..0000000 --- a/cdevents-sdk/src/generated/service_deployed_subject.rs +++ /dev/null @@ -1,31 +0,0 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) -use serde::{Serialize, Deserialize}; - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Subject { - #[serde(rename = "content")] - pub content: Content, - #[serde(rename = "id")] - pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, - #[serde(rename = "type")] - pub r#type: String, -} - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Content { - #[serde(rename = "artifactId")] - pub artifact_id: String, - #[serde(rename = "environment")] - pub environment: Environment, -} - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Environment { - #[serde(rename = "id")] - pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, -} - diff --git a/cdevents-sdk/src/generated/service_published.rs b/cdevents-sdk/src/generated/service_published.rs new file mode 100644 index 0000000..64a31e3 --- /dev/null +++ b/cdevents-sdk/src/generated/service_published.rs @@ -0,0 +1,17 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { + #[serde(rename = "environment", skip_serializing_if = "Option::is_none")] + pub environment: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Environment { + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, +} + diff --git a/cdevents-sdk/src/generated/service_published_subject.rs b/cdevents-sdk/src/generated/service_published_subject.rs deleted file mode 100644 index d480fbc..0000000 --- a/cdevents-sdk/src/generated/service_published_subject.rs +++ /dev/null @@ -1,29 +0,0 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) -use serde::{Serialize, Deserialize}; - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Subject { - #[serde(rename = "content")] - pub content: Content, - #[serde(rename = "id")] - pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, - #[serde(rename = "type")] - pub r#type: String, -} - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Content { - #[serde(rename = "environment", skip_serializing_if = "Option::is_none")] - pub environment: Option, -} - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Environment { - #[serde(rename = "id")] - pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, -} - diff --git a/cdevents-sdk/src/generated/service_removed.rs b/cdevents-sdk/src/generated/service_removed.rs new file mode 100644 index 0000000..64a31e3 --- /dev/null +++ b/cdevents-sdk/src/generated/service_removed.rs @@ -0,0 +1,17 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { + #[serde(rename = "environment", skip_serializing_if = "Option::is_none")] + pub environment: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Environment { + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, +} + diff --git a/cdevents-sdk/src/generated/service_removed_subject.rs b/cdevents-sdk/src/generated/service_removed_subject.rs deleted file mode 100644 index d480fbc..0000000 --- a/cdevents-sdk/src/generated/service_removed_subject.rs +++ /dev/null @@ -1,29 +0,0 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) -use serde::{Serialize, Deserialize}; - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Subject { - #[serde(rename = "content")] - pub content: Content, - #[serde(rename = "id")] - pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, - #[serde(rename = "type")] - pub r#type: String, -} - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Content { - #[serde(rename = "environment", skip_serializing_if = "Option::is_none")] - pub environment: Option, -} - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Environment { - #[serde(rename = "id")] - pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, -} - diff --git a/cdevents-sdk/src/generated/service_rolledback.rs b/cdevents-sdk/src/generated/service_rolledback.rs new file mode 100644 index 0000000..11ac67f --- /dev/null +++ b/cdevents-sdk/src/generated/service_rolledback.rs @@ -0,0 +1,19 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { + #[serde(rename = "artifactId")] + pub artifact_id: String, + #[serde(rename = "environment")] + pub environment: Environment, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Environment { + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, +} + diff --git a/cdevents-sdk/src/generated/service_rolledback_subject.rs b/cdevents-sdk/src/generated/service_rolledback_subject.rs deleted file mode 100644 index 299b77b..0000000 --- a/cdevents-sdk/src/generated/service_rolledback_subject.rs +++ /dev/null @@ -1,31 +0,0 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) -use serde::{Serialize, Deserialize}; - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Subject { - #[serde(rename = "content")] - pub content: Content, - #[serde(rename = "id")] - pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, - #[serde(rename = "type")] - pub r#type: String, -} - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Content { - #[serde(rename = "artifactId")] - pub artifact_id: String, - #[serde(rename = "environment")] - pub environment: Environment, -} - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Environment { - #[serde(rename = "id")] - pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, -} - diff --git a/cdevents-sdk/src/generated/service_upgraded.rs b/cdevents-sdk/src/generated/service_upgraded.rs new file mode 100644 index 0000000..11ac67f --- /dev/null +++ b/cdevents-sdk/src/generated/service_upgraded.rs @@ -0,0 +1,19 @@ +// code generated by cdevents/sdk-rust/generator (subject.hbs) +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Content { + #[serde(rename = "artifactId")] + pub artifact_id: String, + #[serde(rename = "environment")] + pub environment: Environment, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Environment { + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, +} + diff --git a/cdevents-sdk/src/generated/service_upgraded_subject.rs b/cdevents-sdk/src/generated/service_upgraded_subject.rs deleted file mode 100644 index 299b77b..0000000 --- a/cdevents-sdk/src/generated/service_upgraded_subject.rs +++ /dev/null @@ -1,31 +0,0 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) -use serde::{Serialize, Deserialize}; - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Subject { - #[serde(rename = "content")] - pub content: Content, - #[serde(rename = "id")] - pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, - #[serde(rename = "type")] - pub r#type: String, -} - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Content { - #[serde(rename = "artifactId")] - pub artifact_id: String, - #[serde(rename = "environment")] - pub environment: Environment, -} - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Environment { - #[serde(rename = "id")] - pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, -} - diff --git a/cdevents-sdk/src/generated/pipeline_run_finished_subject.rs b/cdevents-sdk/src/generated/task_run_finished.rs similarity index 73% rename from cdevents-sdk/src/generated/pipeline_run_finished_subject.rs rename to cdevents-sdk/src/generated/task_run_finished.rs index 0eb0e2c..247873c 100644 --- a/cdevents-sdk/src/generated/pipeline_run_finished_subject.rs +++ b/cdevents-sdk/src/generated/task_run_finished.rs @@ -1,27 +1,25 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Subject { - #[serde(rename = "content")] - pub content: Content, - #[serde(rename = "id")] - pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, - #[serde(rename = "type")] - pub r#type: String, -} - #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] pub struct Content { #[serde(rename = "errors", skip_serializing_if = "Option::is_none")] pub errors: Option, #[serde(rename = "outcome", skip_serializing_if = "Option::is_none")] pub outcome: Option, - #[serde(rename = "pipelineName", skip_serializing_if = "Option::is_none")] - pub pipeline_name: Option, + #[serde(rename = "pipelineRun", skip_serializing_if = "Option::is_none")] + pub pipeline_run: Option, + #[serde(rename = "taskName", skip_serializing_if = "Option::is_none")] + pub task_name: Option, #[serde(rename = "url", skip_serializing_if = "Option::is_none")] pub url: Option, } +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct PipelineRun { + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, +} + diff --git a/cdevents-sdk/src/generated/task_run_finished_subject.rs b/cdevents-sdk/src/generated/task_run_finished_subject.rs deleted file mode 100644 index 3f81e24..0000000 --- a/cdevents-sdk/src/generated/task_run_finished_subject.rs +++ /dev/null @@ -1,37 +0,0 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) -use serde::{Serialize, Deserialize}; - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Subject { - #[serde(rename = "content")] - pub content: Content, - #[serde(rename = "id")] - pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, - #[serde(rename = "type")] - pub r#type: String, -} - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Content { - #[serde(rename = "errors", skip_serializing_if = "Option::is_none")] - pub errors: Option, - #[serde(rename = "outcome", skip_serializing_if = "Option::is_none")] - pub outcome: Option, - #[serde(rename = "pipelineRun", skip_serializing_if = "Option::is_none")] - pub pipeline_run: Option, - #[serde(rename = "taskName", skip_serializing_if = "Option::is_none")] - pub task_name: Option, - #[serde(rename = "url", skip_serializing_if = "Option::is_none")] - pub url: Option, -} - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct PipelineRun { - #[serde(rename = "id")] - pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, -} - diff --git a/cdevents-sdk/src/generated/task_run_started_subject.rs b/cdevents-sdk/src/generated/task_run_started.rs similarity index 68% rename from cdevents-sdk/src/generated/task_run_started_subject.rs rename to cdevents-sdk/src/generated/task_run_started.rs index 0b7ef17..92089fd 100644 --- a/cdevents-sdk/src/generated/task_run_started_subject.rs +++ b/cdevents-sdk/src/generated/task_run_started.rs @@ -1,18 +1,6 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Subject { - #[serde(rename = "content")] - pub content: Content, - #[serde(rename = "id")] - pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, - #[serde(rename = "type")] - pub r#type: String, -} - #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] pub struct Content { #[serde(rename = "pipelineRun", skip_serializing_if = "Option::is_none")] diff --git a/cdevents-sdk/src/generated/test_case_run_finished_subject.rs b/cdevents-sdk/src/generated/test_case_run_finished.rs similarity index 83% rename from cdevents-sdk/src/generated/test_case_run_finished_subject.rs rename to cdevents-sdk/src/generated/test_case_run_finished.rs index fdf8b97..c42bdbc 100644 --- a/cdevents-sdk/src/generated/test_case_run_finished_subject.rs +++ b/cdevents-sdk/src/generated/test_case_run_finished.rs @@ -1,18 +1,6 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Subject { - #[serde(rename = "content")] - pub content: Content, - #[serde(rename = "id")] - pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, - #[serde(rename = "type")] - pub r#type: String, -} - #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] pub struct Content { #[serde(rename = "environment")] diff --git a/cdevents-sdk/src/generated/test_case_run_queued_subject.rs b/cdevents-sdk/src/generated/test_case_run_queued.rs similarity index 84% rename from cdevents-sdk/src/generated/test_case_run_queued_subject.rs rename to cdevents-sdk/src/generated/test_case_run_queued.rs index f64d3f2..00c2194 100644 --- a/cdevents-sdk/src/generated/test_case_run_queued_subject.rs +++ b/cdevents-sdk/src/generated/test_case_run_queued.rs @@ -1,18 +1,6 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Subject { - #[serde(rename = "content")] - pub content: Content, - #[serde(rename = "id")] - pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, - #[serde(rename = "type")] - pub r#type: String, -} - #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] pub struct Content { #[serde(rename = "environment")] diff --git a/cdevents-sdk/src/generated/test_case_run_started_subject.rs b/cdevents-sdk/src/generated/test_case_run_started.rs similarity index 84% rename from cdevents-sdk/src/generated/test_case_run_started_subject.rs rename to cdevents-sdk/src/generated/test_case_run_started.rs index f64d3f2..00c2194 100644 --- a/cdevents-sdk/src/generated/test_case_run_started_subject.rs +++ b/cdevents-sdk/src/generated/test_case_run_started.rs @@ -1,18 +1,6 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Subject { - #[serde(rename = "content")] - pub content: Content, - #[serde(rename = "id")] - pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, - #[serde(rename = "type")] - pub r#type: String, -} - #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] pub struct Content { #[serde(rename = "environment")] diff --git a/cdevents-sdk/src/generated/test_output_published_subject.rs b/cdevents-sdk/src/generated/test_output_published.rs similarity index 68% rename from cdevents-sdk/src/generated/test_output_published_subject.rs rename to cdevents-sdk/src/generated/test_output_published.rs index 9ccc5ab..56eb4e6 100644 --- a/cdevents-sdk/src/generated/test_output_published_subject.rs +++ b/cdevents-sdk/src/generated/test_output_published.rs @@ -1,18 +1,6 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Subject { - #[serde(rename = "content")] - pub content: Content, - #[serde(rename = "id")] - pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, - #[serde(rename = "type")] - pub r#type: String, -} - #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] pub struct Content { #[serde(rename = "format")] diff --git a/cdevents-sdk/src/generated/test_suite_finished_subject.rs b/cdevents-sdk/src/generated/test_suite_finished.rs similarity index 79% rename from cdevents-sdk/src/generated/test_suite_finished_subject.rs rename to cdevents-sdk/src/generated/test_suite_finished.rs index cae6ee1..923e301 100644 --- a/cdevents-sdk/src/generated/test_suite_finished_subject.rs +++ b/cdevents-sdk/src/generated/test_suite_finished.rs @@ -1,18 +1,6 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Subject { - #[serde(rename = "content")] - pub content: Content, - #[serde(rename = "id")] - pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, - #[serde(rename = "type")] - pub r#type: String, -} - #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] pub struct Content { #[serde(rename = "environment")] diff --git a/cdevents-sdk/src/generated/test_suite_run_queued_subject.rs b/cdevents-sdk/src/generated/test_suite_run_queued.rs similarity index 80% rename from cdevents-sdk/src/generated/test_suite_run_queued_subject.rs rename to cdevents-sdk/src/generated/test_suite_run_queued.rs index a2a20f7..6a42577 100644 --- a/cdevents-sdk/src/generated/test_suite_run_queued_subject.rs +++ b/cdevents-sdk/src/generated/test_suite_run_queued.rs @@ -1,18 +1,6 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Subject { - #[serde(rename = "content")] - pub content: Content, - #[serde(rename = "id")] - pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, - #[serde(rename = "type")] - pub r#type: String, -} - #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] pub struct Content { #[serde(rename = "environment")] diff --git a/cdevents-sdk/src/generated/test_suite_run_started_subject.rs b/cdevents-sdk/src/generated/test_suite_run_started.rs similarity index 80% rename from cdevents-sdk/src/generated/test_suite_run_started_subject.rs rename to cdevents-sdk/src/generated/test_suite_run_started.rs index ac0d61a..63ce7db 100644 --- a/cdevents-sdk/src/generated/test_suite_run_started_subject.rs +++ b/cdevents-sdk/src/generated/test_suite_run_started.rs @@ -1,18 +1,6 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Subject { - #[serde(rename = "content")] - pub content: Content, - #[serde(rename = "id")] - pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, - #[serde(rename = "type")] - pub r#type: String, -} - #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] pub struct Content { #[serde(rename = "environment")] diff --git a/cdevents-sdk/src/lib.rs b/cdevents-sdk/src/lib.rs index ddb6cae..caca2dd 100644 --- a/cdevents-sdk/src/lib.rs +++ b/cdevents-sdk/src/lib.rs @@ -1,3 +1,5 @@ +// TODO remove unwrap(), expect(...) +// TODO reduce clone() mod generated; pub use generated::*; @@ -20,23 +22,13 @@ pub struct CDEvent { pub custom_data_content_type: Option, } -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Context { - version: String, - id: String, - #[serde(with = "http_serde::uri")] - source: http::Uri, - #[serde(rename = "type")] - r#type: String, - #[serde(with = "time::serde::rfc3339")] - timestamp: time::OffsetDateTime, -} - impl<'de> Deserialize<'de> for CDEvent { fn deserialize(deserializer: D) -> Result where D: Deserializer<'de>, { + #[derive(Deserialize)] + #[serde(field_identifier, rename_all = "camelCase")] enum Field { Context, Subject, @@ -44,43 +36,6 @@ impl<'de> Deserialize<'de> for CDEvent { CustomDataContentType, } - // This part could also be generated independently by: - // - // #[derive(Deserialize)] - // #[serde(field_identifier, rename_all = "lowercase")] - // enum Field { { Context, Subject, CustomData, CustomDataContentType } } - impl<'de> Deserialize<'de> for Field { - fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'de>, - { - struct FieldVisitor; - - impl<'de> Visitor<'de> for FieldVisitor { - type Value = Field; - - fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - formatter.write_str("`context` and `subject`") - } - - fn visit_str(self, value: &str) -> Result - where - E: de::Error, - { - match value { - "context" => Ok(Field::Context), - "subject" => Ok(Field::Subject), - "customData" => Ok(Field::CustomData), - "customDataContentType" => Ok(Field::CustomDataContentType), - _ => Err(de::Error::unknown_field(value, FIELDS)), - } - } - } - - deserializer.deserialize_identifier(FieldVisitor) - } - } - struct CDEventVisitor; impl<'de> Visitor<'de> for CDEventVisitor { @@ -127,8 +82,11 @@ impl<'de> Deserialize<'de> for CDEvent { } } let context = context.ok_or_else(|| de::Error::missing_field("context"))?; - let subject = Subject::from_json(&context.r#type, subject_json.unwrap()); - //let subject = subject.ok_or_else(|| de::Error::missing_field("subject"))?; + let subject_json = + subject_json.ok_or_else(|| de::Error::missing_field("subject"))?; + let subject = + Subject::from_json(&context.r#type, subject_json).map_err(de::Error::custom)?; + Ok(CDEvent { context, subject, @@ -143,6 +101,47 @@ impl<'de> Deserialize<'de> for CDEvent { } } +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Context { + version: String, + id: String, + #[serde(with = "http_serde::uri")] + source: http::Uri, + #[serde(rename = "type")] + r#type: String, + #[serde(with = "time::serde::rfc3339")] + timestamp: time::OffsetDateTime, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Subject { + #[serde(rename = "content")] + pub content: Content, + #[serde(rename = "id")] + pub id: String, + #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + pub source: Option, + #[serde(rename = "type")] + pub r#type: String, +} + +impl Subject { + pub fn from_json(ty: &str, json: serde_json::Value) -> Result { + Ok(Subject { + id: json["id"] + .as_str() + .ok_or_else(|| serde::de::Error::missing_field("id"))? + .to_string(), + r#type: json["type"] + .as_str() + .ok_or_else(|| serde::de::Error::missing_field("type"))? + .to_string(), + source: json["source"].as_str().map(|s| s.to_string()), + content: Content::from_json(ty, json["content"].clone())?, + }) + } +} + #[cfg(test)] mod tests { use super::*; @@ -162,10 +161,6 @@ mod tests { dbg!(&example_json); let cdevent: CDEvent = serde_json::from_value(example_json.clone()).expect("to parse as cdevent"); - // let cdevent: CDEvent = - // deserialize::(example_json.clone()) - // .expect("to parse as cdevent"); - dbg!(&cdevent); let cdevent_json = serde_json::to_value(cdevent).expect("to convert into json"); dbg!(&cdevent_json); diff --git a/generator/src/main.rs b/generator/src/main.rs index 40d75d1..885fd34 100644 --- a/generator/src/main.rs +++ b/generator/src/main.rs @@ -32,9 +32,12 @@ fn main() -> Result<()> { handlebars_misc_helpers::register(&mut hbs); hbs.register_templates_directory(settings.templates_dir, DirectorySourceOptions::default())?; + if settings.dest.exists() { + fs::remove_dir_all(&settings.dest)?; + } fs::create_dir_all(&settings.dest)?; - let mut subjects = vec![]; + let mut variants = vec![]; let mut jsonfiles = std::fs::read_dir(settings.jsonschema_dir)?.collect::, _>>()?; jsonfiles.sort_by_key(|v| v.file_name()); @@ -47,14 +50,14 @@ fn main() -> Result<()> { .as_str() .unwrap_or_default() .to_string(); - let (rust_module, code) = generate_subject(&hbs, json) - .with_context(|| format!("failed to generate subject on {:?}", &path))?; + let (rust_module, code) = generate_variant(&hbs, json) + .with_context(|| format!("failed to generate variant on {:?}", &path))?; let file = settings .dest .join(cruet::to_snake_case(&rust_module)) .with_extension("rs"); fs::write(file, code)?; - subjects.push(SubjectInfo { + variants.push(VariantInfo { context_type, rust_module, }); @@ -63,14 +66,14 @@ fn main() -> Result<()> { } let (module_name, code) = - generate_module(&hbs, &subjects).with_context(|| "failed to generate module")?; + generate_module(&hbs, &variants).with_context(|| "failed to generate module")?; let file = settings.dest.join(&module_name).with_extension("rs"); fs::write(file, code)?; Ok(()) } -fn generate_subject(hbs: &Handlebars, jsonschema: Value) -> Result<(String, String)> { +fn generate_variant(hbs: &Handlebars, jsonschema: Value) -> Result<(String, String)> { let id = jsonschema["$id"] .as_str() .ok_or(anyhow!("$id not found or not a string")) @@ -80,27 +83,27 @@ fn generate_subject(hbs: &Handlebars, jsonschema: Value) -> Result<(String, Stri .and_then(|v| v.last()) .map(cruet::to_snake_case) .ok_or(anyhow!("no path in $id"))? - .replace("_event", "_subject"); + .replace("_event", ""); - let data = build_data_for_subjects(jsonschema); - let code = hbs.render("subject", &data)?; + let data = build_data_for_variants(jsonschema); + let code = hbs.render("variant", &data)?; Ok((module_name.to_string(), code)) } -fn generate_module(hbs: &Handlebars, subjects: &[SubjectInfo]) -> Result<(String, String)> { +fn generate_module(hbs: &Handlebars, variants: &[VariantInfo]) -> Result<(String, String)> { let data = json!({ - "subjects": subjects + "variants": variants }); let code = hbs.render("mod", &data)?; Ok(("mod".to_string(), code)) } -fn build_data_for_subjects(jsonschema: Value) -> Value { +fn build_data_for_variants(jsonschema: Value) -> Value { let mut structs = vec![]; collect_structs( &mut structs, - "subject", - &jsonschema["properties"]["subject"], + "content", + &jsonschema["properties"]["subject"]["properties"]["content"], ); structs.reverse(); @@ -113,7 +116,7 @@ fn build_data_for_subjects(jsonschema: Value) -> Value { type RustTypeName = String; #[derive(Debug, Clone, Serialize, Deserialize)] -struct SubjectInfo { +struct VariantInfo { context_type: String, rust_module: String, } diff --git a/generator/templates/mod.hbs b/generator/templates/mod.hbs index 4f0feea..c918aff 100644 --- a/generator/templates/mod.hbs +++ b/generator/templates/mod.hbs @@ -1,28 +1,38 @@ // code generated by cdevents/sdk-rust/generator (mod.hbs) -{{#each subjects }} + +use serde::de::Error; + +{{#each variants }} pub mod {{this.rust_module}}; {{/each}} use serde::{Serialize, Deserialize}; +{{#each variants }} +pub const {{to_screaming_snake_case this.rust_module}}: &str = "{{ this.context_type }}"; +{{/each}} + #[derive(Debug,Clone,Serialize,Deserialize, PartialEq, Eq)] #[serde(untagged)] // TODO how to use content of context.type as discriminator ? -pub enum Subject { - {{#each subjects }} - {{to_class_case this.rust_module}}({{this.rust_module}}::Subject), +pub enum Content { + {{#each variants }} + {{to_class_case this.rust_module}}({{this.rust_module}}::Content), {{/each}} } -impl Subject { - pub fn from_json(ty: &str, json: serde_json::Value) -> Self{ +impl Content { + pub fn from_json(ty: &str, json: serde_json::Value) -> Result{ match ty { - {{#each subjects }} - "{{ this.context_type }}" => { - let subject: {{this.rust_module}}::Subject = serde_json::from_value(json).unwrap(); - Self::{{to_class_case this.rust_module}}(subject) + {{#each variants }} + {{to_screaming_snake_case this.rust_module}} => { + let variant: {{this.rust_module}}::Content = serde_json::from_value(json)?; + Ok(Self::{{to_class_case this.rust_module}}(variant)) }, {{/each}} - x => todo!("no implementation for type '{}', please open an issue", x), + variant => Err(serde_json::Error::custom(format_args!( + "unknown variant `{}`, expected 'dev.cdevents.\{{subject}}.\{{predicate}}.\{{version}}'", + variant, + ))), } } -} \ No newline at end of file +} diff --git a/generator/templates/subject.hbs b/generator/templates/variant.hbs similarity index 100% rename from generator/templates/subject.hbs rename to generator/templates/variant.hbs From 085b6ed83b63fd70e7f131c988abfb89b9c95f07 Mon Sep 17 00:00:00 2001 From: David Bernard Date: Sun, 14 Jan 2024 13:31:06 +0100 Subject: [PATCH 07/34] fix: use the `context.type` (instead of `$id`) to define the module name resulting in a more aligned file naming with spec (schema and example) Signed-off-by: David Bernard --- cdevents-sdk/src/generated/mod.rs | 150 +++++++++--------- ...un_finished.rs => pipelinerun_finished.rs} | 0 ...ne_run_queued.rs => pipelinerun_queued.rs} | 0 ..._run_started.rs => pipelinerun_started.rs} | 0 ...sk_run_finished.rs => taskrun_finished.rs} | 0 ...task_run_started.rs => taskrun_started.rs} | 0 ...un_finished.rs => testcaserun_finished.rs} | 0 ...se_run_queued.rs => testcaserun_queued.rs} | 0 ..._run_started.rs => testcaserun_started.rs} | 0 ...t_published.rs => testoutput_published.rs} | 0 ...e_finished.rs => testsuiterun_finished.rs} | 0 ...e_run_queued.rs => testsuiterun_queued.rs} | 0 ...run_started.rs => testsuiterun_started.rs} | 0 generator/src/main.rs | 39 +++-- 14 files changed, 97 insertions(+), 92 deletions(-) rename cdevents-sdk/src/generated/{pipeline_run_finished.rs => pipelinerun_finished.rs} (100%) rename cdevents-sdk/src/generated/{pipeline_run_queued.rs => pipelinerun_queued.rs} (100%) rename cdevents-sdk/src/generated/{pipeline_run_started.rs => pipelinerun_started.rs} (100%) rename cdevents-sdk/src/generated/{task_run_finished.rs => taskrun_finished.rs} (100%) rename cdevents-sdk/src/generated/{task_run_started.rs => taskrun_started.rs} (100%) rename cdevents-sdk/src/generated/{test_case_run_finished.rs => testcaserun_finished.rs} (100%) rename cdevents-sdk/src/generated/{test_case_run_queued.rs => testcaserun_queued.rs} (100%) rename cdevents-sdk/src/generated/{test_case_run_started.rs => testcaserun_started.rs} (100%) rename cdevents-sdk/src/generated/{test_output_published.rs => testoutput_published.rs} (100%) rename cdevents-sdk/src/generated/{test_suite_finished.rs => testsuiterun_finished.rs} (100%) rename cdevents-sdk/src/generated/{test_suite_run_queued.rs => testsuiterun_queued.rs} (100%) rename cdevents-sdk/src/generated/{test_suite_run_started.rs => testsuiterun_started.rs} (100%) diff --git a/cdevents-sdk/src/generated/mod.rs b/cdevents-sdk/src/generated/mod.rs index 50bd19c..879534f 100644 --- a/cdevents-sdk/src/generated/mod.rs +++ b/cdevents-sdk/src/generated/mod.rs @@ -21,9 +21,9 @@ pub mod environment_modified; pub mod incident_detected; pub mod incident_reported; pub mod incident_resolved; -pub mod pipeline_run_finished; -pub mod pipeline_run_queued; -pub mod pipeline_run_started; +pub mod pipelinerun_finished; +pub mod pipelinerun_queued; +pub mod pipelinerun_started; pub mod repository_created; pub mod repository_deleted; pub mod repository_modified; @@ -32,17 +32,17 @@ pub mod service_published; pub mod service_removed; pub mod service_rolledback; pub mod service_upgraded; -pub mod task_run_finished; -pub mod task_run_started; -pub mod test_case_run_finished; -pub mod test_case_run_queued; -pub mod test_case_run_started; -pub mod test_output_published; -pub mod test_suite_finished; -pub mod test_suite_run_queued; -pub mod test_suite_run_started; +pub mod taskrun_finished; +pub mod taskrun_started; +pub mod testcaserun_finished; +pub mod testcaserun_queued; +pub mod testcaserun_started; +pub mod testoutput_published; +pub mod testsuiterun_finished; +pub mod testsuiterun_queued; +pub mod testsuiterun_started; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; pub const ARTIFACT_PACKAGED: &str = "dev.cdevents.artifact.packaged.0.1.1"; pub const ARTIFACT_PUBLISHED: &str = "dev.cdevents.artifact.published.0.1.1"; @@ -63,9 +63,9 @@ pub const ENVIRONMENT_MODIFIED: &str = "dev.cdevents.environment.modified.0.1.1" pub const INCIDENT_DETECTED: &str = "dev.cdevents.incident.detected.0.1.0"; pub const INCIDENT_REPORTED: &str = "dev.cdevents.incident.reported.0.1.0"; pub const INCIDENT_RESOLVED: &str = "dev.cdevents.incident.resolved.0.1.0"; -pub const PIPELINE_RUN_FINISHED: &str = "dev.cdevents.pipelinerun.finished.0.1.1"; -pub const PIPELINE_RUN_QUEUED: &str = "dev.cdevents.pipelinerun.queued.0.1.1"; -pub const PIPELINE_RUN_STARTED: &str = "dev.cdevents.pipelinerun.started.0.1.1"; +pub const PIPELINERUN_FINISHED: &str = "dev.cdevents.pipelinerun.finished.0.1.1"; +pub const PIPELINERUN_QUEUED: &str = "dev.cdevents.pipelinerun.queued.0.1.1"; +pub const PIPELINERUN_STARTED: &str = "dev.cdevents.pipelinerun.started.0.1.1"; pub const REPOSITORY_CREATED: &str = "dev.cdevents.repository.created.0.1.1"; pub const REPOSITORY_DELETED: &str = "dev.cdevents.repository.deleted.0.1.1"; pub const REPOSITORY_MODIFIED: &str = "dev.cdevents.repository.modified.0.1.1"; @@ -74,17 +74,17 @@ pub const SERVICE_PUBLISHED: &str = "dev.cdevents.service.published.0.1.1"; pub const SERVICE_REMOVED: &str = "dev.cdevents.service.removed.0.1.1"; pub const SERVICE_ROLLEDBACK: &str = "dev.cdevents.service.rolledback.0.1.1"; pub const SERVICE_UPGRADED: &str = "dev.cdevents.service.upgraded.0.1.1"; -pub const TASK_RUN_FINISHED: &str = "dev.cdevents.taskrun.finished.0.1.1"; -pub const TASK_RUN_STARTED: &str = "dev.cdevents.taskrun.started.0.1.1"; -pub const TEST_CASE_RUN_FINISHED: &str = "dev.cdevents.testcaserun.finished.0.1.0"; -pub const TEST_CASE_RUN_QUEUED: &str = "dev.cdevents.testcaserun.queued.0.1.0"; -pub const TEST_CASE_RUN_STARTED: &str = "dev.cdevents.testcaserun.started.0.1.0"; -pub const TEST_OUTPUT_PUBLISHED: &str = "dev.cdevents.testoutput.published.0.1.0"; -pub const TEST_SUITE_FINISHED: &str = "dev.cdevents.testsuiterun.finished.0.1.0"; -pub const TEST_SUITE_RUN_QUEUED: &str = "dev.cdevents.testsuiterun.queued.0.1.0"; -pub const TEST_SUITE_RUN_STARTED: &str = "dev.cdevents.testsuiterun.started.0.1.0"; +pub const TASKRUN_FINISHED: &str = "dev.cdevents.taskrun.finished.0.1.1"; +pub const TASKRUN_STARTED: &str = "dev.cdevents.taskrun.started.0.1.1"; +pub const TESTCASERUN_FINISHED: &str = "dev.cdevents.testcaserun.finished.0.1.0"; +pub const TESTCASERUN_QUEUED: &str = "dev.cdevents.testcaserun.queued.0.1.0"; +pub const TESTCASERUN_STARTED: &str = "dev.cdevents.testcaserun.started.0.1.0"; +pub const TESTOUTPUT_PUBLISHED: &str = "dev.cdevents.testoutput.published.0.1.0"; +pub const TESTSUITERUN_FINISHED: &str = "dev.cdevents.testsuiterun.finished.0.1.0"; +pub const TESTSUITERUN_QUEUED: &str = "dev.cdevents.testsuiterun.queued.0.1.0"; +pub const TESTSUITERUN_STARTED: &str = "dev.cdevents.testsuiterun.started.0.1.0"; -#[derive(Debug,Clone,Serialize,Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(untagged)] // TODO how to use content of context.type as discriminator ? pub enum Content { ArtifactPackaged(artifact_packaged::Content), @@ -106,9 +106,9 @@ pub enum Content { IncidentDetected(incident_detected::Content), IncidentReported(incident_reported::Content), IncidentResolved(incident_resolved::Content), - PipelineRunFinished(pipeline_run_finished::Content), - PipelineRunQueued(pipeline_run_queued::Content), - PipelineRunStarted(pipeline_run_started::Content), + PipelinerunFinished(pipelinerun_finished::Content), + PipelinerunQueued(pipelinerun_queued::Content), + PipelinerunStarted(pipelinerun_started::Content), RepositoryCreated(repository_created::Content), RepositoryDeleted(repository_deleted::Content), RepositoryModified(repository_modified::Content), @@ -117,19 +117,19 @@ pub enum Content { ServiceRemoved(service_removed::Content), ServiceRolledback(service_rolledback::Content), ServiceUpgraded(service_upgraded::Content), - TaskRunFinished(task_run_finished::Content), - TaskRunStarted(task_run_started::Content), - TestCaseRunFinished(test_case_run_finished::Content), - TestCaseRunQueued(test_case_run_queued::Content), - TestCaseRunStarted(test_case_run_started::Content), - TestOutputPublished(test_output_published::Content), - TestSuiteFinished(test_suite_finished::Content), - TestSuiteRunQueued(test_suite_run_queued::Content), - TestSuiteRunStarted(test_suite_run_started::Content), + TaskrunFinished(taskrun_finished::Content), + TaskrunStarted(taskrun_started::Content), + TestcaserunFinished(testcaserun_finished::Content), + TestcaserunQueued(testcaserun_queued::Content), + TestcaserunStarted(testcaserun_started::Content), + TestoutputPublished(testoutput_published::Content), + TestsuiterunFinished(testsuiterun_finished::Content), + TestsuiterunQueued(testsuiterun_queued::Content), + TestsuiterunStarted(testsuiterun_started::Content), } impl Content { - pub fn from_json(ty: &str, json: serde_json::Value) -> Result{ + pub fn from_json(ty: &str, json: serde_json::Value) -> Result { match ty { ARTIFACT_PACKAGED => { let variant: artifact_packaged::Content = serde_json::from_value(json)?; @@ -207,17 +207,17 @@ impl Content { let variant: incident_resolved::Content = serde_json::from_value(json)?; Ok(Self::IncidentResolved(variant)) }, - PIPELINE_RUN_FINISHED => { - let variant: pipeline_run_finished::Content = serde_json::from_value(json)?; - Ok(Self::PipelineRunFinished(variant)) + PIPELINERUN_FINISHED => { + let variant: pipelinerun_finished::Content = serde_json::from_value(json)?; + Ok(Self::PipelinerunFinished(variant)) }, - PIPELINE_RUN_QUEUED => { - let variant: pipeline_run_queued::Content = serde_json::from_value(json)?; - Ok(Self::PipelineRunQueued(variant)) + PIPELINERUN_QUEUED => { + let variant: pipelinerun_queued::Content = serde_json::from_value(json)?; + Ok(Self::PipelinerunQueued(variant)) }, - PIPELINE_RUN_STARTED => { - let variant: pipeline_run_started::Content = serde_json::from_value(json)?; - Ok(Self::PipelineRunStarted(variant)) + PIPELINERUN_STARTED => { + let variant: pipelinerun_started::Content = serde_json::from_value(json)?; + Ok(Self::PipelinerunStarted(variant)) }, REPOSITORY_CREATED => { let variant: repository_created::Content = serde_json::from_value(json)?; @@ -251,41 +251,41 @@ impl Content { let variant: service_upgraded::Content = serde_json::from_value(json)?; Ok(Self::ServiceUpgraded(variant)) }, - TASK_RUN_FINISHED => { - let variant: task_run_finished::Content = serde_json::from_value(json)?; - Ok(Self::TaskRunFinished(variant)) + TASKRUN_FINISHED => { + let variant: taskrun_finished::Content = serde_json::from_value(json)?; + Ok(Self::TaskrunFinished(variant)) }, - TASK_RUN_STARTED => { - let variant: task_run_started::Content = serde_json::from_value(json)?; - Ok(Self::TaskRunStarted(variant)) + TASKRUN_STARTED => { + let variant: taskrun_started::Content = serde_json::from_value(json)?; + Ok(Self::TaskrunStarted(variant)) }, - TEST_CASE_RUN_FINISHED => { - let variant: test_case_run_finished::Content = serde_json::from_value(json)?; - Ok(Self::TestCaseRunFinished(variant)) + TESTCASERUN_FINISHED => { + let variant: testcaserun_finished::Content = serde_json::from_value(json)?; + Ok(Self::TestcaserunFinished(variant)) }, - TEST_CASE_RUN_QUEUED => { - let variant: test_case_run_queued::Content = serde_json::from_value(json)?; - Ok(Self::TestCaseRunQueued(variant)) + TESTCASERUN_QUEUED => { + let variant: testcaserun_queued::Content = serde_json::from_value(json)?; + Ok(Self::TestcaserunQueued(variant)) }, - TEST_CASE_RUN_STARTED => { - let variant: test_case_run_started::Content = serde_json::from_value(json)?; - Ok(Self::TestCaseRunStarted(variant)) + TESTCASERUN_STARTED => { + let variant: testcaserun_started::Content = serde_json::from_value(json)?; + Ok(Self::TestcaserunStarted(variant)) }, - TEST_OUTPUT_PUBLISHED => { - let variant: test_output_published::Content = serde_json::from_value(json)?; - Ok(Self::TestOutputPublished(variant)) + TESTOUTPUT_PUBLISHED => { + let variant: testoutput_published::Content = serde_json::from_value(json)?; + Ok(Self::TestoutputPublished(variant)) }, - TEST_SUITE_FINISHED => { - let variant: test_suite_finished::Content = serde_json::from_value(json)?; - Ok(Self::TestSuiteFinished(variant)) + TESTSUITERUN_FINISHED => { + let variant: testsuiterun_finished::Content = serde_json::from_value(json)?; + Ok(Self::TestsuiterunFinished(variant)) }, - TEST_SUITE_RUN_QUEUED => { - let variant: test_suite_run_queued::Content = serde_json::from_value(json)?; - Ok(Self::TestSuiteRunQueued(variant)) + TESTSUITERUN_QUEUED => { + let variant: testsuiterun_queued::Content = serde_json::from_value(json)?; + Ok(Self::TestsuiterunQueued(variant)) }, - TEST_SUITE_RUN_STARTED => { - let variant: test_suite_run_started::Content = serde_json::from_value(json)?; - Ok(Self::TestSuiteRunStarted(variant)) + TESTSUITERUN_STARTED => { + let variant: testsuiterun_started::Content = serde_json::from_value(json)?; + Ok(Self::TestsuiterunStarted(variant)) }, variant => Err(serde_json::Error::custom(format_args!( "unknown variant `{}`, expected 'dev.cdevents.{{subject}}.{{predicate}}.{{version}}'", diff --git a/cdevents-sdk/src/generated/pipeline_run_finished.rs b/cdevents-sdk/src/generated/pipelinerun_finished.rs similarity index 100% rename from cdevents-sdk/src/generated/pipeline_run_finished.rs rename to cdevents-sdk/src/generated/pipelinerun_finished.rs diff --git a/cdevents-sdk/src/generated/pipeline_run_queued.rs b/cdevents-sdk/src/generated/pipelinerun_queued.rs similarity index 100% rename from cdevents-sdk/src/generated/pipeline_run_queued.rs rename to cdevents-sdk/src/generated/pipelinerun_queued.rs diff --git a/cdevents-sdk/src/generated/pipeline_run_started.rs b/cdevents-sdk/src/generated/pipelinerun_started.rs similarity index 100% rename from cdevents-sdk/src/generated/pipeline_run_started.rs rename to cdevents-sdk/src/generated/pipelinerun_started.rs diff --git a/cdevents-sdk/src/generated/task_run_finished.rs b/cdevents-sdk/src/generated/taskrun_finished.rs similarity index 100% rename from cdevents-sdk/src/generated/task_run_finished.rs rename to cdevents-sdk/src/generated/taskrun_finished.rs diff --git a/cdevents-sdk/src/generated/task_run_started.rs b/cdevents-sdk/src/generated/taskrun_started.rs similarity index 100% rename from cdevents-sdk/src/generated/task_run_started.rs rename to cdevents-sdk/src/generated/taskrun_started.rs diff --git a/cdevents-sdk/src/generated/test_case_run_finished.rs b/cdevents-sdk/src/generated/testcaserun_finished.rs similarity index 100% rename from cdevents-sdk/src/generated/test_case_run_finished.rs rename to cdevents-sdk/src/generated/testcaserun_finished.rs diff --git a/cdevents-sdk/src/generated/test_case_run_queued.rs b/cdevents-sdk/src/generated/testcaserun_queued.rs similarity index 100% rename from cdevents-sdk/src/generated/test_case_run_queued.rs rename to cdevents-sdk/src/generated/testcaserun_queued.rs diff --git a/cdevents-sdk/src/generated/test_case_run_started.rs b/cdevents-sdk/src/generated/testcaserun_started.rs similarity index 100% rename from cdevents-sdk/src/generated/test_case_run_started.rs rename to cdevents-sdk/src/generated/testcaserun_started.rs diff --git a/cdevents-sdk/src/generated/test_output_published.rs b/cdevents-sdk/src/generated/testoutput_published.rs similarity index 100% rename from cdevents-sdk/src/generated/test_output_published.rs rename to cdevents-sdk/src/generated/testoutput_published.rs diff --git a/cdevents-sdk/src/generated/test_suite_finished.rs b/cdevents-sdk/src/generated/testsuiterun_finished.rs similarity index 100% rename from cdevents-sdk/src/generated/test_suite_finished.rs rename to cdevents-sdk/src/generated/testsuiterun_finished.rs diff --git a/cdevents-sdk/src/generated/test_suite_run_queued.rs b/cdevents-sdk/src/generated/testsuiterun_queued.rs similarity index 100% rename from cdevents-sdk/src/generated/test_suite_run_queued.rs rename to cdevents-sdk/src/generated/testsuiterun_queued.rs diff --git a/cdevents-sdk/src/generated/test_suite_run_started.rs b/cdevents-sdk/src/generated/testsuiterun_started.rs similarity index 100% rename from cdevents-sdk/src/generated/test_suite_run_started.rs rename to cdevents-sdk/src/generated/testsuiterun_started.rs diff --git a/generator/src/main.rs b/generator/src/main.rs index 885fd34..793af06 100644 --- a/generator/src/main.rs +++ b/generator/src/main.rs @@ -1,4 +1,4 @@ -use anyhow::{anyhow, Context, Result}; +use anyhow::{Context, Result}; use clap::Parser; use cruet::{to_class_case, Inflector}; use handlebars::{DirectorySourceOptions, Handlebars}; @@ -46,11 +46,7 @@ fn main() -> Result<()> { if let Some(extension) = path.extension() { if extension == "json" { let json: Value = serde_json::from_str(&std::fs::read_to_string(&path)?)?; - let context_type = json["properties"]["context"]["properties"]["type"]["default"] - .as_str() - .unwrap_or_default() - .to_string(); - let (rust_module, code) = generate_variant(&hbs, json) + let (rust_module, context_type, code) = generate_variant(&hbs, json) .with_context(|| format!("failed to generate variant on {:?}", &path))?; let file = settings .dest @@ -73,21 +69,30 @@ fn main() -> Result<()> { Ok(()) } -fn generate_variant(hbs: &Handlebars, jsonschema: Value) -> Result<(String, String)> { - let id = jsonschema["$id"] +fn generate_variant(hbs: &Handlebars, jsonschema: Value) -> Result<(String, String, String)> { + // let id = jsonschema["$id"] + // .as_str() + // .ok_or(anyhow!("$id not found or not a string")) + // .and_then(|s| url::Url::parse(s).with_context(|| format!("failed to parse: {}", s)))?; + // let module_name = id + // .path_segments() + // .and_then(|v| v.last()) + // .map(cruet::to_snake_case) + // .ok_or(anyhow!("no path in $id"))? + // .replace("_event", ""); + + // extract module's name from `context.type` (and not from `$id`) + let context_type = jsonschema["properties"]["context"]["properties"]["type"]["default"] .as_str() - .ok_or(anyhow!("$id not found or not a string")) - .and_then(|s| url::Url::parse(s).with_context(|| format!("failed to parse: {}", s)))?; - let module_name = id - .path_segments() - .and_then(|v| v.last()) - .map(cruet::to_snake_case) - .ok_or(anyhow!("no path in $id"))? - .replace("_event", ""); + .unwrap_or_default() + .to_string(); + + let fragments = context_type.split('.').collect::>(); + let module_name = format!("{}_{}", fragments[2], fragments[3]).to_snake_case(); let data = build_data_for_variants(jsonschema); let code = hbs.render("variant", &data)?; - Ok((module_name.to_string(), code)) + Ok((module_name.to_string(), context_type, code)) } fn generate_module(hbs: &Handlebars, variants: &[VariantInfo]) -> Result<(String, String)> { From 79551ca31dfcb5461565bb443c03f48bdfb13f25 Mon Sep 17 00:00:00 2001 From: David Bernard Date: Sun, 14 Jan 2024 19:32:08 +0100 Subject: [PATCH 08/34] feat: use more precise type for uri & datetime than String - uri => fluent_uri::Uri - uri-referece => fluent_uri::Uri - datetime => time::OffsetDateTime Signed-off-by: David Bernard --- cdevents-sdk/Cargo.toml | 6 +- cdevents-sdk/src/cdevent.rs | 98 ++++++++++ cdevents-sdk/src/context.rs | 13 ++ .../src/generated/artifact_packaged.rs | 12 +- .../src/generated/artifact_published.rs | 2 +- cdevents-sdk/src/generated/artifact_signed.rs | 4 +- cdevents-sdk/src/generated/branch_created.rs | 12 +- cdevents-sdk/src/generated/branch_deleted.rs | 12 +- cdevents-sdk/src/generated/build_finished.rs | 4 +- cdevents-sdk/src/generated/build_queued.rs | 2 +- cdevents-sdk/src/generated/build_started.rs | 2 +- .../src/generated/change_abandoned.rs | 12 +- cdevents-sdk/src/generated/change_created.rs | 12 +- cdevents-sdk/src/generated/change_merged.rs | 12 +- cdevents-sdk/src/generated/change_reviewed.rs | 12 +- cdevents-sdk/src/generated/change_updated.rs | 12 +- .../src/generated/environment_created.rs | 6 +- .../src/generated/environment_deleted.rs | 4 +- .../src/generated/environment_modified.rs | 6 +- .../src/generated/incident_detected.rs | 26 +-- .../src/generated/incident_reported.rs | 30 +-- .../src/generated/incident_resolved.rs | 26 +-- cdevents-sdk/src/generated/mod.rs | 6 +- .../src/generated/pipelinerun_finished.rs | 10 +- .../src/generated/pipelinerun_queued.rs | 6 +- .../src/generated/pipelinerun_started.rs | 6 +- .../src/generated/repository_created.rs | 10 +- .../src/generated/repository_deleted.rs | 10 +- .../src/generated/repository_modified.rs | 10 +- .../src/generated/service_deployed.rs | 14 +- .../src/generated/service_published.rs | 12 +- cdevents-sdk/src/generated/service_removed.rs | 12 +- .../src/generated/service_rolledback.rs | 14 +- .../src/generated/service_upgraded.rs | 14 +- .../src/generated/taskrun_finished.rs | 20 +- cdevents-sdk/src/generated/taskrun_started.rs | 16 +- .../src/generated/testcaserun_finished.rs | 42 ++--- .../src/generated/testcaserun_queued.rs | 46 ++--- .../src/generated/testcaserun_started.rs | 46 ++--- .../src/generated/testoutput_published.rs | 18 +- .../src/generated/testsuiterun_finished.rs | 32 ++-- .../src/generated/testsuiterun_queued.rs | 36 ++-- .../src/generated/testsuiterun_started.rs | 36 ++-- cdevents-sdk/src/lib.rs | 171 +----------------- cdevents-sdk/src/serde.rs | 77 ++++++++ cdevents-sdk/src/subject.rs | 43 +++++ cdevents-sdk/tests/specs.rs | 29 +++ generator/src/main.rs | 64 +++++-- generator/templates/mod.hbs | 2 +- generator/templates/variant.hbs | 11 +- 50 files changed, 642 insertions(+), 496 deletions(-) create mode 100644 cdevents-sdk/src/cdevent.rs create mode 100644 cdevents-sdk/src/context.rs create mode 100644 cdevents-sdk/src/serde.rs create mode 100644 cdevents-sdk/src/subject.rs create mode 100644 cdevents-sdk/tests/specs.rs diff --git a/cdevents-sdk/Cargo.toml b/cdevents-sdk/Cargo.toml index 117cc99..3df0ae8 100644 --- a/cdevents-sdk/Cargo.toml +++ b/cdevents-sdk/Cargo.toml @@ -11,9 +11,11 @@ publish = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -http = "1" -http-serde = "2" +# http = "1" # doesn't support uri-reference +# http-serde = "2" +fluent-uri = "0.1" serde = { version = "1.0", features = ["derive"] } +serde_with = "3.4" serde_json = "1.0" time = { version = "0.3", features = ["serde-human-readable"] } diff --git a/cdevents-sdk/src/cdevent.rs b/cdevents-sdk/src/cdevent.rs new file mode 100644 index 0000000..84ed810 --- /dev/null +++ b/cdevents-sdk/src/cdevent.rs @@ -0,0 +1,98 @@ +use crate::{Context, Subject}; +use serde::{ + de::{self, Deserializer, MapAccess, Visitor}, + Deserialize, Serialize, +}; +use std::fmt; + +#[derive(Debug, Clone, Serialize)] +pub struct CDEvent { + pub context: Context, + pub subject: Subject, + #[serde(rename = "customData", skip_serializing_if = "Option::is_none")] + pub custom_data: Option, + #[serde( + rename = "customDataContentType", + skip_serializing_if = "Option::is_none" + )] + pub custom_data_content_type: Option, +} + +impl<'de> Deserialize<'de> for CDEvent { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + #[derive(Deserialize)] + #[serde(field_identifier, rename_all = "camelCase")] + enum Field { + Context, + Subject, + CustomData, + CustomDataContentType, + } + + struct CDEventVisitor; + + impl<'de> Visitor<'de> for CDEventVisitor { + type Value = CDEvent; + + fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + formatter.write_str("struct CDEvent") + } + + fn visit_map(self, mut map: V) -> Result + where + V: MapAccess<'de>, + { + let mut context: Option = None; + let mut subject_json: Option = None; + let mut custom_data = None; + let mut custom_data_content_type = None; + while let Some(key) = map.next_key()? { + match key { + Field::Context => { + if context.is_some() { + return Err(de::Error::duplicate_field("context")); + } + context = Some(map.next_value()?); + } + Field::Subject => { + if subject_json.is_some() { + return Err(de::Error::duplicate_field("subject")); + } + subject_json = Some(map.next_value()?); + } + Field::CustomData => { + if custom_data.is_some() { + return Err(de::Error::duplicate_field("customData")); + } + custom_data = Some(map.next_value()?); + } + Field::CustomDataContentType => { + if custom_data_content_type.is_some() { + return Err(de::Error::duplicate_field("customDataContentType")); + } + custom_data_content_type = Some(map.next_value()?); + } + } + } + let context = context.ok_or_else(|| de::Error::missing_field("context"))?; + let subject_json = + subject_json.ok_or_else(|| de::Error::missing_field("subject"))?; + let subject = + Subject::from_json(&context.r#type, subject_json).map_err(de::Error::custom)?; + + Ok(CDEvent { + context, + subject, + custom_data, + custom_data_content_type, + }) + } + } + + const FIELDS: &'static [&'static str] = &["context", "subject"]; + deserializer.deserialize_struct("CDEvent", FIELDS, CDEventVisitor) + } +} diff --git a/cdevents-sdk/src/context.rs b/cdevents-sdk/src/context.rs new file mode 100644 index 0000000..e54d022 --- /dev/null +++ b/cdevents-sdk/src/context.rs @@ -0,0 +1,13 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Context { + pub version: String, + pub id: String, + #[serde(with = "crate::serde::uri_reference")] + pub source: fluent_uri::Uri, + #[serde(rename = "type")] + pub r#type: String, + #[serde(with = "crate::serde::datetime")] + pub timestamp: time::OffsetDateTime, +} diff --git a/cdevents-sdk/src/generated/artifact_packaged.rs b/cdevents-sdk/src/generated/artifact_packaged.rs index 460a266..481a3e9 100644 --- a/cdevents-sdk/src/generated/artifact_packaged.rs +++ b/cdevents-sdk/src/generated/artifact_packaged.rs @@ -1,17 +1,17 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Content { - #[serde(rename = "change")] + #[serde(rename = "change",)] pub change: Change, } -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Change { - #[serde(rename = "id")] + #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] + pub source: Option>, } diff --git a/cdevents-sdk/src/generated/artifact_published.rs b/cdevents-sdk/src/generated/artifact_published.rs index 4367d0a..afc7ec5 100644 --- a/cdevents-sdk/src/generated/artifact_published.rs +++ b/cdevents-sdk/src/generated/artifact_published.rs @@ -1,7 +1,7 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Content { } diff --git a/cdevents-sdk/src/generated/artifact_signed.rs b/cdevents-sdk/src/generated/artifact_signed.rs index 0876c99..a57374f 100644 --- a/cdevents-sdk/src/generated/artifact_signed.rs +++ b/cdevents-sdk/src/generated/artifact_signed.rs @@ -1,9 +1,9 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Content { - #[serde(rename = "signature")] + #[serde(rename = "signature",)] pub signature: String, } diff --git a/cdevents-sdk/src/generated/branch_created.rs b/cdevents-sdk/src/generated/branch_created.rs index 6a21b4d..203a406 100644 --- a/cdevents-sdk/src/generated/branch_created.rs +++ b/cdevents-sdk/src/generated/branch_created.rs @@ -1,17 +1,17 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Content { - #[serde(rename = "repository", skip_serializing_if = "Option::is_none")] + #[serde(rename = "repository", default, skip_serializing_if = "Option::is_none",)] pub repository: Option, } -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Repository { - #[serde(rename = "id")] + #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] + pub source: Option>, } diff --git a/cdevents-sdk/src/generated/branch_deleted.rs b/cdevents-sdk/src/generated/branch_deleted.rs index 6a21b4d..203a406 100644 --- a/cdevents-sdk/src/generated/branch_deleted.rs +++ b/cdevents-sdk/src/generated/branch_deleted.rs @@ -1,17 +1,17 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Content { - #[serde(rename = "repository", skip_serializing_if = "Option::is_none")] + #[serde(rename = "repository", default, skip_serializing_if = "Option::is_none",)] pub repository: Option, } -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Repository { - #[serde(rename = "id")] + #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] + pub source: Option>, } diff --git a/cdevents-sdk/src/generated/build_finished.rs b/cdevents-sdk/src/generated/build_finished.rs index 6a27785..dd28b25 100644 --- a/cdevents-sdk/src/generated/build_finished.rs +++ b/cdevents-sdk/src/generated/build_finished.rs @@ -1,9 +1,9 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Content { - #[serde(rename = "artifactId", skip_serializing_if = "Option::is_none")] + #[serde(rename = "artifactId", default, skip_serializing_if = "Option::is_none",)] pub artifact_id: Option, } diff --git a/cdevents-sdk/src/generated/build_queued.rs b/cdevents-sdk/src/generated/build_queued.rs index 4367d0a..afc7ec5 100644 --- a/cdevents-sdk/src/generated/build_queued.rs +++ b/cdevents-sdk/src/generated/build_queued.rs @@ -1,7 +1,7 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Content { } diff --git a/cdevents-sdk/src/generated/build_started.rs b/cdevents-sdk/src/generated/build_started.rs index 4367d0a..afc7ec5 100644 --- a/cdevents-sdk/src/generated/build_started.rs +++ b/cdevents-sdk/src/generated/build_started.rs @@ -1,7 +1,7 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Content { } diff --git a/cdevents-sdk/src/generated/change_abandoned.rs b/cdevents-sdk/src/generated/change_abandoned.rs index 6a21b4d..203a406 100644 --- a/cdevents-sdk/src/generated/change_abandoned.rs +++ b/cdevents-sdk/src/generated/change_abandoned.rs @@ -1,17 +1,17 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Content { - #[serde(rename = "repository", skip_serializing_if = "Option::is_none")] + #[serde(rename = "repository", default, skip_serializing_if = "Option::is_none",)] pub repository: Option, } -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Repository { - #[serde(rename = "id")] + #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] + pub source: Option>, } diff --git a/cdevents-sdk/src/generated/change_created.rs b/cdevents-sdk/src/generated/change_created.rs index 6a21b4d..203a406 100644 --- a/cdevents-sdk/src/generated/change_created.rs +++ b/cdevents-sdk/src/generated/change_created.rs @@ -1,17 +1,17 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Content { - #[serde(rename = "repository", skip_serializing_if = "Option::is_none")] + #[serde(rename = "repository", default, skip_serializing_if = "Option::is_none",)] pub repository: Option, } -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Repository { - #[serde(rename = "id")] + #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] + pub source: Option>, } diff --git a/cdevents-sdk/src/generated/change_merged.rs b/cdevents-sdk/src/generated/change_merged.rs index 6a21b4d..203a406 100644 --- a/cdevents-sdk/src/generated/change_merged.rs +++ b/cdevents-sdk/src/generated/change_merged.rs @@ -1,17 +1,17 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Content { - #[serde(rename = "repository", skip_serializing_if = "Option::is_none")] + #[serde(rename = "repository", default, skip_serializing_if = "Option::is_none",)] pub repository: Option, } -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Repository { - #[serde(rename = "id")] + #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] + pub source: Option>, } diff --git a/cdevents-sdk/src/generated/change_reviewed.rs b/cdevents-sdk/src/generated/change_reviewed.rs index 6a21b4d..203a406 100644 --- a/cdevents-sdk/src/generated/change_reviewed.rs +++ b/cdevents-sdk/src/generated/change_reviewed.rs @@ -1,17 +1,17 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Content { - #[serde(rename = "repository", skip_serializing_if = "Option::is_none")] + #[serde(rename = "repository", default, skip_serializing_if = "Option::is_none",)] pub repository: Option, } -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Repository { - #[serde(rename = "id")] + #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] + pub source: Option>, } diff --git a/cdevents-sdk/src/generated/change_updated.rs b/cdevents-sdk/src/generated/change_updated.rs index 6a21b4d..203a406 100644 --- a/cdevents-sdk/src/generated/change_updated.rs +++ b/cdevents-sdk/src/generated/change_updated.rs @@ -1,17 +1,17 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Content { - #[serde(rename = "repository", skip_serializing_if = "Option::is_none")] + #[serde(rename = "repository", default, skip_serializing_if = "Option::is_none",)] pub repository: Option, } -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Repository { - #[serde(rename = "id")] + #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] + pub source: Option>, } diff --git a/cdevents-sdk/src/generated/environment_created.rs b/cdevents-sdk/src/generated/environment_created.rs index 5efe460..9e7e3bd 100644 --- a/cdevents-sdk/src/generated/environment_created.rs +++ b/cdevents-sdk/src/generated/environment_created.rs @@ -1,11 +1,11 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Content { - #[serde(rename = "name", skip_serializing_if = "Option::is_none")] + #[serde(rename = "name", default, skip_serializing_if = "Option::is_none",)] pub name: Option, - #[serde(rename = "url", skip_serializing_if = "Option::is_none")] + #[serde(rename = "url", default, skip_serializing_if = "Option::is_none",)] pub url: Option, } diff --git a/cdevents-sdk/src/generated/environment_deleted.rs b/cdevents-sdk/src/generated/environment_deleted.rs index 1e25b81..0ed9572 100644 --- a/cdevents-sdk/src/generated/environment_deleted.rs +++ b/cdevents-sdk/src/generated/environment_deleted.rs @@ -1,9 +1,9 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Content { - #[serde(rename = "name", skip_serializing_if = "Option::is_none")] + #[serde(rename = "name", default, skip_serializing_if = "Option::is_none",)] pub name: Option, } diff --git a/cdevents-sdk/src/generated/environment_modified.rs b/cdevents-sdk/src/generated/environment_modified.rs index 5efe460..9e7e3bd 100644 --- a/cdevents-sdk/src/generated/environment_modified.rs +++ b/cdevents-sdk/src/generated/environment_modified.rs @@ -1,11 +1,11 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Content { - #[serde(rename = "name", skip_serializing_if = "Option::is_none")] + #[serde(rename = "name", default, skip_serializing_if = "Option::is_none",)] pub name: Option, - #[serde(rename = "url", skip_serializing_if = "Option::is_none")] + #[serde(rename = "url", default, skip_serializing_if = "Option::is_none",)] pub url: Option, } diff --git a/cdevents-sdk/src/generated/incident_detected.rs b/cdevents-sdk/src/generated/incident_detected.rs index a444e59..21c52e9 100644 --- a/cdevents-sdk/src/generated/incident_detected.rs +++ b/cdevents-sdk/src/generated/incident_detected.rs @@ -1,31 +1,31 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Content { - #[serde(rename = "artifactId", skip_serializing_if = "Option::is_none")] + #[serde(rename = "artifactId", default, skip_serializing_if = "Option::is_none",)] pub artifact_id: Option, - #[serde(rename = "description", skip_serializing_if = "Option::is_none")] + #[serde(rename = "description", default, skip_serializing_if = "Option::is_none",)] pub description: Option, - #[serde(rename = "environment")] + #[serde(rename = "environment",)] pub environment: Environment, - #[serde(rename = "service", skip_serializing_if = "Option::is_none")] + #[serde(rename = "service", default, skip_serializing_if = "Option::is_none",)] pub service: Option, } -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Service { - #[serde(rename = "id")] + #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] + pub source: Option>, } -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Environment { - #[serde(rename = "id")] + #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] + pub source: Option>, } diff --git a/cdevents-sdk/src/generated/incident_reported.rs b/cdevents-sdk/src/generated/incident_reported.rs index 43ed85d..19789d8 100644 --- a/cdevents-sdk/src/generated/incident_reported.rs +++ b/cdevents-sdk/src/generated/incident_reported.rs @@ -1,33 +1,33 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Content { - #[serde(rename = "artifactId", skip_serializing_if = "Option::is_none")] + #[serde(rename = "artifactId", default, skip_serializing_if = "Option::is_none",)] pub artifact_id: Option, - #[serde(rename = "description", skip_serializing_if = "Option::is_none")] + #[serde(rename = "description", default, skip_serializing_if = "Option::is_none",)] pub description: Option, - #[serde(rename = "environment")] + #[serde(rename = "environment",)] pub environment: Environment, - #[serde(rename = "service", skip_serializing_if = "Option::is_none")] + #[serde(rename = "service", default, skip_serializing_if = "Option::is_none",)] pub service: Option, - #[serde(rename = "ticketURI")] - pub ticket_uri: String, + #[serde(rename = "ticketURI", with = "crate::serde::uri",)] + pub ticket_uri: fluent_uri::Uri, } -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Service { - #[serde(rename = "id")] + #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] + pub source: Option>, } -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Environment { - #[serde(rename = "id")] + #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] + pub source: Option>, } diff --git a/cdevents-sdk/src/generated/incident_resolved.rs b/cdevents-sdk/src/generated/incident_resolved.rs index a444e59..21c52e9 100644 --- a/cdevents-sdk/src/generated/incident_resolved.rs +++ b/cdevents-sdk/src/generated/incident_resolved.rs @@ -1,31 +1,31 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Content { - #[serde(rename = "artifactId", skip_serializing_if = "Option::is_none")] + #[serde(rename = "artifactId", default, skip_serializing_if = "Option::is_none",)] pub artifact_id: Option, - #[serde(rename = "description", skip_serializing_if = "Option::is_none")] + #[serde(rename = "description", default, skip_serializing_if = "Option::is_none",)] pub description: Option, - #[serde(rename = "environment")] + #[serde(rename = "environment",)] pub environment: Environment, - #[serde(rename = "service", skip_serializing_if = "Option::is_none")] + #[serde(rename = "service", default, skip_serializing_if = "Option::is_none",)] pub service: Option, } -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Service { - #[serde(rename = "id")] + #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] + pub source: Option>, } -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Environment { - #[serde(rename = "id")] + #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] + pub source: Option>, } diff --git a/cdevents-sdk/src/generated/mod.rs b/cdevents-sdk/src/generated/mod.rs index 879534f..c49590a 100644 --- a/cdevents-sdk/src/generated/mod.rs +++ b/cdevents-sdk/src/generated/mod.rs @@ -42,7 +42,7 @@ pub mod testsuiterun_finished; pub mod testsuiterun_queued; pub mod testsuiterun_started; -use serde::{Deserialize, Serialize}; +use serde::{Serialize, Deserialize}; pub const ARTIFACT_PACKAGED: &str = "dev.cdevents.artifact.packaged.0.1.1"; pub const ARTIFACT_PUBLISHED: &str = "dev.cdevents.artifact.published.0.1.1"; @@ -84,7 +84,7 @@ pub const TESTSUITERUN_FINISHED: &str = "dev.cdevents.testsuiterun.finished.0.1. pub const TESTSUITERUN_QUEUED: &str = "dev.cdevents.testsuiterun.queued.0.1.0"; pub const TESTSUITERUN_STARTED: &str = "dev.cdevents.testsuiterun.started.0.1.0"; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug,Clone,Serialize,Deserialize)] #[serde(untagged)] // TODO how to use content of context.type as discriminator ? pub enum Content { ArtifactPackaged(artifact_packaged::Content), @@ -129,7 +129,7 @@ pub enum Content { } impl Content { - pub fn from_json(ty: &str, json: serde_json::Value) -> Result { + pub fn from_json(ty: &str, json: serde_json::Value) -> Result{ match ty { ARTIFACT_PACKAGED => { let variant: artifact_packaged::Content = serde_json::from_value(json)?; diff --git a/cdevents-sdk/src/generated/pipelinerun_finished.rs b/cdevents-sdk/src/generated/pipelinerun_finished.rs index 56c979f..91302b0 100644 --- a/cdevents-sdk/src/generated/pipelinerun_finished.rs +++ b/cdevents-sdk/src/generated/pipelinerun_finished.rs @@ -1,15 +1,15 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Content { - #[serde(rename = "errors", skip_serializing_if = "Option::is_none")] + #[serde(rename = "errors", default, skip_serializing_if = "Option::is_none",)] pub errors: Option, - #[serde(rename = "outcome", skip_serializing_if = "Option::is_none")] + #[serde(rename = "outcome", default, skip_serializing_if = "Option::is_none",)] pub outcome: Option, - #[serde(rename = "pipelineName", skip_serializing_if = "Option::is_none")] + #[serde(rename = "pipelineName", default, skip_serializing_if = "Option::is_none",)] pub pipeline_name: Option, - #[serde(rename = "url", skip_serializing_if = "Option::is_none")] + #[serde(rename = "url", default, skip_serializing_if = "Option::is_none",)] pub url: Option, } diff --git a/cdevents-sdk/src/generated/pipelinerun_queued.rs b/cdevents-sdk/src/generated/pipelinerun_queued.rs index 1885da8..3a79f47 100644 --- a/cdevents-sdk/src/generated/pipelinerun_queued.rs +++ b/cdevents-sdk/src/generated/pipelinerun_queued.rs @@ -1,11 +1,11 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Content { - #[serde(rename = "pipelineName", skip_serializing_if = "Option::is_none")] + #[serde(rename = "pipelineName", default, skip_serializing_if = "Option::is_none",)] pub pipeline_name: Option, - #[serde(rename = "url", skip_serializing_if = "Option::is_none")] + #[serde(rename = "url", default, skip_serializing_if = "Option::is_none",)] pub url: Option, } diff --git a/cdevents-sdk/src/generated/pipelinerun_started.rs b/cdevents-sdk/src/generated/pipelinerun_started.rs index d832d1b..8c27f88 100644 --- a/cdevents-sdk/src/generated/pipelinerun_started.rs +++ b/cdevents-sdk/src/generated/pipelinerun_started.rs @@ -1,11 +1,11 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Content { - #[serde(rename = "pipelineName")] + #[serde(rename = "pipelineName",)] pub pipeline_name: String, - #[serde(rename = "url")] + #[serde(rename = "url",)] pub url: String, } diff --git a/cdevents-sdk/src/generated/repository_created.rs b/cdevents-sdk/src/generated/repository_created.rs index 9ca92ef..168050b 100644 --- a/cdevents-sdk/src/generated/repository_created.rs +++ b/cdevents-sdk/src/generated/repository_created.rs @@ -1,15 +1,15 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Content { - #[serde(rename = "name")] + #[serde(rename = "name",)] pub name: String, - #[serde(rename = "owner", skip_serializing_if = "Option::is_none")] + #[serde(rename = "owner", default, skip_serializing_if = "Option::is_none",)] pub owner: Option, - #[serde(rename = "url")] + #[serde(rename = "url",)] pub url: String, - #[serde(rename = "viewUrl", skip_serializing_if = "Option::is_none")] + #[serde(rename = "viewUrl", default, skip_serializing_if = "Option::is_none",)] pub view_url: Option, } diff --git a/cdevents-sdk/src/generated/repository_deleted.rs b/cdevents-sdk/src/generated/repository_deleted.rs index faac696..16bd662 100644 --- a/cdevents-sdk/src/generated/repository_deleted.rs +++ b/cdevents-sdk/src/generated/repository_deleted.rs @@ -1,15 +1,15 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Content { - #[serde(rename = "name", skip_serializing_if = "Option::is_none")] + #[serde(rename = "name", default, skip_serializing_if = "Option::is_none",)] pub name: Option, - #[serde(rename = "owner", skip_serializing_if = "Option::is_none")] + #[serde(rename = "owner", default, skip_serializing_if = "Option::is_none",)] pub owner: Option, - #[serde(rename = "url", skip_serializing_if = "Option::is_none")] + #[serde(rename = "url", default, skip_serializing_if = "Option::is_none",)] pub url: Option, - #[serde(rename = "viewUrl", skip_serializing_if = "Option::is_none")] + #[serde(rename = "viewUrl", default, skip_serializing_if = "Option::is_none",)] pub view_url: Option, } diff --git a/cdevents-sdk/src/generated/repository_modified.rs b/cdevents-sdk/src/generated/repository_modified.rs index faac696..16bd662 100644 --- a/cdevents-sdk/src/generated/repository_modified.rs +++ b/cdevents-sdk/src/generated/repository_modified.rs @@ -1,15 +1,15 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Content { - #[serde(rename = "name", skip_serializing_if = "Option::is_none")] + #[serde(rename = "name", default, skip_serializing_if = "Option::is_none",)] pub name: Option, - #[serde(rename = "owner", skip_serializing_if = "Option::is_none")] + #[serde(rename = "owner", default, skip_serializing_if = "Option::is_none",)] pub owner: Option, - #[serde(rename = "url", skip_serializing_if = "Option::is_none")] + #[serde(rename = "url", default, skip_serializing_if = "Option::is_none",)] pub url: Option, - #[serde(rename = "viewUrl", skip_serializing_if = "Option::is_none")] + #[serde(rename = "viewUrl", default, skip_serializing_if = "Option::is_none",)] pub view_url: Option, } diff --git a/cdevents-sdk/src/generated/service_deployed.rs b/cdevents-sdk/src/generated/service_deployed.rs index 11ac67f..40f0f34 100644 --- a/cdevents-sdk/src/generated/service_deployed.rs +++ b/cdevents-sdk/src/generated/service_deployed.rs @@ -1,19 +1,19 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Content { - #[serde(rename = "artifactId")] + #[serde(rename = "artifactId",)] pub artifact_id: String, - #[serde(rename = "environment")] + #[serde(rename = "environment",)] pub environment: Environment, } -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Environment { - #[serde(rename = "id")] + #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] + pub source: Option>, } diff --git a/cdevents-sdk/src/generated/service_published.rs b/cdevents-sdk/src/generated/service_published.rs index 64a31e3..b4571ed 100644 --- a/cdevents-sdk/src/generated/service_published.rs +++ b/cdevents-sdk/src/generated/service_published.rs @@ -1,17 +1,17 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Content { - #[serde(rename = "environment", skip_serializing_if = "Option::is_none")] + #[serde(rename = "environment", default, skip_serializing_if = "Option::is_none",)] pub environment: Option, } -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Environment { - #[serde(rename = "id")] + #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] + pub source: Option>, } diff --git a/cdevents-sdk/src/generated/service_removed.rs b/cdevents-sdk/src/generated/service_removed.rs index 64a31e3..b4571ed 100644 --- a/cdevents-sdk/src/generated/service_removed.rs +++ b/cdevents-sdk/src/generated/service_removed.rs @@ -1,17 +1,17 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Content { - #[serde(rename = "environment", skip_serializing_if = "Option::is_none")] + #[serde(rename = "environment", default, skip_serializing_if = "Option::is_none",)] pub environment: Option, } -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Environment { - #[serde(rename = "id")] + #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] + pub source: Option>, } diff --git a/cdevents-sdk/src/generated/service_rolledback.rs b/cdevents-sdk/src/generated/service_rolledback.rs index 11ac67f..40f0f34 100644 --- a/cdevents-sdk/src/generated/service_rolledback.rs +++ b/cdevents-sdk/src/generated/service_rolledback.rs @@ -1,19 +1,19 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Content { - #[serde(rename = "artifactId")] + #[serde(rename = "artifactId",)] pub artifact_id: String, - #[serde(rename = "environment")] + #[serde(rename = "environment",)] pub environment: Environment, } -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Environment { - #[serde(rename = "id")] + #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] + pub source: Option>, } diff --git a/cdevents-sdk/src/generated/service_upgraded.rs b/cdevents-sdk/src/generated/service_upgraded.rs index 11ac67f..40f0f34 100644 --- a/cdevents-sdk/src/generated/service_upgraded.rs +++ b/cdevents-sdk/src/generated/service_upgraded.rs @@ -1,19 +1,19 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Content { - #[serde(rename = "artifactId")] + #[serde(rename = "artifactId",)] pub artifact_id: String, - #[serde(rename = "environment")] + #[serde(rename = "environment",)] pub environment: Environment, } -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Environment { - #[serde(rename = "id")] + #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] + pub source: Option>, } diff --git a/cdevents-sdk/src/generated/taskrun_finished.rs b/cdevents-sdk/src/generated/taskrun_finished.rs index 247873c..f1bdb00 100644 --- a/cdevents-sdk/src/generated/taskrun_finished.rs +++ b/cdevents-sdk/src/generated/taskrun_finished.rs @@ -1,25 +1,25 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Content { - #[serde(rename = "errors", skip_serializing_if = "Option::is_none")] + #[serde(rename = "errors", default, skip_serializing_if = "Option::is_none",)] pub errors: Option, - #[serde(rename = "outcome", skip_serializing_if = "Option::is_none")] + #[serde(rename = "outcome", default, skip_serializing_if = "Option::is_none",)] pub outcome: Option, - #[serde(rename = "pipelineRun", skip_serializing_if = "Option::is_none")] + #[serde(rename = "pipelineRun", default, skip_serializing_if = "Option::is_none",)] pub pipeline_run: Option, - #[serde(rename = "taskName", skip_serializing_if = "Option::is_none")] + #[serde(rename = "taskName", default, skip_serializing_if = "Option::is_none",)] pub task_name: Option, - #[serde(rename = "url", skip_serializing_if = "Option::is_none")] + #[serde(rename = "url", default, skip_serializing_if = "Option::is_none",)] pub url: Option, } -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct PipelineRun { - #[serde(rename = "id")] + #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] + pub source: Option>, } diff --git a/cdevents-sdk/src/generated/taskrun_started.rs b/cdevents-sdk/src/generated/taskrun_started.rs index 92089fd..6c703a6 100644 --- a/cdevents-sdk/src/generated/taskrun_started.rs +++ b/cdevents-sdk/src/generated/taskrun_started.rs @@ -1,21 +1,21 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Content { - #[serde(rename = "pipelineRun", skip_serializing_if = "Option::is_none")] + #[serde(rename = "pipelineRun", default, skip_serializing_if = "Option::is_none",)] pub pipeline_run: Option, - #[serde(rename = "taskName", skip_serializing_if = "Option::is_none")] + #[serde(rename = "taskName", default, skip_serializing_if = "Option::is_none",)] pub task_name: Option, - #[serde(rename = "url", skip_serializing_if = "Option::is_none")] + #[serde(rename = "url", default, skip_serializing_if = "Option::is_none",)] pub url: Option, } -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct PipelineRun { - #[serde(rename = "id")] + #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] + pub source: Option>, } diff --git a/cdevents-sdk/src/generated/testcaserun_finished.rs b/cdevents-sdk/src/generated/testcaserun_finished.rs index c42bdbc..0abaaff 100644 --- a/cdevents-sdk/src/generated/testcaserun_finished.rs +++ b/cdevents-sdk/src/generated/testcaserun_finished.rs @@ -1,49 +1,49 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Content { - #[serde(rename = "environment")] + #[serde(rename = "environment",)] pub environment: Environment, - #[serde(rename = "outcome")] + #[serde(rename = "outcome",)] pub outcome: String, - #[serde(rename = "reason", skip_serializing_if = "Option::is_none")] + #[serde(rename = "reason", default, skip_serializing_if = "Option::is_none",)] pub reason: Option, - #[serde(rename = "severity", skip_serializing_if = "Option::is_none")] + #[serde(rename = "severity", default, skip_serializing_if = "Option::is_none",)] pub severity: Option, - #[serde(rename = "testCase", skip_serializing_if = "Option::is_none")] + #[serde(rename = "testCase", default, skip_serializing_if = "Option::is_none",)] pub test_case: Option, - #[serde(rename = "testSuiteRun", skip_serializing_if = "Option::is_none")] + #[serde(rename = "testSuiteRun", default, skip_serializing_if = "Option::is_none",)] pub test_suite_run: Option, } -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct TestSuiteRun { - #[serde(rename = "id")] + #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct TestCase { - #[serde(rename = "id")] + #[serde(rename = "id",)] pub id: String, - #[serde(rename = "name", skip_serializing_if = "Option::is_none")] + #[serde(rename = "name", default, skip_serializing_if = "Option::is_none",)] pub name: Option, - #[serde(rename = "type", skip_serializing_if = "Option::is_none")] + #[serde(rename = "type", default, skip_serializing_if = "Option::is_none",)] pub r#type: Option, - #[serde(rename = "uri", skip_serializing_if = "Option::is_none")] - pub uri: Option, - #[serde(rename = "version", skip_serializing_if = "Option::is_none")] + #[serde(rename = "uri", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_optional",)] + pub uri: Option>, + #[serde(rename = "version", default, skip_serializing_if = "Option::is_none",)] pub version: Option, } -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Environment { - #[serde(rename = "id")] + #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] + pub source: Option>, } diff --git a/cdevents-sdk/src/generated/testcaserun_queued.rs b/cdevents-sdk/src/generated/testcaserun_queued.rs index 00c2194..dcdd6a9 100644 --- a/cdevents-sdk/src/generated/testcaserun_queued.rs +++ b/cdevents-sdk/src/generated/testcaserun_queued.rs @@ -1,53 +1,53 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Content { - #[serde(rename = "environment")] + #[serde(rename = "environment",)] pub environment: Environment, - #[serde(rename = "testCase", skip_serializing_if = "Option::is_none")] + #[serde(rename = "testCase", default, skip_serializing_if = "Option::is_none",)] pub test_case: Option, - #[serde(rename = "testSuiteRun", skip_serializing_if = "Option::is_none")] + #[serde(rename = "testSuiteRun", default, skip_serializing_if = "Option::is_none",)] pub test_suite_run: Option, - #[serde(rename = "trigger", skip_serializing_if = "Option::is_none")] + #[serde(rename = "trigger", default, skip_serializing_if = "Option::is_none",)] pub trigger: Option, } -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Trigger { - #[serde(rename = "type", skip_serializing_if = "Option::is_none")] + #[serde(rename = "type", default, skip_serializing_if = "Option::is_none",)] pub r#type: Option, - #[serde(rename = "uri", skip_serializing_if = "Option::is_none")] - pub uri: Option, + #[serde(rename = "uri", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_optional",)] + pub uri: Option>, } -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct TestSuiteRun { - #[serde(rename = "id")] + #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct TestCase { - #[serde(rename = "id")] + #[serde(rename = "id",)] pub id: String, - #[serde(rename = "name", skip_serializing_if = "Option::is_none")] + #[serde(rename = "name", default, skip_serializing_if = "Option::is_none",)] pub name: Option, - #[serde(rename = "type", skip_serializing_if = "Option::is_none")] + #[serde(rename = "type", default, skip_serializing_if = "Option::is_none",)] pub r#type: Option, - #[serde(rename = "uri", skip_serializing_if = "Option::is_none")] - pub uri: Option, - #[serde(rename = "version", skip_serializing_if = "Option::is_none")] + #[serde(rename = "uri", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_optional",)] + pub uri: Option>, + #[serde(rename = "version", default, skip_serializing_if = "Option::is_none",)] pub version: Option, } -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Environment { - #[serde(rename = "id")] + #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] + pub source: Option>, } diff --git a/cdevents-sdk/src/generated/testcaserun_started.rs b/cdevents-sdk/src/generated/testcaserun_started.rs index 00c2194..dcdd6a9 100644 --- a/cdevents-sdk/src/generated/testcaserun_started.rs +++ b/cdevents-sdk/src/generated/testcaserun_started.rs @@ -1,53 +1,53 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Content { - #[serde(rename = "environment")] + #[serde(rename = "environment",)] pub environment: Environment, - #[serde(rename = "testCase", skip_serializing_if = "Option::is_none")] + #[serde(rename = "testCase", default, skip_serializing_if = "Option::is_none",)] pub test_case: Option, - #[serde(rename = "testSuiteRun", skip_serializing_if = "Option::is_none")] + #[serde(rename = "testSuiteRun", default, skip_serializing_if = "Option::is_none",)] pub test_suite_run: Option, - #[serde(rename = "trigger", skip_serializing_if = "Option::is_none")] + #[serde(rename = "trigger", default, skip_serializing_if = "Option::is_none",)] pub trigger: Option, } -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Trigger { - #[serde(rename = "type", skip_serializing_if = "Option::is_none")] + #[serde(rename = "type", default, skip_serializing_if = "Option::is_none",)] pub r#type: Option, - #[serde(rename = "uri", skip_serializing_if = "Option::is_none")] - pub uri: Option, + #[serde(rename = "uri", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_optional",)] + pub uri: Option>, } -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct TestSuiteRun { - #[serde(rename = "id")] + #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct TestCase { - #[serde(rename = "id")] + #[serde(rename = "id",)] pub id: String, - #[serde(rename = "name", skip_serializing_if = "Option::is_none")] + #[serde(rename = "name", default, skip_serializing_if = "Option::is_none",)] pub name: Option, - #[serde(rename = "type", skip_serializing_if = "Option::is_none")] + #[serde(rename = "type", default, skip_serializing_if = "Option::is_none",)] pub r#type: Option, - #[serde(rename = "uri", skip_serializing_if = "Option::is_none")] - pub uri: Option, - #[serde(rename = "version", skip_serializing_if = "Option::is_none")] + #[serde(rename = "uri", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_optional",)] + pub uri: Option>, + #[serde(rename = "version", default, skip_serializing_if = "Option::is_none",)] pub version: Option, } -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Environment { - #[serde(rename = "id")] + #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] + pub source: Option>, } diff --git a/cdevents-sdk/src/generated/testoutput_published.rs b/cdevents-sdk/src/generated/testoutput_published.rs index 56eb4e6..f12c6ec 100644 --- a/cdevents-sdk/src/generated/testoutput_published.rs +++ b/cdevents-sdk/src/generated/testoutput_published.rs @@ -1,23 +1,23 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Content { - #[serde(rename = "format")] + #[serde(rename = "format",)] pub format: String, - #[serde(rename = "outputType")] + #[serde(rename = "outputType",)] pub output_type: String, - #[serde(rename = "testCaseRun", skip_serializing_if = "Option::is_none")] + #[serde(rename = "testCaseRun", default, skip_serializing_if = "Option::is_none",)] pub test_case_run: Option, - #[serde(rename = "uri", skip_serializing_if = "Option::is_none")] - pub uri: Option, + #[serde(rename = "uri", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_optional",)] + pub uri: Option>, } -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct TestCaseRun { - #[serde(rename = "id")] + #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } diff --git a/cdevents-sdk/src/generated/testsuiterun_finished.rs b/cdevents-sdk/src/generated/testsuiterun_finished.rs index 923e301..5f3f6b8 100644 --- a/cdevents-sdk/src/generated/testsuiterun_finished.rs +++ b/cdevents-sdk/src/generated/testsuiterun_finished.rs @@ -1,37 +1,37 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Content { - #[serde(rename = "environment")] + #[serde(rename = "environment",)] pub environment: Environment, - #[serde(rename = "outcome")] + #[serde(rename = "outcome",)] pub outcome: String, - #[serde(rename = "reason", skip_serializing_if = "Option::is_none")] + #[serde(rename = "reason", default, skip_serializing_if = "Option::is_none",)] pub reason: Option, - #[serde(rename = "severity", skip_serializing_if = "Option::is_none")] + #[serde(rename = "severity", default, skip_serializing_if = "Option::is_none",)] pub severity: Option, - #[serde(rename = "testSuite", skip_serializing_if = "Option::is_none")] + #[serde(rename = "testSuite", default, skip_serializing_if = "Option::is_none",)] pub test_suite: Option, } -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct TestSuite { - #[serde(rename = "id")] + #[serde(rename = "id",)] pub id: String, - #[serde(rename = "name", skip_serializing_if = "Option::is_none")] + #[serde(rename = "name", default, skip_serializing_if = "Option::is_none",)] pub name: Option, - #[serde(rename = "uri", skip_serializing_if = "Option::is_none")] - pub uri: Option, - #[serde(rename = "version", skip_serializing_if = "Option::is_none")] + #[serde(rename = "uri", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_optional",)] + pub uri: Option>, + #[serde(rename = "version", default, skip_serializing_if = "Option::is_none",)] pub version: Option, } -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Environment { - #[serde(rename = "id")] + #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] + pub source: Option>, } diff --git a/cdevents-sdk/src/generated/testsuiterun_queued.rs b/cdevents-sdk/src/generated/testsuiterun_queued.rs index 6a42577..9c74cb2 100644 --- a/cdevents-sdk/src/generated/testsuiterun_queued.rs +++ b/cdevents-sdk/src/generated/testsuiterun_queued.rs @@ -1,41 +1,41 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Content { - #[serde(rename = "environment")] + #[serde(rename = "environment",)] pub environment: Environment, - #[serde(rename = "testSuite", skip_serializing_if = "Option::is_none")] + #[serde(rename = "testSuite", default, skip_serializing_if = "Option::is_none",)] pub test_suite: Option, - #[serde(rename = "trigger", skip_serializing_if = "Option::is_none")] + #[serde(rename = "trigger", default, skip_serializing_if = "Option::is_none",)] pub trigger: Option, } -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Trigger { - #[serde(rename = "type", skip_serializing_if = "Option::is_none")] + #[serde(rename = "type", default, skip_serializing_if = "Option::is_none",)] pub r#type: Option, - #[serde(rename = "uri", skip_serializing_if = "Option::is_none")] - pub uri: Option, + #[serde(rename = "uri", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_optional",)] + pub uri: Option>, } -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct TestSuite { - #[serde(rename = "id")] + #[serde(rename = "id",)] pub id: String, - #[serde(rename = "name", skip_serializing_if = "Option::is_none")] + #[serde(rename = "name", default, skip_serializing_if = "Option::is_none",)] pub name: Option, - #[serde(rename = "url", skip_serializing_if = "Option::is_none")] - pub url: Option, - #[serde(rename = "version", skip_serializing_if = "Option::is_none")] + #[serde(rename = "url", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_optional",)] + pub url: Option>, + #[serde(rename = "version", default, skip_serializing_if = "Option::is_none",)] pub version: Option, } -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Environment { - #[serde(rename = "id")] + #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] + pub source: Option>, } diff --git a/cdevents-sdk/src/generated/testsuiterun_started.rs b/cdevents-sdk/src/generated/testsuiterun_started.rs index 63ce7db..b028508 100644 --- a/cdevents-sdk/src/generated/testsuiterun_started.rs +++ b/cdevents-sdk/src/generated/testsuiterun_started.rs @@ -1,41 +1,41 @@ // code generated by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Content { - #[serde(rename = "environment")] + #[serde(rename = "environment",)] pub environment: Environment, - #[serde(rename = "testSuite", skip_serializing_if = "Option::is_none")] + #[serde(rename = "testSuite", default, skip_serializing_if = "Option::is_none",)] pub test_suite: Option, - #[serde(rename = "trigger", skip_serializing_if = "Option::is_none")] + #[serde(rename = "trigger", default, skip_serializing_if = "Option::is_none",)] pub trigger: Option, } -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Trigger { - #[serde(rename = "type", skip_serializing_if = "Option::is_none")] + #[serde(rename = "type", default, skip_serializing_if = "Option::is_none",)] pub r#type: Option, - #[serde(rename = "uri", skip_serializing_if = "Option::is_none")] - pub uri: Option, + #[serde(rename = "uri", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_optional",)] + pub uri: Option>, } -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct TestSuite { - #[serde(rename = "id")] + #[serde(rename = "id",)] pub id: String, - #[serde(rename = "name", skip_serializing_if = "Option::is_none")] + #[serde(rename = "name", default, skip_serializing_if = "Option::is_none",)] pub name: Option, - #[serde(rename = "uri", skip_serializing_if = "Option::is_none")] - pub uri: Option, - #[serde(rename = "version", skip_serializing_if = "Option::is_none")] + #[serde(rename = "uri", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_optional",)] + pub uri: Option>, + #[serde(rename = "version", default, skip_serializing_if = "Option::is_none",)] pub version: Option, } -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Environment { - #[serde(rename = "id")] + #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] + pub source: Option>, } diff --git a/cdevents-sdk/src/lib.rs b/cdevents-sdk/src/lib.rs index caca2dd..d4be46c 100644 --- a/cdevents-sdk/src/lib.rs +++ b/cdevents-sdk/src/lib.rs @@ -1,169 +1,12 @@ // TODO remove unwrap(), expect(...) // TODO reduce clone() +mod cdevent; +mod context; mod generated; +pub(crate) mod serde; +mod subject; +pub use cdevent::*; +pub use context::*; pub use generated::*; -use serde::{ - de::{self, Deserializer, MapAccess, Visitor}, - Deserialize, Serialize, -}; -use std::fmt; - -#[derive(Debug, Clone, Serialize, PartialEq, Eq)] -pub struct CDEvent { - pub context: Context, - pub subject: Subject, - #[serde(rename = "customData", skip_serializing_if = "Option::is_none")] - pub custom_data: Option, - #[serde( - rename = "customDataContentType", - skip_serializing_if = "Option::is_none" - )] - pub custom_data_content_type: Option, -} - -impl<'de> Deserialize<'de> for CDEvent { - fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'de>, - { - #[derive(Deserialize)] - #[serde(field_identifier, rename_all = "camelCase")] - enum Field { - Context, - Subject, - CustomData, - CustomDataContentType, - } - - struct CDEventVisitor; - - impl<'de> Visitor<'de> for CDEventVisitor { - type Value = CDEvent; - - fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - formatter.write_str("struct CDEvent") - } - - fn visit_map(self, mut map: V) -> Result - where - V: MapAccess<'de>, - { - let mut context: Option = None; - let mut subject_json: Option = None; - let mut custom_data = None; - let mut custom_data_content_type = None; - while let Some(key) = map.next_key()? { - match key { - Field::Context => { - if context.is_some() { - return Err(de::Error::duplicate_field("context")); - } - context = Some(map.next_value()?); - } - Field::Subject => { - if subject_json.is_some() { - return Err(de::Error::duplicate_field("subject")); - } - subject_json = Some(map.next_value()?); - } - Field::CustomData => { - if custom_data.is_some() { - return Err(de::Error::duplicate_field("customData")); - } - custom_data = Some(map.next_value()?); - } - Field::CustomDataContentType => { - if custom_data_content_type.is_some() { - return Err(de::Error::duplicate_field("customDataContentType")); - } - custom_data_content_type = Some(map.next_value()?); - } - } - } - let context = context.ok_or_else(|| de::Error::missing_field("context"))?; - let subject_json = - subject_json.ok_or_else(|| de::Error::missing_field("subject"))?; - let subject = - Subject::from_json(&context.r#type, subject_json).map_err(de::Error::custom)?; - - Ok(CDEvent { - context, - subject, - custom_data, - custom_data_content_type, - }) - } - } - - const FIELDS: &'static [&'static str] = &["context", "subject"]; - deserializer.deserialize_struct("CDEvent", FIELDS, CDEventVisitor) - } -} - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Context { - version: String, - id: String, - #[serde(with = "http_serde::uri")] - source: http::Uri, - #[serde(rename = "type")] - r#type: String, - #[serde(with = "time::serde::rfc3339")] - timestamp: time::OffsetDateTime, -} - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct Subject { - #[serde(rename = "content")] - pub content: Content, - #[serde(rename = "id")] - pub id: String, - #[serde(rename = "source", skip_serializing_if = "Option::is_none")] - pub source: Option, - #[serde(rename = "type")] - pub r#type: String, -} - -impl Subject { - pub fn from_json(ty: &str, json: serde_json::Value) -> Result { - Ok(Subject { - id: json["id"] - .as_str() - .ok_or_else(|| serde::de::Error::missing_field("id"))? - .to_string(), - r#type: json["type"] - .as_str() - .ok_or_else(|| serde::de::Error::missing_field("type"))? - .to_string(), - source: json["source"].as_str().map(|s| s.to_string()), - content: Content::from_json(ty, json["content"].clone())?, - }) - } -} - -#[cfg(test)] -mod tests { - use super::*; - use assert_json_diff::assert_json_eq; - use rstest::rstest; - use std::fs; - use std::path::PathBuf; - - #[rstest] - fn for_each_example(#[files("../cdevents-spec/examples/*.json")] path: PathBuf) { - let example_json: serde_json::Value = serde_json::from_str( - fs::read_to_string(&path) - .expect("to read file as string") - .as_str(), - ) - .expect("to parse as json"); - dbg!(&example_json); - let cdevent: CDEvent = - serde_json::from_value(example_json.clone()).expect("to parse as cdevent"); - dbg!(&cdevent); - let cdevent_json = serde_json::to_value(cdevent).expect("to convert into json"); - dbg!(&cdevent_json); - assert_json_eq!(example_json, cdevent_json); - } -} +pub use subject::*; diff --git a/cdevents-sdk/src/serde.rs b/cdevents-sdk/src/serde.rs new file mode 100644 index 0000000..b0eca8a --- /dev/null +++ b/cdevents-sdk/src/serde.rs @@ -0,0 +1,77 @@ +// currently there is no generic way to handle Option +// 2 alertnatives: +// - write custom serializer +// - try to use the crate serde_with (serde_as) +// +// Creating, aliasing module with custom (de)serializer, +// also simplify the generation and introduce a small layer of abstraction/documentation. +// +// see [Using de/serialize\_with inside of an Option, Map, Vec · Issue #723 · serde-rs/serde](https://github.com/serde-rs/serde/issues/723) + +pub(crate) mod datetime { + use serde::{Deserializer, Serializer}; + + pub fn deserialize<'de, D>(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + time::serde::rfc3339::deserialize(deserializer) + } + + pub fn serialize(input: &time::OffsetDateTime, serializer: S) -> Result + where + S: Serializer, + { + time::serde::rfc3339::serialize(input, serializer) + } +} + +pub(crate) use uri_reference as uri; +pub(crate) use uri_reference_optional as uri_optional; + +pub(crate) mod uri_reference_optional { + use serde::{Deserialize, Deserializer, Serializer}; + + #[derive(Deserialize)] + struct Wrapper(#[serde(with = "crate::serde::uri_reference")] fluent_uri::Uri); + + pub fn deserialize<'de, D>(deserializer: D) -> Result>, D::Error> + where + D: Deserializer<'de>, + { + let v = Option::deserialize(deserializer)?; + Ok(v.map(|Wrapper(a)| a)) + } + + pub fn serialize( + input: &Option>, + serializer: S, + ) -> Result + where + S: Serializer, + { + match input { + None => serializer.serialize_none(), + Some(input) => crate::serde::uri_reference::serialize(input, serializer), + } + } +} + +pub(crate) mod uri_reference { + use serde::{de::Error, Deserialize, Deserializer, Serializer}; + + pub fn deserialize<'de, D>(deserializer: D) -> Result, D::Error> + where + D: Deserializer<'de>, + { + let txt = String::deserialize(deserializer)?; + fluent_uri::Uri::parse_from(txt).map_err(|e| D::Error::custom(e.1)) + } + + pub fn serialize(input: &fluent_uri::Uri, serializer: S) -> Result + where + S: Serializer, + { + serializer.collect_str(input.as_str()) + } +} diff --git a/cdevents-sdk/src/subject.rs b/cdevents-sdk/src/subject.rs new file mode 100644 index 0000000..314ab4e --- /dev/null +++ b/cdevents-sdk/src/subject.rs @@ -0,0 +1,43 @@ +use serde::{Deserialize, Serialize}; + +use crate::Content; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Subject { + #[serde(rename = "content")] + pub content: Content, + #[serde(rename = "id")] + pub id: String, + #[serde( + rename = "source", + default, + skip_serializing_if = "Option::is_none", + with = "crate::serde::uri_reference_optional" + )] + pub source: Option>, + #[serde(rename = "type")] + pub r#type: String, +} + +impl Subject { + pub fn from_json(ty: &str, json: serde_json::Value) -> Result { + Ok(Subject { + id: json["id"] + .as_str() + .ok_or_else(|| serde::de::Error::missing_field("id"))? + .to_string(), + r#type: json["type"] + .as_str() + .ok_or_else(|| serde::de::Error::missing_field("type"))? + .to_string(), + source: match json["source"].as_str() { + None => None, + Some(s) => Some( + fluent_uri::Uri::parse_from(s.to_owned()) + .map_err(|e| serde::de::Error::custom(e.1))?, + ), + }, + content: Content::from_json(ty, json["content"].clone())?, + }) + } +} diff --git a/cdevents-sdk/tests/specs.rs b/cdevents-sdk/tests/specs.rs new file mode 100644 index 0000000..3bab7d8 --- /dev/null +++ b/cdevents-sdk/tests/specs.rs @@ -0,0 +1,29 @@ +use assert_json_diff::assert_json_eq; +use cdevents_sdk::CDEvent; +use rstest::rstest; +use std::fs; +use std::path::PathBuf; + +#[rstest] +fn for_each_example(#[files("../cdevents-spec/examples/*.json")] path: PathBuf) { + let example_txt = fs::read_to_string(&path).expect("to read file as string"); + //HACK uri are stored ad http::Uri, they are "normalized" when serialized, so prenormalization to avoid failure like + // json atoms at path ".subject.content.repository.source" are not equal: + // lhs: + // "https://example.org" + // rhs: + // "https://example.org/" + // But it's not the case with fluent_uri::Uri + // + // example_txt = example_txt.replace("\"https://example.org\"", "\"https://example.org/\""); + + let example_json: serde_json::Value = + serde_json::from_str(&example_txt).expect("to parse as json"); + dbg!(&example_json); + let cdevent: CDEvent = + serde_json::from_value(example_json.clone()).expect("to parse as cdevent"); + dbg!(&cdevent); + let cdevent_json = serde_json::to_value(cdevent).expect("to convert into json"); + dbg!(&cdevent_json); + assert_json_eq!(example_json, cdevent_json); +} diff --git a/generator/src/main.rs b/generator/src/main.rs index 793af06..2be652f 100644 --- a/generator/src/main.rs +++ b/generator/src/main.rs @@ -1,6 +1,6 @@ use anyhow::{Context, Result}; use clap::Parser; -use cruet::{to_class_case, Inflector}; +use cruet::Inflector; use handlebars::{DirectorySourceOptions, Handlebars}; use serde::{Deserialize, Serialize}; use serde_json::{json, Value}; @@ -118,7 +118,11 @@ fn build_data_for_variants(jsonschema: Value) -> Value { }) } -type RustTypeName = String; +#[derive(Debug, Clone, Serialize, Deserialize, Default)] +struct TypeInfo { + type_declaration: String, + serde_with: Option, +} #[derive(Debug, Clone, Serialize, Deserialize)] struct VariantInfo { @@ -128,7 +132,7 @@ struct VariantInfo { #[derive(Debug, Clone, Serialize, Deserialize)] struct StructDef { - type_name: RustTypeName, + type_info: TypeInfo, json_definition: Value, fields: Vec, } @@ -137,7 +141,7 @@ struct StructDef { struct FieldDef { rust_name: String, serde_name: String, - type_name: RustTypeName, + type_info: TypeInfo, is_optional: bool, } @@ -145,11 +149,41 @@ fn collect_structs( structs: &mut Vec, field_name: &str, json_definition: &Value, -) -> RustTypeName { +) -> TypeInfo { match json_definition["type"].as_str() { - Some("string") => "String".to_string(), + Some("string") => match json_definition["format"].as_str() { + Some("date-time") => TypeInfo { + type_declaration: "time::OffsetDateTime".to_string(), + serde_with: Some("crate::serde::datetime".to_string()), + ..Default::default() + }, + //TODO manage purl + Some("uri-reference") => TypeInfo { + type_declaration: "fluent_uri::Uri".to_string(), + serde_with: Some("crate::serde::uri_reference".to_string()), + ..Default::default() + }, + Some("uri") => TypeInfo { + type_declaration: "fluent_uri::Uri".to_string(), + serde_with: Some("crate::serde::uri".to_string()), + ..Default::default() + }, + // Some("uri") => TypeInfo { + // type_declaration: "http::Uri".to_string(), + // serde_with: Some("crate::serde::uri".to_string()), + // ..Default::default() + // }, + //TODO manage enum + _ => TypeInfo { + type_declaration: "String".to_string(), + ..Default::default() + }, + }, Some("object") => match json_definition["properties"].as_object() { - None => "serde_json::Map".to_string(), + None => TypeInfo { + type_declaration: "serde_json::Map".to_string(), + ..Default::default() + }, Some(fields_kv) => { let required = json_definition["required"].as_array(); let fields = fields_kv @@ -161,28 +195,32 @@ fn collect_structs( } else { serde_name.to_snake_case() }; - let mut type_name = collect_structs(structs, &serde_name, field.1); + let mut type_info = collect_structs(structs, &serde_name, field.1); let field_name = json!(&serde_name); let is_optional = required.map(|a| !a.contains(&field_name)).unwrap_or(true); if is_optional { - type_name = format!("Option<{}>", type_name); + type_info.type_declaration = + format!("Option<{}>", type_info.type_declaration); } FieldDef { rust_name, serde_name, - type_name, + type_info, is_optional, } }) .collect::>(); - let type_name = to_class_case(field_name); + let type_info = TypeInfo { + type_declaration: field_name.to_class_case(), + ..Default::default() + }; structs.push(StructDef { - type_name: type_name.clone(), + type_info: type_info.clone(), fields, json_definition: json_definition.clone(), }); - type_name + type_info } }, Some(x) => todo!("impl for type='{}'", x), diff --git a/generator/templates/mod.hbs b/generator/templates/mod.hbs index c918aff..8244a10 100644 --- a/generator/templates/mod.hbs +++ b/generator/templates/mod.hbs @@ -12,7 +12,7 @@ use serde::{Serialize, Deserialize}; pub const {{to_screaming_snake_case this.rust_module}}: &str = "{{ this.context_type }}"; {{/each}} -#[derive(Debug,Clone,Serialize,Deserialize, PartialEq, Eq)] +#[derive(Debug,Clone,Serialize,Deserialize)] #[serde(untagged)] // TODO how to use content of context.type as discriminator ? pub enum Content { {{#each variants }} diff --git a/generator/templates/variant.hbs b/generator/templates/variant.hbs index 6854e7d..41a7a25 100644 --- a/generator/templates/variant.hbs +++ b/generator/templates/variant.hbs @@ -2,11 +2,14 @@ use serde::{Serialize, Deserialize}; {{#each structs }} -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -pub struct {{ this.type_name }} { +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct {{ this.type_info.type_declaration }} { {{#each this.fields }} - #[serde(rename = "{{ this.serde_name }}"{{#if this.is_optional }}, skip_serializing_if = "Option::is_none"{{/if}})] - pub {{ this.rust_name }}: {{this.type_name }}, + #[serde(rename = "{{ this.serde_name }}", + {{~#if this.is_optional }} default, skip_serializing_if = "Option::is_none",{{/if~}} + {{~#if this.type_info.serde_with }} with = "{{ this.type_info.serde_with }}{{#if this.is_optional }}_optional{{/if}}",{{/if~}} + )] + pub {{ this.rust_name }}: {{this.type_info.type_declaration }}, {{/each}} } From 1428d4825d716393f80472eb28dc60949456c8b3 Mon Sep 17 00:00:00 2001 From: David Bernard Date: Sun, 14 Jan 2024 19:50:06 +0100 Subject: [PATCH 09/34] build(deps): remove useless "serde_with" Signed-off-by: David Bernard --- cdevents-sdk/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/cdevents-sdk/Cargo.toml b/cdevents-sdk/Cargo.toml index 3df0ae8..85df285 100644 --- a/cdevents-sdk/Cargo.toml +++ b/cdevents-sdk/Cargo.toml @@ -15,7 +15,6 @@ publish = true # http-serde = "2" fluent-uri = "0.1" serde = { version = "1.0", features = ["derive"] } -serde_with = "3.4" serde_json = "1.0" time = { version = "0.3", features = ["serde-human-readable"] } From 479cb5d4686c579fb559f7e0662a00b904c138de Mon Sep 17 00:00:00 2001 From: David Bernard Date: Sun, 14 Jan 2024 20:59:32 +0100 Subject: [PATCH 10/34] build: enable deny_unknown_fields Signed-off-by: David Bernard --- cdevents-sdk/src/cdevent.rs | 1 + cdevents-sdk/src/context.rs | 1 + cdevents-sdk/src/generated/artifact_packaged.rs | 2 ++ cdevents-sdk/src/generated/artifact_published.rs | 1 + cdevents-sdk/src/generated/artifact_signed.rs | 1 + cdevents-sdk/src/generated/branch_created.rs | 2 ++ cdevents-sdk/src/generated/branch_deleted.rs | 2 ++ cdevents-sdk/src/generated/build_finished.rs | 1 + cdevents-sdk/src/generated/build_queued.rs | 1 + cdevents-sdk/src/generated/build_started.rs | 1 + cdevents-sdk/src/generated/change_abandoned.rs | 2 ++ cdevents-sdk/src/generated/change_created.rs | 2 ++ cdevents-sdk/src/generated/change_merged.rs | 2 ++ cdevents-sdk/src/generated/change_reviewed.rs | 2 ++ cdevents-sdk/src/generated/change_updated.rs | 2 ++ cdevents-sdk/src/generated/environment_created.rs | 1 + cdevents-sdk/src/generated/environment_deleted.rs | 1 + cdevents-sdk/src/generated/environment_modified.rs | 1 + cdevents-sdk/src/generated/incident_detected.rs | 3 +++ cdevents-sdk/src/generated/incident_reported.rs | 3 +++ cdevents-sdk/src/generated/incident_resolved.rs | 3 +++ cdevents-sdk/src/generated/pipelinerun_finished.rs | 1 + cdevents-sdk/src/generated/pipelinerun_queued.rs | 1 + cdevents-sdk/src/generated/pipelinerun_started.rs | 1 + cdevents-sdk/src/generated/repository_created.rs | 1 + cdevents-sdk/src/generated/repository_deleted.rs | 1 + cdevents-sdk/src/generated/repository_modified.rs | 1 + cdevents-sdk/src/generated/service_deployed.rs | 2 ++ cdevents-sdk/src/generated/service_published.rs | 2 ++ cdevents-sdk/src/generated/service_removed.rs | 2 ++ cdevents-sdk/src/generated/service_rolledback.rs | 2 ++ cdevents-sdk/src/generated/service_upgraded.rs | 2 ++ cdevents-sdk/src/generated/taskrun_finished.rs | 2 ++ cdevents-sdk/src/generated/taskrun_started.rs | 2 ++ cdevents-sdk/src/generated/testcaserun_finished.rs | 4 ++++ cdevents-sdk/src/generated/testcaserun_queued.rs | 5 +++++ cdevents-sdk/src/generated/testcaserun_started.rs | 5 +++++ cdevents-sdk/src/generated/testoutput_published.rs | 2 ++ cdevents-sdk/src/generated/testsuiterun_finished.rs | 3 +++ cdevents-sdk/src/generated/testsuiterun_queued.rs | 4 ++++ cdevents-sdk/src/generated/testsuiterun_started.rs | 4 ++++ cdevents-sdk/src/subject.rs | 1 + generator/templates/variant.hbs | 1 + 43 files changed, 84 insertions(+) diff --git a/cdevents-sdk/src/cdevent.rs b/cdevents-sdk/src/cdevent.rs index 84ed810..24a25f2 100644 --- a/cdevents-sdk/src/cdevent.rs +++ b/cdevents-sdk/src/cdevent.rs @@ -6,6 +6,7 @@ use serde::{ use std::fmt; #[derive(Debug, Clone, Serialize)] +#[serde(deny_unknown_fields)] pub struct CDEvent { pub context: Context, pub subject: Subject, diff --git a/cdevents-sdk/src/context.rs b/cdevents-sdk/src/context.rs index e54d022..be3d836 100644 --- a/cdevents-sdk/src/context.rs +++ b/cdevents-sdk/src/context.rs @@ -1,6 +1,7 @@ use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Context { pub version: String, pub id: String, diff --git a/cdevents-sdk/src/generated/artifact_packaged.rs b/cdevents-sdk/src/generated/artifact_packaged.rs index 481a3e9..859a013 100644 --- a/cdevents-sdk/src/generated/artifact_packaged.rs +++ b/cdevents-sdk/src/generated/artifact_packaged.rs @@ -2,12 +2,14 @@ use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "change",)] pub change: Change, } #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Change { #[serde(rename = "id",)] pub id: String, diff --git a/cdevents-sdk/src/generated/artifact_published.rs b/cdevents-sdk/src/generated/artifact_published.rs index afc7ec5..e922b9a 100644 --- a/cdevents-sdk/src/generated/artifact_published.rs +++ b/cdevents-sdk/src/generated/artifact_published.rs @@ -2,6 +2,7 @@ use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Content { } diff --git a/cdevents-sdk/src/generated/artifact_signed.rs b/cdevents-sdk/src/generated/artifact_signed.rs index a57374f..ff40f63 100644 --- a/cdevents-sdk/src/generated/artifact_signed.rs +++ b/cdevents-sdk/src/generated/artifact_signed.rs @@ -2,6 +2,7 @@ use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "signature",)] pub signature: String, diff --git a/cdevents-sdk/src/generated/branch_created.rs b/cdevents-sdk/src/generated/branch_created.rs index 203a406..a6f4c7e 100644 --- a/cdevents-sdk/src/generated/branch_created.rs +++ b/cdevents-sdk/src/generated/branch_created.rs @@ -2,12 +2,14 @@ use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "repository", default, skip_serializing_if = "Option::is_none",)] pub repository: Option, } #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Repository { #[serde(rename = "id",)] pub id: String, diff --git a/cdevents-sdk/src/generated/branch_deleted.rs b/cdevents-sdk/src/generated/branch_deleted.rs index 203a406..a6f4c7e 100644 --- a/cdevents-sdk/src/generated/branch_deleted.rs +++ b/cdevents-sdk/src/generated/branch_deleted.rs @@ -2,12 +2,14 @@ use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "repository", default, skip_serializing_if = "Option::is_none",)] pub repository: Option, } #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Repository { #[serde(rename = "id",)] pub id: String, diff --git a/cdevents-sdk/src/generated/build_finished.rs b/cdevents-sdk/src/generated/build_finished.rs index dd28b25..87618d7 100644 --- a/cdevents-sdk/src/generated/build_finished.rs +++ b/cdevents-sdk/src/generated/build_finished.rs @@ -2,6 +2,7 @@ use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "artifactId", default, skip_serializing_if = "Option::is_none",)] pub artifact_id: Option, diff --git a/cdevents-sdk/src/generated/build_queued.rs b/cdevents-sdk/src/generated/build_queued.rs index afc7ec5..e922b9a 100644 --- a/cdevents-sdk/src/generated/build_queued.rs +++ b/cdevents-sdk/src/generated/build_queued.rs @@ -2,6 +2,7 @@ use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Content { } diff --git a/cdevents-sdk/src/generated/build_started.rs b/cdevents-sdk/src/generated/build_started.rs index afc7ec5..e922b9a 100644 --- a/cdevents-sdk/src/generated/build_started.rs +++ b/cdevents-sdk/src/generated/build_started.rs @@ -2,6 +2,7 @@ use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Content { } diff --git a/cdevents-sdk/src/generated/change_abandoned.rs b/cdevents-sdk/src/generated/change_abandoned.rs index 203a406..a6f4c7e 100644 --- a/cdevents-sdk/src/generated/change_abandoned.rs +++ b/cdevents-sdk/src/generated/change_abandoned.rs @@ -2,12 +2,14 @@ use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "repository", default, skip_serializing_if = "Option::is_none",)] pub repository: Option, } #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Repository { #[serde(rename = "id",)] pub id: String, diff --git a/cdevents-sdk/src/generated/change_created.rs b/cdevents-sdk/src/generated/change_created.rs index 203a406..a6f4c7e 100644 --- a/cdevents-sdk/src/generated/change_created.rs +++ b/cdevents-sdk/src/generated/change_created.rs @@ -2,12 +2,14 @@ use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "repository", default, skip_serializing_if = "Option::is_none",)] pub repository: Option, } #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Repository { #[serde(rename = "id",)] pub id: String, diff --git a/cdevents-sdk/src/generated/change_merged.rs b/cdevents-sdk/src/generated/change_merged.rs index 203a406..a6f4c7e 100644 --- a/cdevents-sdk/src/generated/change_merged.rs +++ b/cdevents-sdk/src/generated/change_merged.rs @@ -2,12 +2,14 @@ use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "repository", default, skip_serializing_if = "Option::is_none",)] pub repository: Option, } #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Repository { #[serde(rename = "id",)] pub id: String, diff --git a/cdevents-sdk/src/generated/change_reviewed.rs b/cdevents-sdk/src/generated/change_reviewed.rs index 203a406..a6f4c7e 100644 --- a/cdevents-sdk/src/generated/change_reviewed.rs +++ b/cdevents-sdk/src/generated/change_reviewed.rs @@ -2,12 +2,14 @@ use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "repository", default, skip_serializing_if = "Option::is_none",)] pub repository: Option, } #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Repository { #[serde(rename = "id",)] pub id: String, diff --git a/cdevents-sdk/src/generated/change_updated.rs b/cdevents-sdk/src/generated/change_updated.rs index 203a406..a6f4c7e 100644 --- a/cdevents-sdk/src/generated/change_updated.rs +++ b/cdevents-sdk/src/generated/change_updated.rs @@ -2,12 +2,14 @@ use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "repository", default, skip_serializing_if = "Option::is_none",)] pub repository: Option, } #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Repository { #[serde(rename = "id",)] pub id: String, diff --git a/cdevents-sdk/src/generated/environment_created.rs b/cdevents-sdk/src/generated/environment_created.rs index 9e7e3bd..62de02f 100644 --- a/cdevents-sdk/src/generated/environment_created.rs +++ b/cdevents-sdk/src/generated/environment_created.rs @@ -2,6 +2,7 @@ use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "name", default, skip_serializing_if = "Option::is_none",)] pub name: Option, diff --git a/cdevents-sdk/src/generated/environment_deleted.rs b/cdevents-sdk/src/generated/environment_deleted.rs index 0ed9572..028edac 100644 --- a/cdevents-sdk/src/generated/environment_deleted.rs +++ b/cdevents-sdk/src/generated/environment_deleted.rs @@ -2,6 +2,7 @@ use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "name", default, skip_serializing_if = "Option::is_none",)] pub name: Option, diff --git a/cdevents-sdk/src/generated/environment_modified.rs b/cdevents-sdk/src/generated/environment_modified.rs index 9e7e3bd..62de02f 100644 --- a/cdevents-sdk/src/generated/environment_modified.rs +++ b/cdevents-sdk/src/generated/environment_modified.rs @@ -2,6 +2,7 @@ use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "name", default, skip_serializing_if = "Option::is_none",)] pub name: Option, diff --git a/cdevents-sdk/src/generated/incident_detected.rs b/cdevents-sdk/src/generated/incident_detected.rs index 21c52e9..93ca1d7 100644 --- a/cdevents-sdk/src/generated/incident_detected.rs +++ b/cdevents-sdk/src/generated/incident_detected.rs @@ -2,6 +2,7 @@ use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "artifactId", default, skip_serializing_if = "Option::is_none",)] pub artifact_id: Option, @@ -14,6 +15,7 @@ pub struct Content { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Service { #[serde(rename = "id",)] pub id: String, @@ -22,6 +24,7 @@ pub struct Service { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Environment { #[serde(rename = "id",)] pub id: String, diff --git a/cdevents-sdk/src/generated/incident_reported.rs b/cdevents-sdk/src/generated/incident_reported.rs index 19789d8..3a3a152 100644 --- a/cdevents-sdk/src/generated/incident_reported.rs +++ b/cdevents-sdk/src/generated/incident_reported.rs @@ -2,6 +2,7 @@ use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "artifactId", default, skip_serializing_if = "Option::is_none",)] pub artifact_id: Option, @@ -16,6 +17,7 @@ pub struct Content { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Service { #[serde(rename = "id",)] pub id: String, @@ -24,6 +26,7 @@ pub struct Service { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Environment { #[serde(rename = "id",)] pub id: String, diff --git a/cdevents-sdk/src/generated/incident_resolved.rs b/cdevents-sdk/src/generated/incident_resolved.rs index 21c52e9..93ca1d7 100644 --- a/cdevents-sdk/src/generated/incident_resolved.rs +++ b/cdevents-sdk/src/generated/incident_resolved.rs @@ -2,6 +2,7 @@ use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "artifactId", default, skip_serializing_if = "Option::is_none",)] pub artifact_id: Option, @@ -14,6 +15,7 @@ pub struct Content { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Service { #[serde(rename = "id",)] pub id: String, @@ -22,6 +24,7 @@ pub struct Service { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Environment { #[serde(rename = "id",)] pub id: String, diff --git a/cdevents-sdk/src/generated/pipelinerun_finished.rs b/cdevents-sdk/src/generated/pipelinerun_finished.rs index 91302b0..cf0437c 100644 --- a/cdevents-sdk/src/generated/pipelinerun_finished.rs +++ b/cdevents-sdk/src/generated/pipelinerun_finished.rs @@ -2,6 +2,7 @@ use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "errors", default, skip_serializing_if = "Option::is_none",)] pub errors: Option, diff --git a/cdevents-sdk/src/generated/pipelinerun_queued.rs b/cdevents-sdk/src/generated/pipelinerun_queued.rs index 3a79f47..e156c94 100644 --- a/cdevents-sdk/src/generated/pipelinerun_queued.rs +++ b/cdevents-sdk/src/generated/pipelinerun_queued.rs @@ -2,6 +2,7 @@ use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "pipelineName", default, skip_serializing_if = "Option::is_none",)] pub pipeline_name: Option, diff --git a/cdevents-sdk/src/generated/pipelinerun_started.rs b/cdevents-sdk/src/generated/pipelinerun_started.rs index 8c27f88..ef5a4fe 100644 --- a/cdevents-sdk/src/generated/pipelinerun_started.rs +++ b/cdevents-sdk/src/generated/pipelinerun_started.rs @@ -2,6 +2,7 @@ use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "pipelineName",)] pub pipeline_name: String, diff --git a/cdevents-sdk/src/generated/repository_created.rs b/cdevents-sdk/src/generated/repository_created.rs index 168050b..3145c9a 100644 --- a/cdevents-sdk/src/generated/repository_created.rs +++ b/cdevents-sdk/src/generated/repository_created.rs @@ -2,6 +2,7 @@ use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "name",)] pub name: String, diff --git a/cdevents-sdk/src/generated/repository_deleted.rs b/cdevents-sdk/src/generated/repository_deleted.rs index 16bd662..b1489c8 100644 --- a/cdevents-sdk/src/generated/repository_deleted.rs +++ b/cdevents-sdk/src/generated/repository_deleted.rs @@ -2,6 +2,7 @@ use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "name", default, skip_serializing_if = "Option::is_none",)] pub name: Option, diff --git a/cdevents-sdk/src/generated/repository_modified.rs b/cdevents-sdk/src/generated/repository_modified.rs index 16bd662..b1489c8 100644 --- a/cdevents-sdk/src/generated/repository_modified.rs +++ b/cdevents-sdk/src/generated/repository_modified.rs @@ -2,6 +2,7 @@ use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "name", default, skip_serializing_if = "Option::is_none",)] pub name: Option, diff --git a/cdevents-sdk/src/generated/service_deployed.rs b/cdevents-sdk/src/generated/service_deployed.rs index 40f0f34..712fc2c 100644 --- a/cdevents-sdk/src/generated/service_deployed.rs +++ b/cdevents-sdk/src/generated/service_deployed.rs @@ -2,6 +2,7 @@ use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "artifactId",)] pub artifact_id: String, @@ -10,6 +11,7 @@ pub struct Content { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Environment { #[serde(rename = "id",)] pub id: String, diff --git a/cdevents-sdk/src/generated/service_published.rs b/cdevents-sdk/src/generated/service_published.rs index b4571ed..aa249a5 100644 --- a/cdevents-sdk/src/generated/service_published.rs +++ b/cdevents-sdk/src/generated/service_published.rs @@ -2,12 +2,14 @@ use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "environment", default, skip_serializing_if = "Option::is_none",)] pub environment: Option, } #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Environment { #[serde(rename = "id",)] pub id: String, diff --git a/cdevents-sdk/src/generated/service_removed.rs b/cdevents-sdk/src/generated/service_removed.rs index b4571ed..aa249a5 100644 --- a/cdevents-sdk/src/generated/service_removed.rs +++ b/cdevents-sdk/src/generated/service_removed.rs @@ -2,12 +2,14 @@ use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "environment", default, skip_serializing_if = "Option::is_none",)] pub environment: Option, } #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Environment { #[serde(rename = "id",)] pub id: String, diff --git a/cdevents-sdk/src/generated/service_rolledback.rs b/cdevents-sdk/src/generated/service_rolledback.rs index 40f0f34..712fc2c 100644 --- a/cdevents-sdk/src/generated/service_rolledback.rs +++ b/cdevents-sdk/src/generated/service_rolledback.rs @@ -2,6 +2,7 @@ use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "artifactId",)] pub artifact_id: String, @@ -10,6 +11,7 @@ pub struct Content { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Environment { #[serde(rename = "id",)] pub id: String, diff --git a/cdevents-sdk/src/generated/service_upgraded.rs b/cdevents-sdk/src/generated/service_upgraded.rs index 40f0f34..712fc2c 100644 --- a/cdevents-sdk/src/generated/service_upgraded.rs +++ b/cdevents-sdk/src/generated/service_upgraded.rs @@ -2,6 +2,7 @@ use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "artifactId",)] pub artifact_id: String, @@ -10,6 +11,7 @@ pub struct Content { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Environment { #[serde(rename = "id",)] pub id: String, diff --git a/cdevents-sdk/src/generated/taskrun_finished.rs b/cdevents-sdk/src/generated/taskrun_finished.rs index f1bdb00..9efd356 100644 --- a/cdevents-sdk/src/generated/taskrun_finished.rs +++ b/cdevents-sdk/src/generated/taskrun_finished.rs @@ -2,6 +2,7 @@ use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "errors", default, skip_serializing_if = "Option::is_none",)] pub errors: Option, @@ -16,6 +17,7 @@ pub struct Content { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct PipelineRun { #[serde(rename = "id",)] pub id: String, diff --git a/cdevents-sdk/src/generated/taskrun_started.rs b/cdevents-sdk/src/generated/taskrun_started.rs index 6c703a6..835b4d0 100644 --- a/cdevents-sdk/src/generated/taskrun_started.rs +++ b/cdevents-sdk/src/generated/taskrun_started.rs @@ -2,6 +2,7 @@ use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "pipelineRun", default, skip_serializing_if = "Option::is_none",)] pub pipeline_run: Option, @@ -12,6 +13,7 @@ pub struct Content { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct PipelineRun { #[serde(rename = "id",)] pub id: String, diff --git a/cdevents-sdk/src/generated/testcaserun_finished.rs b/cdevents-sdk/src/generated/testcaserun_finished.rs index 0abaaff..523a0b2 100644 --- a/cdevents-sdk/src/generated/testcaserun_finished.rs +++ b/cdevents-sdk/src/generated/testcaserun_finished.rs @@ -2,6 +2,7 @@ use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "environment",)] pub environment: Environment, @@ -18,6 +19,7 @@ pub struct Content { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct TestSuiteRun { #[serde(rename = "id",)] pub id: String, @@ -26,6 +28,7 @@ pub struct TestSuiteRun { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct TestCase { #[serde(rename = "id",)] pub id: String, @@ -40,6 +43,7 @@ pub struct TestCase { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Environment { #[serde(rename = "id",)] pub id: String, diff --git a/cdevents-sdk/src/generated/testcaserun_queued.rs b/cdevents-sdk/src/generated/testcaserun_queued.rs index dcdd6a9..2b879d1 100644 --- a/cdevents-sdk/src/generated/testcaserun_queued.rs +++ b/cdevents-sdk/src/generated/testcaserun_queued.rs @@ -2,6 +2,7 @@ use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "environment",)] pub environment: Environment, @@ -14,6 +15,7 @@ pub struct Content { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Trigger { #[serde(rename = "type", default, skip_serializing_if = "Option::is_none",)] pub r#type: Option, @@ -22,6 +24,7 @@ pub struct Trigger { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct TestSuiteRun { #[serde(rename = "id",)] pub id: String, @@ -30,6 +33,7 @@ pub struct TestSuiteRun { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct TestCase { #[serde(rename = "id",)] pub id: String, @@ -44,6 +48,7 @@ pub struct TestCase { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Environment { #[serde(rename = "id",)] pub id: String, diff --git a/cdevents-sdk/src/generated/testcaserun_started.rs b/cdevents-sdk/src/generated/testcaserun_started.rs index dcdd6a9..2b879d1 100644 --- a/cdevents-sdk/src/generated/testcaserun_started.rs +++ b/cdevents-sdk/src/generated/testcaserun_started.rs @@ -2,6 +2,7 @@ use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "environment",)] pub environment: Environment, @@ -14,6 +15,7 @@ pub struct Content { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Trigger { #[serde(rename = "type", default, skip_serializing_if = "Option::is_none",)] pub r#type: Option, @@ -22,6 +24,7 @@ pub struct Trigger { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct TestSuiteRun { #[serde(rename = "id",)] pub id: String, @@ -30,6 +33,7 @@ pub struct TestSuiteRun { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct TestCase { #[serde(rename = "id",)] pub id: String, @@ -44,6 +48,7 @@ pub struct TestCase { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Environment { #[serde(rename = "id",)] pub id: String, diff --git a/cdevents-sdk/src/generated/testoutput_published.rs b/cdevents-sdk/src/generated/testoutput_published.rs index f12c6ec..85ff1b6 100644 --- a/cdevents-sdk/src/generated/testoutput_published.rs +++ b/cdevents-sdk/src/generated/testoutput_published.rs @@ -2,6 +2,7 @@ use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "format",)] pub format: String, @@ -14,6 +15,7 @@ pub struct Content { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct TestCaseRun { #[serde(rename = "id",)] pub id: String, diff --git a/cdevents-sdk/src/generated/testsuiterun_finished.rs b/cdevents-sdk/src/generated/testsuiterun_finished.rs index 5f3f6b8..f4fc33d 100644 --- a/cdevents-sdk/src/generated/testsuiterun_finished.rs +++ b/cdevents-sdk/src/generated/testsuiterun_finished.rs @@ -2,6 +2,7 @@ use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "environment",)] pub environment: Environment, @@ -16,6 +17,7 @@ pub struct Content { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct TestSuite { #[serde(rename = "id",)] pub id: String, @@ -28,6 +30,7 @@ pub struct TestSuite { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Environment { #[serde(rename = "id",)] pub id: String, diff --git a/cdevents-sdk/src/generated/testsuiterun_queued.rs b/cdevents-sdk/src/generated/testsuiterun_queued.rs index 9c74cb2..009822e 100644 --- a/cdevents-sdk/src/generated/testsuiterun_queued.rs +++ b/cdevents-sdk/src/generated/testsuiterun_queued.rs @@ -2,6 +2,7 @@ use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "environment",)] pub environment: Environment, @@ -12,6 +13,7 @@ pub struct Content { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Trigger { #[serde(rename = "type", default, skip_serializing_if = "Option::is_none",)] pub r#type: Option, @@ -20,6 +22,7 @@ pub struct Trigger { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct TestSuite { #[serde(rename = "id",)] pub id: String, @@ -32,6 +35,7 @@ pub struct TestSuite { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Environment { #[serde(rename = "id",)] pub id: String, diff --git a/cdevents-sdk/src/generated/testsuiterun_started.rs b/cdevents-sdk/src/generated/testsuiterun_started.rs index b028508..23116ca 100644 --- a/cdevents-sdk/src/generated/testsuiterun_started.rs +++ b/cdevents-sdk/src/generated/testsuiterun_started.rs @@ -2,6 +2,7 @@ use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "environment",)] pub environment: Environment, @@ -12,6 +13,7 @@ pub struct Content { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Trigger { #[serde(rename = "type", default, skip_serializing_if = "Option::is_none",)] pub r#type: Option, @@ -20,6 +22,7 @@ pub struct Trigger { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct TestSuite { #[serde(rename = "id",)] pub id: String, @@ -32,6 +35,7 @@ pub struct TestSuite { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Environment { #[serde(rename = "id",)] pub id: String, diff --git a/cdevents-sdk/src/subject.rs b/cdevents-sdk/src/subject.rs index 314ab4e..1108c5f 100644 --- a/cdevents-sdk/src/subject.rs +++ b/cdevents-sdk/src/subject.rs @@ -3,6 +3,7 @@ use serde::{Deserialize, Serialize}; use crate::Content; #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Subject { #[serde(rename = "content")] pub content: Content, diff --git a/generator/templates/variant.hbs b/generator/templates/variant.hbs index 41a7a25..7cacb0f 100644 --- a/generator/templates/variant.hbs +++ b/generator/templates/variant.hbs @@ -3,6 +3,7 @@ use serde::{Serialize, Deserialize}; {{#each structs }} #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct {{ this.type_info.type_declaration }} { {{#each this.fields }} #[serde(rename = "{{ this.serde_name }}", From 3a51cb9b368efbf605b8ca66b3b1c4a8bad35354 Mon Sep 17 00:00:00 2001 From: David Bernard Date: Thu, 18 Jan 2024 20:18:43 +0100 Subject: [PATCH 11/34] build: apply some recommendation from clippy Signed-off-by: David Bernard --- cdevents-sdk/src/cdevent.rs | 2 +- cdevents-sdk/tests/specs.rs | 2 +- generator/src/main.rs | 5 +---- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/cdevents-sdk/src/cdevent.rs b/cdevents-sdk/src/cdevent.rs index 24a25f2..dadc199 100644 --- a/cdevents-sdk/src/cdevent.rs +++ b/cdevents-sdk/src/cdevent.rs @@ -93,7 +93,7 @@ impl<'de> Deserialize<'de> for CDEvent { } } - const FIELDS: &'static [&'static str] = &["context", "subject"]; + const FIELDS: &[&str] = &["context", "subject"]; deserializer.deserialize_struct("CDEvent", FIELDS, CDEventVisitor) } } diff --git a/cdevents-sdk/tests/specs.rs b/cdevents-sdk/tests/specs.rs index 3bab7d8..0cd1008 100644 --- a/cdevents-sdk/tests/specs.rs +++ b/cdevents-sdk/tests/specs.rs @@ -6,7 +6,7 @@ use std::path::PathBuf; #[rstest] fn for_each_example(#[files("../cdevents-spec/examples/*.json")] path: PathBuf) { - let example_txt = fs::read_to_string(&path).expect("to read file as string"); + let example_txt = fs::read_to_string(path).expect("to read file as string"); //HACK uri are stored ad http::Uri, they are "normalized" when serialized, so prenormalization to avoid failure like // json atoms at path ".subject.content.repository.source" are not equal: // lhs: diff --git a/generator/src/main.rs b/generator/src/main.rs index 2be652f..eda0ba0 100644 --- a/generator/src/main.rs +++ b/generator/src/main.rs @@ -63,7 +63,7 @@ fn main() -> Result<()> { let (module_name, code) = generate_module(&hbs, &variants).with_context(|| "failed to generate module")?; - let file = settings.dest.join(&module_name).with_extension("rs"); + let file = settings.dest.join(module_name).with_extension("rs"); fs::write(file, code)?; Ok(()) @@ -155,18 +155,15 @@ fn collect_structs( Some("date-time") => TypeInfo { type_declaration: "time::OffsetDateTime".to_string(), serde_with: Some("crate::serde::datetime".to_string()), - ..Default::default() }, //TODO manage purl Some("uri-reference") => TypeInfo { type_declaration: "fluent_uri::Uri".to_string(), serde_with: Some("crate::serde::uri_reference".to_string()), - ..Default::default() }, Some("uri") => TypeInfo { type_declaration: "fluent_uri::Uri".to_string(), serde_with: Some("crate::serde::uri".to_string()), - ..Default::default() }, // Some("uri") => TypeInfo { // type_declaration: "http::Uri".to_string(), From e738b7f48caa57ba12cf0f5bddc40f10bd586342 Mon Sep 17 00:00:00 2001 From: David Bernard Date: Thu, 18 Jan 2024 21:02:08 +0100 Subject: [PATCH 12/34] style: reformat Signed-off-by: David Bernard --- README.md | 86 +++++++++---------- .../src/generated/artifact_packaged.rs | 4 +- .../src/generated/artifact_published.rs | 4 +- cdevents-sdk/src/generated/artifact_signed.rs | 4 +- cdevents-sdk/src/generated/branch_created.rs | 4 +- cdevents-sdk/src/generated/branch_deleted.rs | 4 +- cdevents-sdk/src/generated/build_finished.rs | 4 +- cdevents-sdk/src/generated/build_queued.rs | 4 +- cdevents-sdk/src/generated/build_started.rs | 4 +- .../src/generated/change_abandoned.rs | 4 +- cdevents-sdk/src/generated/change_created.rs | 4 +- cdevents-sdk/src/generated/change_merged.rs | 4 +- cdevents-sdk/src/generated/change_reviewed.rs | 4 +- cdevents-sdk/src/generated/change_updated.rs | 4 +- .../src/generated/environment_created.rs | 4 +- .../src/generated/environment_deleted.rs | 4 +- .../src/generated/environment_modified.rs | 4 +- .../src/generated/incident_detected.rs | 4 +- .../src/generated/incident_reported.rs | 4 +- .../src/generated/incident_resolved.rs | 4 +- cdevents-sdk/src/generated/mod.rs | 3 +- .../src/generated/pipelinerun_finished.rs | 4 +- .../src/generated/pipelinerun_queued.rs | 4 +- .../src/generated/pipelinerun_started.rs | 4 +- .../src/generated/repository_created.rs | 4 +- .../src/generated/repository_deleted.rs | 4 +- .../src/generated/repository_modified.rs | 4 +- .../src/generated/service_deployed.rs | 4 +- .../src/generated/service_published.rs | 4 +- cdevents-sdk/src/generated/service_removed.rs | 4 +- .../src/generated/service_rolledback.rs | 4 +- .../src/generated/service_upgraded.rs | 4 +- .../src/generated/taskrun_finished.rs | 4 +- cdevents-sdk/src/generated/taskrun_started.rs | 4 +- .../src/generated/testcaserun_finished.rs | 4 +- .../src/generated/testcaserun_queued.rs | 4 +- .../src/generated/testcaserun_started.rs | 4 +- .../src/generated/testoutput_published.rs | 4 +- .../src/generated/testsuiterun_finished.rs | 4 +- .../src/generated/testsuiterun_queued.rs | 4 +- .../src/generated/testsuiterun_started.rs | 4 +- generator/README.md | 2 +- generator/src/main.rs | 2 + generator/templates/mod.hbs | 3 +- generator/templates/variant.hbs | 6 +- 45 files changed, 171 insertions(+), 87 deletions(-) diff --git a/README.md b/README.md index 2090aab..3d9a5d2 100644 --- a/README.md +++ b/README.md @@ -1,43 +1,43 @@ -# Rust CDEvents SDK - -Rust SDK to emit [CDEvents](https://cdevents.dev). - -The SDK can be used to create CDEvents and send them as CloudEvents, as well as parse a received CloudEvent into a CDEvent. - -## Get started - -```rust -WIP -``` - -## Create your first CDEvent - -To create a CDEvent, for instance a [*pipelineRun queued*](https://cdevents.dev/docs/core/#pipelinerun-queued) one: - -```rust -WIP -``` - -## Send your first CDEvent as CloudEvent - -Import the modules in your code - -```rust -WIP -``` - -To send a CDEvent as CloudEvent: - -```rust -WIP -``` - -See the [CloudEvents](https://github.com/cloudevents/sdk-go#send-your-first-cloudevent) docs as well. - -## Contributing - -If you would like to contribute, see our [development](DEVELOPMENT.md) guide. - -## References - -- [CDEvents](https://cdevents.dev) \ No newline at end of file +# Rust CDEvents SDK + +Rust SDK to emit [CDEvents](https://cdevents.dev). + +The SDK can be used to create CDEvents and send them as CloudEvents, as well as parse a received CloudEvent into a CDEvent. + +## Get started + +```rust +WIP +``` + +## Create your first CDEvent + +To create a CDEvent, for instance a [*pipelineRun queued*](https://cdevents.dev/docs/core/#pipelinerun-queued) one: + +```rust +WIP +``` + +## Send your first CDEvent as CloudEvent + +Import the modules in your code + +```rust +WIP +``` + +To send a CDEvent as CloudEvent: + +```rust +WIP +``` + +See the [CloudEvents](https://github.com/cloudevents/sdk-go#send-your-first-cloudevent) docs as well. + +## Contributing + +If you would like to contribute, see our [development](DEVELOPMENT.md) guide. + +## References + +- [CDEvents](https://cdevents.dev) diff --git a/cdevents-sdk/src/generated/artifact_packaged.rs b/cdevents-sdk/src/generated/artifact_packaged.rs index 859a013..46d7918 100644 --- a/cdevents-sdk/src/generated/artifact_packaged.rs +++ b/cdevents-sdk/src/generated/artifact_packaged.rs @@ -1,4 +1,6 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) +// @generated +// by cdevents/sdk-rust/generator (subject.hbs) + use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/cdevents-sdk/src/generated/artifact_published.rs b/cdevents-sdk/src/generated/artifact_published.rs index e922b9a..4d0f724 100644 --- a/cdevents-sdk/src/generated/artifact_published.rs +++ b/cdevents-sdk/src/generated/artifact_published.rs @@ -1,4 +1,6 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) +// @generated +// by cdevents/sdk-rust/generator (subject.hbs) + use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/cdevents-sdk/src/generated/artifact_signed.rs b/cdevents-sdk/src/generated/artifact_signed.rs index ff40f63..18bbaf8 100644 --- a/cdevents-sdk/src/generated/artifact_signed.rs +++ b/cdevents-sdk/src/generated/artifact_signed.rs @@ -1,4 +1,6 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) +// @generated +// by cdevents/sdk-rust/generator (subject.hbs) + use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/cdevents-sdk/src/generated/branch_created.rs b/cdevents-sdk/src/generated/branch_created.rs index a6f4c7e..afa2999 100644 --- a/cdevents-sdk/src/generated/branch_created.rs +++ b/cdevents-sdk/src/generated/branch_created.rs @@ -1,4 +1,6 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) +// @generated +// by cdevents/sdk-rust/generator (subject.hbs) + use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/cdevents-sdk/src/generated/branch_deleted.rs b/cdevents-sdk/src/generated/branch_deleted.rs index a6f4c7e..afa2999 100644 --- a/cdevents-sdk/src/generated/branch_deleted.rs +++ b/cdevents-sdk/src/generated/branch_deleted.rs @@ -1,4 +1,6 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) +// @generated +// by cdevents/sdk-rust/generator (subject.hbs) + use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/cdevents-sdk/src/generated/build_finished.rs b/cdevents-sdk/src/generated/build_finished.rs index 87618d7..a0b451f 100644 --- a/cdevents-sdk/src/generated/build_finished.rs +++ b/cdevents-sdk/src/generated/build_finished.rs @@ -1,4 +1,6 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) +// @generated +// by cdevents/sdk-rust/generator (subject.hbs) + use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/cdevents-sdk/src/generated/build_queued.rs b/cdevents-sdk/src/generated/build_queued.rs index e922b9a..4d0f724 100644 --- a/cdevents-sdk/src/generated/build_queued.rs +++ b/cdevents-sdk/src/generated/build_queued.rs @@ -1,4 +1,6 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) +// @generated +// by cdevents/sdk-rust/generator (subject.hbs) + use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/cdevents-sdk/src/generated/build_started.rs b/cdevents-sdk/src/generated/build_started.rs index e922b9a..4d0f724 100644 --- a/cdevents-sdk/src/generated/build_started.rs +++ b/cdevents-sdk/src/generated/build_started.rs @@ -1,4 +1,6 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) +// @generated +// by cdevents/sdk-rust/generator (subject.hbs) + use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/cdevents-sdk/src/generated/change_abandoned.rs b/cdevents-sdk/src/generated/change_abandoned.rs index a6f4c7e..afa2999 100644 --- a/cdevents-sdk/src/generated/change_abandoned.rs +++ b/cdevents-sdk/src/generated/change_abandoned.rs @@ -1,4 +1,6 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) +// @generated +// by cdevents/sdk-rust/generator (subject.hbs) + use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/cdevents-sdk/src/generated/change_created.rs b/cdevents-sdk/src/generated/change_created.rs index a6f4c7e..afa2999 100644 --- a/cdevents-sdk/src/generated/change_created.rs +++ b/cdevents-sdk/src/generated/change_created.rs @@ -1,4 +1,6 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) +// @generated +// by cdevents/sdk-rust/generator (subject.hbs) + use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/cdevents-sdk/src/generated/change_merged.rs b/cdevents-sdk/src/generated/change_merged.rs index a6f4c7e..afa2999 100644 --- a/cdevents-sdk/src/generated/change_merged.rs +++ b/cdevents-sdk/src/generated/change_merged.rs @@ -1,4 +1,6 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) +// @generated +// by cdevents/sdk-rust/generator (subject.hbs) + use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/cdevents-sdk/src/generated/change_reviewed.rs b/cdevents-sdk/src/generated/change_reviewed.rs index a6f4c7e..afa2999 100644 --- a/cdevents-sdk/src/generated/change_reviewed.rs +++ b/cdevents-sdk/src/generated/change_reviewed.rs @@ -1,4 +1,6 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) +// @generated +// by cdevents/sdk-rust/generator (subject.hbs) + use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/cdevents-sdk/src/generated/change_updated.rs b/cdevents-sdk/src/generated/change_updated.rs index a6f4c7e..afa2999 100644 --- a/cdevents-sdk/src/generated/change_updated.rs +++ b/cdevents-sdk/src/generated/change_updated.rs @@ -1,4 +1,6 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) +// @generated +// by cdevents/sdk-rust/generator (subject.hbs) + use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/cdevents-sdk/src/generated/environment_created.rs b/cdevents-sdk/src/generated/environment_created.rs index 62de02f..79fbb07 100644 --- a/cdevents-sdk/src/generated/environment_created.rs +++ b/cdevents-sdk/src/generated/environment_created.rs @@ -1,4 +1,6 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) +// @generated +// by cdevents/sdk-rust/generator (subject.hbs) + use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/cdevents-sdk/src/generated/environment_deleted.rs b/cdevents-sdk/src/generated/environment_deleted.rs index 028edac..99d4138 100644 --- a/cdevents-sdk/src/generated/environment_deleted.rs +++ b/cdevents-sdk/src/generated/environment_deleted.rs @@ -1,4 +1,6 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) +// @generated +// by cdevents/sdk-rust/generator (subject.hbs) + use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/cdevents-sdk/src/generated/environment_modified.rs b/cdevents-sdk/src/generated/environment_modified.rs index 62de02f..79fbb07 100644 --- a/cdevents-sdk/src/generated/environment_modified.rs +++ b/cdevents-sdk/src/generated/environment_modified.rs @@ -1,4 +1,6 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) +// @generated +// by cdevents/sdk-rust/generator (subject.hbs) + use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/cdevents-sdk/src/generated/incident_detected.rs b/cdevents-sdk/src/generated/incident_detected.rs index 93ca1d7..c7bf3e1 100644 --- a/cdevents-sdk/src/generated/incident_detected.rs +++ b/cdevents-sdk/src/generated/incident_detected.rs @@ -1,4 +1,6 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) +// @generated +// by cdevents/sdk-rust/generator (subject.hbs) + use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/cdevents-sdk/src/generated/incident_reported.rs b/cdevents-sdk/src/generated/incident_reported.rs index 3a3a152..070a784 100644 --- a/cdevents-sdk/src/generated/incident_reported.rs +++ b/cdevents-sdk/src/generated/incident_reported.rs @@ -1,4 +1,6 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) +// @generated +// by cdevents/sdk-rust/generator (subject.hbs) + use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/cdevents-sdk/src/generated/incident_resolved.rs b/cdevents-sdk/src/generated/incident_resolved.rs index 93ca1d7..c7bf3e1 100644 --- a/cdevents-sdk/src/generated/incident_resolved.rs +++ b/cdevents-sdk/src/generated/incident_resolved.rs @@ -1,4 +1,6 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) +// @generated +// by cdevents/sdk-rust/generator (subject.hbs) + use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/cdevents-sdk/src/generated/mod.rs b/cdevents-sdk/src/generated/mod.rs index c49590a..4efc969 100644 --- a/cdevents-sdk/src/generated/mod.rs +++ b/cdevents-sdk/src/generated/mod.rs @@ -1,4 +1,5 @@ -// code generated by cdevents/sdk-rust/generator (mod.hbs) +// @generated +// by cdevents/sdk-rust/generator (mod.hbs) use serde::de::Error; diff --git a/cdevents-sdk/src/generated/pipelinerun_finished.rs b/cdevents-sdk/src/generated/pipelinerun_finished.rs index cf0437c..dfb1ada 100644 --- a/cdevents-sdk/src/generated/pipelinerun_finished.rs +++ b/cdevents-sdk/src/generated/pipelinerun_finished.rs @@ -1,4 +1,6 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) +// @generated +// by cdevents/sdk-rust/generator (subject.hbs) + use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/cdevents-sdk/src/generated/pipelinerun_queued.rs b/cdevents-sdk/src/generated/pipelinerun_queued.rs index e156c94..365e8bd 100644 --- a/cdevents-sdk/src/generated/pipelinerun_queued.rs +++ b/cdevents-sdk/src/generated/pipelinerun_queued.rs @@ -1,4 +1,6 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) +// @generated +// by cdevents/sdk-rust/generator (subject.hbs) + use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/cdevents-sdk/src/generated/pipelinerun_started.rs b/cdevents-sdk/src/generated/pipelinerun_started.rs index ef5a4fe..564eeb0 100644 --- a/cdevents-sdk/src/generated/pipelinerun_started.rs +++ b/cdevents-sdk/src/generated/pipelinerun_started.rs @@ -1,4 +1,6 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) +// @generated +// by cdevents/sdk-rust/generator (subject.hbs) + use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/cdevents-sdk/src/generated/repository_created.rs b/cdevents-sdk/src/generated/repository_created.rs index 3145c9a..8eeb683 100644 --- a/cdevents-sdk/src/generated/repository_created.rs +++ b/cdevents-sdk/src/generated/repository_created.rs @@ -1,4 +1,6 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) +// @generated +// by cdevents/sdk-rust/generator (subject.hbs) + use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/cdevents-sdk/src/generated/repository_deleted.rs b/cdevents-sdk/src/generated/repository_deleted.rs index b1489c8..82eb5c6 100644 --- a/cdevents-sdk/src/generated/repository_deleted.rs +++ b/cdevents-sdk/src/generated/repository_deleted.rs @@ -1,4 +1,6 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) +// @generated +// by cdevents/sdk-rust/generator (subject.hbs) + use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/cdevents-sdk/src/generated/repository_modified.rs b/cdevents-sdk/src/generated/repository_modified.rs index b1489c8..82eb5c6 100644 --- a/cdevents-sdk/src/generated/repository_modified.rs +++ b/cdevents-sdk/src/generated/repository_modified.rs @@ -1,4 +1,6 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) +// @generated +// by cdevents/sdk-rust/generator (subject.hbs) + use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/cdevents-sdk/src/generated/service_deployed.rs b/cdevents-sdk/src/generated/service_deployed.rs index 712fc2c..048a691 100644 --- a/cdevents-sdk/src/generated/service_deployed.rs +++ b/cdevents-sdk/src/generated/service_deployed.rs @@ -1,4 +1,6 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) +// @generated +// by cdevents/sdk-rust/generator (subject.hbs) + use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/cdevents-sdk/src/generated/service_published.rs b/cdevents-sdk/src/generated/service_published.rs index aa249a5..b894eaf 100644 --- a/cdevents-sdk/src/generated/service_published.rs +++ b/cdevents-sdk/src/generated/service_published.rs @@ -1,4 +1,6 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) +// @generated +// by cdevents/sdk-rust/generator (subject.hbs) + use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/cdevents-sdk/src/generated/service_removed.rs b/cdevents-sdk/src/generated/service_removed.rs index aa249a5..b894eaf 100644 --- a/cdevents-sdk/src/generated/service_removed.rs +++ b/cdevents-sdk/src/generated/service_removed.rs @@ -1,4 +1,6 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) +// @generated +// by cdevents/sdk-rust/generator (subject.hbs) + use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/cdevents-sdk/src/generated/service_rolledback.rs b/cdevents-sdk/src/generated/service_rolledback.rs index 712fc2c..048a691 100644 --- a/cdevents-sdk/src/generated/service_rolledback.rs +++ b/cdevents-sdk/src/generated/service_rolledback.rs @@ -1,4 +1,6 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) +// @generated +// by cdevents/sdk-rust/generator (subject.hbs) + use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/cdevents-sdk/src/generated/service_upgraded.rs b/cdevents-sdk/src/generated/service_upgraded.rs index 712fc2c..048a691 100644 --- a/cdevents-sdk/src/generated/service_upgraded.rs +++ b/cdevents-sdk/src/generated/service_upgraded.rs @@ -1,4 +1,6 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) +// @generated +// by cdevents/sdk-rust/generator (subject.hbs) + use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/cdevents-sdk/src/generated/taskrun_finished.rs b/cdevents-sdk/src/generated/taskrun_finished.rs index 9efd356..9d2fa66 100644 --- a/cdevents-sdk/src/generated/taskrun_finished.rs +++ b/cdevents-sdk/src/generated/taskrun_finished.rs @@ -1,4 +1,6 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) +// @generated +// by cdevents/sdk-rust/generator (subject.hbs) + use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/cdevents-sdk/src/generated/taskrun_started.rs b/cdevents-sdk/src/generated/taskrun_started.rs index 835b4d0..6600fd4 100644 --- a/cdevents-sdk/src/generated/taskrun_started.rs +++ b/cdevents-sdk/src/generated/taskrun_started.rs @@ -1,4 +1,6 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) +// @generated +// by cdevents/sdk-rust/generator (subject.hbs) + use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/cdevents-sdk/src/generated/testcaserun_finished.rs b/cdevents-sdk/src/generated/testcaserun_finished.rs index 523a0b2..d812055 100644 --- a/cdevents-sdk/src/generated/testcaserun_finished.rs +++ b/cdevents-sdk/src/generated/testcaserun_finished.rs @@ -1,4 +1,6 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) +// @generated +// by cdevents/sdk-rust/generator (subject.hbs) + use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/cdevents-sdk/src/generated/testcaserun_queued.rs b/cdevents-sdk/src/generated/testcaserun_queued.rs index 2b879d1..06e1aff 100644 --- a/cdevents-sdk/src/generated/testcaserun_queued.rs +++ b/cdevents-sdk/src/generated/testcaserun_queued.rs @@ -1,4 +1,6 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) +// @generated +// by cdevents/sdk-rust/generator (subject.hbs) + use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/cdevents-sdk/src/generated/testcaserun_started.rs b/cdevents-sdk/src/generated/testcaserun_started.rs index 2b879d1..06e1aff 100644 --- a/cdevents-sdk/src/generated/testcaserun_started.rs +++ b/cdevents-sdk/src/generated/testcaserun_started.rs @@ -1,4 +1,6 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) +// @generated +// by cdevents/sdk-rust/generator (subject.hbs) + use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/cdevents-sdk/src/generated/testoutput_published.rs b/cdevents-sdk/src/generated/testoutput_published.rs index 85ff1b6..b244d46 100644 --- a/cdevents-sdk/src/generated/testoutput_published.rs +++ b/cdevents-sdk/src/generated/testoutput_published.rs @@ -1,4 +1,6 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) +// @generated +// by cdevents/sdk-rust/generator (subject.hbs) + use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/cdevents-sdk/src/generated/testsuiterun_finished.rs b/cdevents-sdk/src/generated/testsuiterun_finished.rs index f4fc33d..aceeb10 100644 --- a/cdevents-sdk/src/generated/testsuiterun_finished.rs +++ b/cdevents-sdk/src/generated/testsuiterun_finished.rs @@ -1,4 +1,6 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) +// @generated +// by cdevents/sdk-rust/generator (subject.hbs) + use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/cdevents-sdk/src/generated/testsuiterun_queued.rs b/cdevents-sdk/src/generated/testsuiterun_queued.rs index 009822e..49265bf 100644 --- a/cdevents-sdk/src/generated/testsuiterun_queued.rs +++ b/cdevents-sdk/src/generated/testsuiterun_queued.rs @@ -1,4 +1,6 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) +// @generated +// by cdevents/sdk-rust/generator (subject.hbs) + use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/cdevents-sdk/src/generated/testsuiterun_started.rs b/cdevents-sdk/src/generated/testsuiterun_started.rs index 23116ca..cd88a72 100644 --- a/cdevents-sdk/src/generated/testsuiterun_started.rs +++ b/cdevents-sdk/src/generated/testsuiterun_started.rs @@ -1,4 +1,6 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) +// @generated +// by cdevents/sdk-rust/generator (subject.hbs) + use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/generator/README.md b/generator/README.md index 6938a84..3760e75 100644 --- a/generator/README.md +++ b/generator/README.md @@ -18,4 +18,4 @@ To generate the `subjects` into sibling crate `cdevents/src/generated` from cont ```sh cargo run -p generator -- --help cargo run -p generator -- --templates-dir "generator/templates" --jsonschema-dir "cdevents-spec/schemas" --dest "cdevents-sdk/src/generated" -``` \ No newline at end of file +``` diff --git a/generator/src/main.rs b/generator/src/main.rs index eda0ba0..532d8c8 100644 --- a/generator/src/main.rs +++ b/generator/src/main.rs @@ -52,6 +52,7 @@ fn main() -> Result<()> { .dest .join(cruet::to_snake_case(&rust_module)) .with_extension("rs"); + //TODO use a formatter like https://crates.io/crates/prettyplease? fs::write(file, code)?; variants.push(VariantInfo { context_type, @@ -64,6 +65,7 @@ fn main() -> Result<()> { let (module_name, code) = generate_module(&hbs, &variants).with_context(|| "failed to generate module")?; let file = settings.dest.join(module_name).with_extension("rs"); + //TODO use a formatter like https://crates.io/crates/prettyplease? fs::write(file, code)?; Ok(()) diff --git a/generator/templates/mod.hbs b/generator/templates/mod.hbs index 8244a10..e01a066 100644 --- a/generator/templates/mod.hbs +++ b/generator/templates/mod.hbs @@ -1,4 +1,5 @@ -// code generated by cdevents/sdk-rust/generator (mod.hbs) +// @generated +// by cdevents/sdk-rust/generator (mod.hbs) use serde::de::Error; diff --git a/generator/templates/variant.hbs b/generator/templates/variant.hbs index 7cacb0f..0b3fa2e 100644 --- a/generator/templates/variant.hbs +++ b/generator/templates/variant.hbs @@ -1,4 +1,6 @@ -// code generated by cdevents/sdk-rust/generator (subject.hbs) +// @generated +// by cdevents/sdk-rust/generator (subject.hbs) + use serde::{Serialize, Deserialize}; {{#each structs }} @@ -14,4 +16,4 @@ pub struct {{ this.type_info.type_declaration }} { {{/each}} } -{{/each}} \ No newline at end of file +{{/each}} From 59210a67a82d1758f193350e7fb4c91995031894 Mon Sep 17 00:00:00 2001 From: David Bernard Date: Thu, 18 Jan 2024 21:03:11 +0100 Subject: [PATCH 13/34] ci: setup ci & linters Signed-off-by: David Bernard --- .editorconfig | 68 ++++++++++ .github/dependabot.yml | 12 ++ .github/workflows/ci.yml | 39 ++++++ .github/workflows/mega-linter.yml | 173 +++++++++++++++++++++++++ .gitignore | 201 ++++++++++++++++++++++++++++++ .gitmodules | 2 +- .mega-linter.yml | 40 ++++++ .rtx.toml | 8 ++ cdevents-sdk/.rustfmt.toml | 9 ++ cdevents-spec | 1 + justfile | 76 +++++++++++ 11 files changed, 628 insertions(+), 1 deletion(-) create mode 100644 .editorconfig create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/mega-linter.yml create mode 100644 .mega-linter.yml create mode 100644 .rtx.toml create mode 100644 cdevents-sdk/.rustfmt.toml create mode 160000 cdevents-spec create mode 100644 justfile diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..8f411f9 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,68 @@ +# https://editorconfig.org/ + +root = true + +[*] +indent_style = space +indent_size = 2 +insert_final_newline = true +trim_trailing_whitespace = true +end_of_line = lf +charset = utf-8 + +[*.conf] +indent_size = 2 + +[*.md] +#inside code block, indentation could be anything +indent_size = unset + +[*.py] +indent_size = 4 +# 88 is the default for black formatter +# 79 is PEP8's recommendation +# 119 is django's recommendation +max_line_length = 88 + +[*.rs] +# https://github.com/rust-dev-tools/fmt-rfcs/blob/master/guide/guide.md +indent_size = 4 +# officially the limit is 100, but we have long url (unsplittable) in comment +max_line_length = 200 + +[{*.bazel,*.bzl,BUILD,WORKSPACE}] +indent_size = 4 + +[*.java] +# try to align with https://github.com/diffplug/spotless (https://github.com/google/google-java-format) +indent_size = 4 +max_line_length = 100 + +# The JSON files contain newlines inconsistently +[*.json] +insert_final_newline = unset + +[**/vendor/**] +indent_style = unset +indent_size = unset +insert_final_newline = unset + +# Minified JavaScript files shouldn't be changed +[**.min.js] +indent_style = unset +indent_size = unset +insert_final_newline = unset + +# Makefiles always use tabs for indentation +[Makefile] +indent_style = tab +indent_size = 4 + +[justfile] +indent_style = space +indent_size = 4 + +# Batch files use tabs for indentation +[*.bat] +indent_style = tab +indent_size = 4 diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..62a183b --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,12 @@ +version: 2 +updates: + - package-ecosystem: "cargo" + directory: "/" + schedule: + interval: "weekly" + - package-ecosystem: "github-actions" + # Workflow files stored in the + # default location of `.github/workflows` + directory: "/" + schedule: + interval: "weekly" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..ae254b4 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,39 @@ +--- +name: ci + +on: + push: + workflow_dispatch: + +permissions: + contents: read + +jobs: + tests: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest] + env: + CARGO_TERM_COLOR: always + RUST_BACKTRACE: full + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + submodules: "true" + - uses: jdx/rtx-action@v1 + - name: Cache cargo registry + uses: actions/cache@v3 + continue-on-error: false + with: + path: | + ~/.cargo/registry + ~/.cargo/git + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-cargo- + - run: just check + - run: just lint_rust # megalinter is running via an other workflow + - run: just test diff --git a/.github/workflows/mega-linter.yml b/.github/workflows/mega-linter.yml new file mode 100644 index 0000000..190c18b --- /dev/null +++ b/.github/workflows/mega-linter.yml @@ -0,0 +1,173 @@ +# MegaLinter GitHub Action configuration file +# More info at https://megalinter.io +--- +name: MegaLinter + +# Trigger mega-linter at every push. Action will also be visible from Pull +# Requests to main +on: + # Comment this line to trigger action only on pull-requests + # (not recommended if you don't pay for GH Actions) + push: + + # pull_request: + # branches: + # - main + # - master + +# Comment env block if you do not want to apply fixes +env: + # Apply linter fixes configuration + # + # When active, APPLY_FIXES must also be defined as environment variable + # (in github/workflows/mega-linter.yml or other CI tool) + APPLY_FIXES: all + + # Decide which event triggers application of fixes in a commit or a PR + # (pull_request, push, all) + APPLY_FIXES_EVENT: pull_request + + # If APPLY_FIXES is used, defines if the fixes are directly committed (commit) + # or posted in a PR (pull_request) + APPLY_FIXES_MODE: commit + +concurrency: + group: ${{ github.ref }}-${{ github.workflow }} + cancel-in-progress: true + +# Give the default GITHUB_TOKEN write permission to commit and push, comment +# issues & post new PR; remove the ones you do not need +permissions: + contents: write + issues: write + pull-requests: write + +jobs: + megalinter: + name: MegaLinter + runs-on: ubuntu-latest + + steps: + # Git Checkout + - name: Checkout Code + uses: actions/checkout@v4 + with: + token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }} + + # If you use VALIDATE_ALL_CODEBASE = true, you can remove this line to + # improve performance + fetch-depth: 0 + + # MegaLinter + - name: MegaLinter + + # You can override MegaLinter flavor used to have faster performances + # More info at https://megalinter.io/flavors/ + uses: oxsecurity/megalinter@v7 + + id: ml + + # All available variables are described in documentation + # https://megalinter.io/configuration/ + env: + # Validates all source when push on main, else just the git diff with + # main. Override with true if you always want to lint all sources + # + # To validate the entire codebase, set to: + # VALIDATE_ALL_CODEBASE: true + # + # To validate only diff with main, set to: + # VALIDATE_ALL_CODEBASE: >- + # ${{ + # github.event_name == 'push' && + # contains(fromJSON('["refs/heads/main", "refs/heads/master"]'), github.ref) + # }} + VALIDATE_ALL_CODEBASE: >- + ${{ + github.event_name == 'push' && + contains(fromJSON('["refs/heads/main", "refs/heads/master"]'), github.ref) + }} + + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + # ADD YOUR CUSTOM ENV VARIABLES HERE OR DEFINE THEM IN A FILE + # .mega-linter.yml AT THE ROOT OF YOUR REPOSITORY + + # Uncomment to disable copy-paste and spell checks + # DISABLE: COPYPASTE,SPELL + + # Upload MegaLinter artifacts + - name: Archive production artifacts + uses: actions/upload-artifact@v4 + if: success() || failure() + with: + name: MegaLinter reports + path: | + megalinter-reports + mega-linter.log + + # Set APPLY_FIXES_IF var for use in future steps + - name: Set APPLY_FIXES_IF var + run: | + printf 'APPLY_FIXES_IF=%s\n' "${{ + steps.ml.outputs.has_updated_sources == 1 && + ( + env.APPLY_FIXES_EVENT == 'all' || + env.APPLY_FIXES_EVENT == github.event_name + ) && + ( + github.event_name == 'push' || + github.event.pull_request.head.repo.full_name == github.repository + ) + }}" >> "${GITHUB_ENV}" + + # Set APPLY_FIXES_IF_* vars for use in future steps + - name: Set APPLY_FIXES_IF_* vars + run: | + printf 'APPLY_FIXES_IF_PR=%s\n' "${{ + env.APPLY_FIXES_IF == 'true' && + env.APPLY_FIXES_MODE == 'pull_request' + }}" >> "${GITHUB_ENV}" + printf 'APPLY_FIXES_IF_COMMIT=%s\n' "${{ + env.APPLY_FIXES_IF == 'true' && + env.APPLY_FIXES_MODE == 'commit' && + (!contains(fromJSON('["refs/heads/main", "refs/heads/master"]'), github.ref)) + }}" >> "${GITHUB_ENV}" + + # Create pull request if applicable + # (for now works only on PR from same repository, not from forks) + - name: Create Pull Request with applied fixes + uses: peter-evans/create-pull-request@v5 + id: cpr + if: env.APPLY_FIXES_IF_PR == 'true' + with: + token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }} + commit-message: "[MegaLinter] Apply linters automatic fixes" + title: "[MegaLinter] Apply linters automatic fixes" + labels: bot + + - name: Create PR output + if: env.APPLY_FIXES_IF_PR == 'true' + run: | + echo "PR Number - ${{ steps.cpr.outputs.pull-request-number }}" + echo "PR URL - ${{ steps.cpr.outputs.pull-request-url }}" + + # Push new commit if applicable + # (for now works only on PR from same repository, not from forks) + - name: Prepare commit + if: env.APPLY_FIXES_IF_COMMIT == 'true' + run: sudo chown -Rc $UID .git/ + + - name: Commit and push applied linter fixes + uses: stefanzweifel/git-auto-commit-action@v5 + if: env.APPLY_FIXES_IF_COMMIT == 'true' + with: + branch: >- + ${{ + github.event.pull_request.head.ref || + github.head_ref || + github.ref + }} + commit_message: "[MegaLinter] Apply linters fixes" + commit_user_name: megalinter-bot + commit_user_email: nicolas.vuillamy@ox.security diff --git a/.gitignore b/.gitignore index 6985cf1..35a3f8c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,161 @@ +# Created by https://www.toptal.com/developers/gitignore/api/git,vim,rust,emacs,jetbrains+all,visualstudiocode +# Edit at https://www.toptal.com/developers/gitignore?templates=git,vim,rust,emacs,jetbrains+all,visualstudiocode + +### Emacs ### +# -*- mode: gitignore; -*- +*~ +\#*\# +/.emacs.desktop +/.emacs.desktop.lock +*.elc +auto-save-list +tramp +.\#* + +# Org-mode +.org-id-locations +*_archive + +# flymake-mode +*_flymake.* + +# eshell files +/eshell/history +/eshell/lastdir + +# elpa packages +/elpa/ + +# reftex files +*.rel + +# AUCTeX auto folder +/auto/ + +# cask packages +.cask/ +dist/ + +# Flycheck +flycheck_*.el + +# server auth directory +/server/ + +# projectiles files +.projectile + +# directory configuration +.dir-locals.el + +# network security +/network-security.data + + +### Git ### +# Created by git for backups. To disable backups in Git: +# $ git config --global mergetool.keepBackup false +*.orig + +# Created by git when using merge tools for conflicts +*.BACKUP.* +*.BASE.* +*.LOCAL.* +*.REMOTE.* +*_BACKUP_*.txt +*_BASE_*.txt +*_LOCAL_*.txt +*_REMOTE_*.txt + +### JetBrains+all ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# AWS User-specific +.idea/**/aws.xml + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# SonarLint plugin +.idea/sonarlint/ + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### JetBrains+all Patch ### +# Ignore everything but code style settings and run configurations +# that are supposed to be shared within teams. + +.idea/* + +!.idea/codeStyles +!.idea/runConfigurations + +### Rust ### # Generated by Cargo # will have compiled files and executables debug/ @@ -12,3 +170,46 @@ Cargo.lock # MSVC Windows builds of rustc generate these, which store debugging information *.pdb + +### Vim ### +# Swap +[._]*.s[a-v][a-z] +!*.svg # comment out if you don't need vector files +[._]*.sw[a-p] +[._]s[a-rt-v][a-z] +[._]ss[a-gi-z] +[._]sw[a-p] + +# Session +Session.vim +Sessionx.vim + +# Temporary +.netrwhist +# Auto-generated tag files +tags +# Persistent undo +[._]*.un~ + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +!.vscode/*.code-snippets + +# Local History for Visual Studio Code +.history/ + +# Built Visual Studio Code Extensions +*.vsix + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history +.ionide + +# End of https://www.toptal.com/developers/gitignore/api/git,vim,rust,emacs,jetbrains+all,visualstudiocode + +megalinter-reports diff --git a/.gitmodules b/.gitmodules index ed8598b..72bdf71 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +1,4 @@ [submodule "cdevents-spec"] path = cdevents-spec - url = git@github.com:cdevents/spec.git + url = https://github.com/cdevents/spec.git branch = spec-v0.3 diff --git a/.mega-linter.yml b/.mega-linter.yml new file mode 100644 index 0000000..bbfe908 --- /dev/null +++ b/.mega-linter.yml @@ -0,0 +1,40 @@ +# Configuration file for MegaLinter +# See all available variables at https://megalinter.github.io/configuration/ and in linters documentation + +APPLY_FIXES: none # all, none, or list of linter keys +# ENABLE: # If you use ENABLE variable, all other languages/formats/tooling-formats will be disabled by default +# ENABLE_LINTERS: # If you use ENABLE_LINTERS variable, all other linters will be disabled by default +DISABLE: + - COPYPASTE # Comment to enable checks of excessive copy-pastes + - SPELL # Comment to enable checks of spelling mistakes +DISABLE_LINTERS: + - DOCKERFILE_DOCKERFILELINT + - MARKDOWN_MARKDOWN_LINK_CHECK + - REPOSITORY_CHECKOV # unstable randomly failed (false negative) on generated k8s manifest + - REPOSITORY_DEVSKIM # issue with "git config --global --add safe.directory ..." + - REPOSITORY_GIT_DIFF + - REPOSITORY_GRYPE + - REPOSITORY_KICS + - REPOSITORY_SYFT + - REPOSITORY_TRUFFLEHOG # too long to search for secret + - RUST_CLIPPY # run via an other way, and current version doesn't support `--deny ... --allow ...` + - SQL_TSQLLINT # "You must install or update .NET to run this application." +SHOW_ELAPSED_TIME: true +FILEIO_REPORTER: false +# DISABLE_ERRORS: true # Uncomment if you want MegaLinter to detect errors but not block CI to pass +FILTER_REGEX_EXCLUDE: "(generated)|(megalinter-reports)|(cdevents-spec.*)|(.gitmodules)|(.sqlx)|(\\.lock)|(\\.ndjson)|(\\.pdf)|(\\.csv)|(\\.zip)|(\\.tar)|(\\.ipynb)|(license.*)|(LICENSE.*)" +SPELL_FILTER_REGEX_INCLUDE: '\\.md$' +PRINT_ALPACA: false +REPOSITORY_SECRETLINT_ARGUMENTS: + - --secretlintignore + - .gitignore +REPOSITORY_TRIVY_ARGUMENTS: + - --skip-dirs + - "cdevents-spec" +RUST_CLIPPY_ARGUMENTS: + - --workspace + - --all-features + - --all-targets + # - --deny warnings + # - --allow deprecated + # - --allow unknown-lints diff --git a/.rtx.toml b/.rtx.toml new file mode 100644 index 0000000..4b21953 --- /dev/null +++ b/.rtx.toml @@ -0,0 +1,8 @@ +[env] +# RUSTC_WRAPPER = "sccache" +RUST_WITHOUT = "rust-docs" +# ASDF_RUST_PROFILE = "minimal" + +[tools] +rust = '1.75' +just = '1' diff --git a/cdevents-sdk/.rustfmt.toml b/cdevents-sdk/.rustfmt.toml new file mode 100644 index 0000000..9dc8a31 --- /dev/null +++ b/cdevents-sdk/.rustfmt.toml @@ -0,0 +1,9 @@ +# see https://rust-lang.github.io/rustfmt/ + +# - disable all formatting until support of `ignore` or `generated` +# - the marker `#![rustfmt::skip]` generates an `error: custom inner attributes are unstable` on clippy,... +disable_all_formatting = true + +# unstable_features = true # nightly only +# ignore = ["generated"] # unstable +# format_generated_files = false # unstable diff --git a/cdevents-spec b/cdevents-spec new file mode 160000 index 0000000..2b63793 --- /dev/null +++ b/cdevents-spec @@ -0,0 +1 @@ +Subproject commit 2b63793165fa609d3a3b954ce71957209e79475e diff --git a/justfile b/justfile new file mode 100644 index 0000000..3ade1e9 --- /dev/null +++ b/justfile @@ -0,0 +1,76 @@ +default: + @just --list --unsorted + +_install_cargo-binstall: + cargo install cargo-binstall + +_install_cargo-nextest: _install_cargo-binstall + cargo binstall cargo-nextest -y + +_install_cargo-insta: _install_cargo-binstall + cargo binstall cargo-insta -y + +_install_cargo-release: _install_cargo-binstall + cargo binstall cargo-release -y + +_install_cargo-hack: _install_cargo-binstall + cargo binstall cargo-hack -y + +_install_cargo-deny: _install_cargo-binstall + cargo binstall cargo-deny -y + +_install_git-cliff: _install_cargo-binstall + cargo binstall git-cliff -y + +check: _install_cargo-hack + cargo hack check --each-feature --no-dev-deps + +generate: + # cd generator; cargo run + cargo run -p generator -- --templates-dir "generator/templates" --jsonschema-dir "cdevents-spec/schemas" --dest "cdevents-sdk/src/generated" + +build: + cargo build + +alias fmt := format + +# Format the code and sort dependencies +format: + cargo fmt + # cargo sort --workspace --grouped + just --unstable --fmt + +deny: _install_cargo-deny + cargo deny check advisories + cargo deny check bans licenses sources + +# Lint all the code (megalinter + lint_rust) +lint: lint_rust megalinter + +# Lint the rust code +lint_rust: + just --unstable --fmt --check + cargo fmt --all -- --check # generated code is not formatted + # cargo sort --workspace --grouped --check + cargo clippy --workspace --all-features --all-targets -- --deny warnings --allow deprecated --allow unknown-lints + +# Lint with megalinter (locally via docker) +megalinter: + # rm -rf megalinter-reports + docker run --rm --name megalinter -it --env "DEFAULT_WORKSPACE=/tmp/lint" -v "${DOCKER_HOST:-/var/run/docker.sock}:/var/run/docker.sock:rw" -v "$PWD:/tmp/lint:rw" "oxsecurity/megalinter:v7" + +# Launch tests +test: _install_cargo-nextest + cargo nextest run + # cargo test --doc + # cargo hack nextest --each-feature -- --test-threads=1 + +changelog: _install_git-cliff + git-cliff -o "CHANGELOG.md" + git add CHANGELOG.md && git commit -m "📝 update CHANGELOG" + +release *arguments: _install_cargo-release _install_git-cliff + cargo release --workspace --execute {{ arguments }} + # git-cliff could not be used as `pre-release-hook` of cargo-release because it uses tag + git-cliff -o "CHANGELOG.md" + git add CHANGELOG.md && git commit -m "📝 update CHANGELOG" && git push From b63b9d6dab2aec2a515c7021940eec94cfd33834 Mon Sep 17 00:00:00 2001 From: David Bernard Date: Thu, 18 Jan 2024 22:48:51 +0100 Subject: [PATCH 14/34] ci: avoid to install cargo-binstall from source Signed-off-by: David Bernard --- justfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/justfile b/justfile index 3ade1e9..91e64ee 100644 --- a/justfile +++ b/justfile @@ -2,7 +2,8 @@ default: @just --list --unsorted _install_cargo-binstall: - cargo install cargo-binstall + # cargo install cargo-binstall + cargo binstall -V || curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash _install_cargo-nextest: _install_cargo-binstall cargo binstall cargo-nextest -y From c2863212c55f313dc81ab9028d99e2cf4d2a9c83 Mon Sep 17 00:00:00 2001 From: David Bernard Date: Sun, 21 Jan 2024 11:47:41 +0100 Subject: [PATCH 15/34] feat: add support for `PartialEq`, `Eq` on `CDEvent`, use wrapper for `Uri` and `UriReference` Signed-off-by: David Bernard --- cdevents-sdk/Cargo.toml | 1 + cdevents-sdk/src/cdevent.rs | 2 +- cdevents-sdk/src/context.rs | 19 +++- cdevents-sdk/src/error.rs | 9 ++ .../src/generated/artifact_packaged.rs | 8 +- .../src/generated/artifact_published.rs | 2 +- cdevents-sdk/src/generated/artifact_signed.rs | 2 +- cdevents-sdk/src/generated/branch_created.rs | 8 +- cdevents-sdk/src/generated/branch_deleted.rs | 8 +- cdevents-sdk/src/generated/build_finished.rs | 2 +- cdevents-sdk/src/generated/build_queued.rs | 2 +- cdevents-sdk/src/generated/build_started.rs | 2 +- .../src/generated/change_abandoned.rs | 8 +- cdevents-sdk/src/generated/change_created.rs | 8 +- cdevents-sdk/src/generated/change_merged.rs | 8 +- cdevents-sdk/src/generated/change_reviewed.rs | 8 +- cdevents-sdk/src/generated/change_updated.rs | 8 +- .../src/generated/environment_created.rs | 2 +- .../src/generated/environment_deleted.rs | 2 +- .../src/generated/environment_modified.rs | 2 +- .../src/generated/incident_detected.rs | 14 +-- .../src/generated/incident_reported.rs | 18 ++-- .../src/generated/incident_resolved.rs | 14 +-- cdevents-sdk/src/generated/mod.rs | 2 +- .../src/generated/pipelinerun_finished.rs | 2 +- .../src/generated/pipelinerun_queued.rs | 2 +- .../src/generated/pipelinerun_started.rs | 2 +- .../src/generated/repository_created.rs | 2 +- .../src/generated/repository_deleted.rs | 2 +- .../src/generated/repository_modified.rs | 2 +- .../src/generated/service_deployed.rs | 8 +- .../src/generated/service_published.rs | 8 +- cdevents-sdk/src/generated/service_removed.rs | 8 +- .../src/generated/service_rolledback.rs | 8 +- .../src/generated/service_upgraded.rs | 8 +- .../src/generated/taskrun_finished.rs | 8 +- cdevents-sdk/src/generated/taskrun_started.rs | 8 +- .../src/generated/testcaserun_finished.rs | 16 ++-- .../src/generated/testcaserun_queued.rs | 22 ++--- .../src/generated/testcaserun_started.rs | 22 ++--- .../src/generated/testoutput_published.rs | 8 +- .../src/generated/testsuiterun_finished.rs | 14 +-- .../src/generated/testsuiterun_queued.rs | 20 ++--- .../src/generated/testsuiterun_started.rs | 20 ++--- cdevents-sdk/src/lib.rs | 6 ++ cdevents-sdk/src/serde.rs | 86 +++++++++++++------ cdevents-sdk/src/subject.rs | 12 +-- cdevents-sdk/src/uri.rs | 71 +++++++++++++++ cdevents-sdk/src/uri_reference.rs | 66 ++++++++++++++ generator/src/main.rs | 9 +- generator/templates/mod.hbs | 2 +- generator/templates/variant.hbs | 2 +- 52 files changed, 400 insertions(+), 203 deletions(-) create mode 100644 cdevents-sdk/src/error.rs create mode 100644 cdevents-sdk/src/uri.rs create mode 100644 cdevents-sdk/src/uri_reference.rs diff --git a/cdevents-sdk/Cargo.toml b/cdevents-sdk/Cargo.toml index 85df285..10d5878 100644 --- a/cdevents-sdk/Cargo.toml +++ b/cdevents-sdk/Cargo.toml @@ -16,6 +16,7 @@ publish = true fluent-uri = "0.1" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" +thiserror = "1.0" time = { version = "0.3", features = ["serde-human-readable"] } [dev-dependencies] diff --git a/cdevents-sdk/src/cdevent.rs b/cdevents-sdk/src/cdevent.rs index dadc199..6325762 100644 --- a/cdevents-sdk/src/cdevent.rs +++ b/cdevents-sdk/src/cdevent.rs @@ -5,7 +5,7 @@ use serde::{ }; use std::fmt; -#[derive(Debug, Clone, Serialize)] +#[derive(Debug, Clone, Serialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct CDEvent { pub context: Context, diff --git a/cdevents-sdk/src/context.rs b/cdevents-sdk/src/context.rs index be3d836..5d7658c 100644 --- a/cdevents-sdk/src/context.rs +++ b/cdevents-sdk/src/context.rs @@ -1,14 +1,27 @@ use serde::{Deserialize, Serialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] +use crate::UriReference; + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Context { pub version: String, pub id: String, - #[serde(with = "crate::serde::uri_reference")] - pub source: fluent_uri::Uri, + pub source: UriReference, #[serde(rename = "type")] pub r#type: String, #[serde(with = "crate::serde::datetime")] pub timestamp: time::OffsetDateTime, } + +impl Default for Context { + fn default() -> Self { + Self { + version: "0.3.0".into(), + id: "00000000-0000-0000-0000-000000000000".into(), + source: UriReference::default(), + r#type: "dev.cdevents.undef.undef.0.0.0".into(), + timestamp: time::OffsetDateTime::now_utc(), + } + } +} diff --git a/cdevents-sdk/src/error.rs b/cdevents-sdk/src/error.rs new file mode 100644 index 0000000..a5afdc5 --- /dev/null +++ b/cdevents-sdk/src/error.rs @@ -0,0 +1,9 @@ +use thiserror::Error; + +#[derive(Error, Debug)] +pub enum Error { + #[error(transparent)] + UriParseError( #[from] fluent_uri::ParseError), + #[error("unknown error")] + Unknown, +} diff --git a/cdevents-sdk/src/generated/artifact_packaged.rs b/cdevents-sdk/src/generated/artifact_packaged.rs index 46d7918..a8fe025 100644 --- a/cdevents-sdk/src/generated/artifact_packaged.rs +++ b/cdevents-sdk/src/generated/artifact_packaged.rs @@ -3,19 +3,19 @@ use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "change",)] pub change: Change, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Change { #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] - pub source: Option>, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] + pub source: Option, } diff --git a/cdevents-sdk/src/generated/artifact_published.rs b/cdevents-sdk/src/generated/artifact_published.rs index 4d0f724..e80c34f 100644 --- a/cdevents-sdk/src/generated/artifact_published.rs +++ b/cdevents-sdk/src/generated/artifact_published.rs @@ -3,7 +3,7 @@ use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Content { } diff --git a/cdevents-sdk/src/generated/artifact_signed.rs b/cdevents-sdk/src/generated/artifact_signed.rs index 18bbaf8..25a9d3b 100644 --- a/cdevents-sdk/src/generated/artifact_signed.rs +++ b/cdevents-sdk/src/generated/artifact_signed.rs @@ -3,7 +3,7 @@ use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "signature",)] diff --git a/cdevents-sdk/src/generated/branch_created.rs b/cdevents-sdk/src/generated/branch_created.rs index afa2999..65e29b9 100644 --- a/cdevents-sdk/src/generated/branch_created.rs +++ b/cdevents-sdk/src/generated/branch_created.rs @@ -3,19 +3,19 @@ use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "repository", default, skip_serializing_if = "Option::is_none",)] pub repository: Option, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Repository { #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] - pub source: Option>, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] + pub source: Option, } diff --git a/cdevents-sdk/src/generated/branch_deleted.rs b/cdevents-sdk/src/generated/branch_deleted.rs index afa2999..65e29b9 100644 --- a/cdevents-sdk/src/generated/branch_deleted.rs +++ b/cdevents-sdk/src/generated/branch_deleted.rs @@ -3,19 +3,19 @@ use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "repository", default, skip_serializing_if = "Option::is_none",)] pub repository: Option, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Repository { #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] - pub source: Option>, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] + pub source: Option, } diff --git a/cdevents-sdk/src/generated/build_finished.rs b/cdevents-sdk/src/generated/build_finished.rs index a0b451f..1141db9 100644 --- a/cdevents-sdk/src/generated/build_finished.rs +++ b/cdevents-sdk/src/generated/build_finished.rs @@ -3,7 +3,7 @@ use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "artifactId", default, skip_serializing_if = "Option::is_none",)] diff --git a/cdevents-sdk/src/generated/build_queued.rs b/cdevents-sdk/src/generated/build_queued.rs index 4d0f724..e80c34f 100644 --- a/cdevents-sdk/src/generated/build_queued.rs +++ b/cdevents-sdk/src/generated/build_queued.rs @@ -3,7 +3,7 @@ use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Content { } diff --git a/cdevents-sdk/src/generated/build_started.rs b/cdevents-sdk/src/generated/build_started.rs index 4d0f724..e80c34f 100644 --- a/cdevents-sdk/src/generated/build_started.rs +++ b/cdevents-sdk/src/generated/build_started.rs @@ -3,7 +3,7 @@ use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Content { } diff --git a/cdevents-sdk/src/generated/change_abandoned.rs b/cdevents-sdk/src/generated/change_abandoned.rs index afa2999..65e29b9 100644 --- a/cdevents-sdk/src/generated/change_abandoned.rs +++ b/cdevents-sdk/src/generated/change_abandoned.rs @@ -3,19 +3,19 @@ use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "repository", default, skip_serializing_if = "Option::is_none",)] pub repository: Option, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Repository { #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] - pub source: Option>, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] + pub source: Option, } diff --git a/cdevents-sdk/src/generated/change_created.rs b/cdevents-sdk/src/generated/change_created.rs index afa2999..65e29b9 100644 --- a/cdevents-sdk/src/generated/change_created.rs +++ b/cdevents-sdk/src/generated/change_created.rs @@ -3,19 +3,19 @@ use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "repository", default, skip_serializing_if = "Option::is_none",)] pub repository: Option, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Repository { #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] - pub source: Option>, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] + pub source: Option, } diff --git a/cdevents-sdk/src/generated/change_merged.rs b/cdevents-sdk/src/generated/change_merged.rs index afa2999..65e29b9 100644 --- a/cdevents-sdk/src/generated/change_merged.rs +++ b/cdevents-sdk/src/generated/change_merged.rs @@ -3,19 +3,19 @@ use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "repository", default, skip_serializing_if = "Option::is_none",)] pub repository: Option, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Repository { #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] - pub source: Option>, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] + pub source: Option, } diff --git a/cdevents-sdk/src/generated/change_reviewed.rs b/cdevents-sdk/src/generated/change_reviewed.rs index afa2999..65e29b9 100644 --- a/cdevents-sdk/src/generated/change_reviewed.rs +++ b/cdevents-sdk/src/generated/change_reviewed.rs @@ -3,19 +3,19 @@ use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "repository", default, skip_serializing_if = "Option::is_none",)] pub repository: Option, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Repository { #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] - pub source: Option>, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] + pub source: Option, } diff --git a/cdevents-sdk/src/generated/change_updated.rs b/cdevents-sdk/src/generated/change_updated.rs index afa2999..65e29b9 100644 --- a/cdevents-sdk/src/generated/change_updated.rs +++ b/cdevents-sdk/src/generated/change_updated.rs @@ -3,19 +3,19 @@ use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "repository", default, skip_serializing_if = "Option::is_none",)] pub repository: Option, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Repository { #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] - pub source: Option>, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] + pub source: Option, } diff --git a/cdevents-sdk/src/generated/environment_created.rs b/cdevents-sdk/src/generated/environment_created.rs index 79fbb07..e2f42cc 100644 --- a/cdevents-sdk/src/generated/environment_created.rs +++ b/cdevents-sdk/src/generated/environment_created.rs @@ -3,7 +3,7 @@ use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "name", default, skip_serializing_if = "Option::is_none",)] diff --git a/cdevents-sdk/src/generated/environment_deleted.rs b/cdevents-sdk/src/generated/environment_deleted.rs index 99d4138..d436795 100644 --- a/cdevents-sdk/src/generated/environment_deleted.rs +++ b/cdevents-sdk/src/generated/environment_deleted.rs @@ -3,7 +3,7 @@ use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "name", default, skip_serializing_if = "Option::is_none",)] diff --git a/cdevents-sdk/src/generated/environment_modified.rs b/cdevents-sdk/src/generated/environment_modified.rs index 79fbb07..e2f42cc 100644 --- a/cdevents-sdk/src/generated/environment_modified.rs +++ b/cdevents-sdk/src/generated/environment_modified.rs @@ -3,7 +3,7 @@ use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "name", default, skip_serializing_if = "Option::is_none",)] diff --git a/cdevents-sdk/src/generated/incident_detected.rs b/cdevents-sdk/src/generated/incident_detected.rs index c7bf3e1..a2f4d67 100644 --- a/cdevents-sdk/src/generated/incident_detected.rs +++ b/cdevents-sdk/src/generated/incident_detected.rs @@ -3,7 +3,7 @@ use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "artifactId", default, skip_serializing_if = "Option::is_none",)] @@ -16,21 +16,21 @@ pub struct Content { pub service: Option, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Service { #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] - pub source: Option>, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] + pub source: Option, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Environment { #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] - pub source: Option>, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] + pub source: Option, } diff --git a/cdevents-sdk/src/generated/incident_reported.rs b/cdevents-sdk/src/generated/incident_reported.rs index 070a784..fb70170 100644 --- a/cdevents-sdk/src/generated/incident_reported.rs +++ b/cdevents-sdk/src/generated/incident_reported.rs @@ -3,7 +3,7 @@ use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "artifactId", default, skip_serializing_if = "Option::is_none",)] @@ -14,25 +14,25 @@ pub struct Content { pub environment: Environment, #[serde(rename = "service", default, skip_serializing_if = "Option::is_none",)] pub service: Option, - #[serde(rename = "ticketURI", with = "crate::serde::uri",)] - pub ticket_uri: fluent_uri::Uri, + #[serde(rename = "ticketURI",)] + pub ticket_uri: crate::Uri, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Service { #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] - pub source: Option>, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] + pub source: Option, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Environment { #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] - pub source: Option>, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] + pub source: Option, } diff --git a/cdevents-sdk/src/generated/incident_resolved.rs b/cdevents-sdk/src/generated/incident_resolved.rs index c7bf3e1..a2f4d67 100644 --- a/cdevents-sdk/src/generated/incident_resolved.rs +++ b/cdevents-sdk/src/generated/incident_resolved.rs @@ -3,7 +3,7 @@ use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "artifactId", default, skip_serializing_if = "Option::is_none",)] @@ -16,21 +16,21 @@ pub struct Content { pub service: Option, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Service { #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] - pub source: Option>, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] + pub source: Option, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Environment { #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] - pub source: Option>, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] + pub source: Option, } diff --git a/cdevents-sdk/src/generated/mod.rs b/cdevents-sdk/src/generated/mod.rs index 4efc969..3facfa3 100644 --- a/cdevents-sdk/src/generated/mod.rs +++ b/cdevents-sdk/src/generated/mod.rs @@ -85,7 +85,7 @@ pub const TESTSUITERUN_FINISHED: &str = "dev.cdevents.testsuiterun.finished.0.1. pub const TESTSUITERUN_QUEUED: &str = "dev.cdevents.testsuiterun.queued.0.1.0"; pub const TESTSUITERUN_STARTED: &str = "dev.cdevents.testsuiterun.started.0.1.0"; -#[derive(Debug,Clone,Serialize,Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(untagged)] // TODO how to use content of context.type as discriminator ? pub enum Content { ArtifactPackaged(artifact_packaged::Content), diff --git a/cdevents-sdk/src/generated/pipelinerun_finished.rs b/cdevents-sdk/src/generated/pipelinerun_finished.rs index dfb1ada..953e175 100644 --- a/cdevents-sdk/src/generated/pipelinerun_finished.rs +++ b/cdevents-sdk/src/generated/pipelinerun_finished.rs @@ -3,7 +3,7 @@ use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "errors", default, skip_serializing_if = "Option::is_none",)] diff --git a/cdevents-sdk/src/generated/pipelinerun_queued.rs b/cdevents-sdk/src/generated/pipelinerun_queued.rs index 365e8bd..f949258 100644 --- a/cdevents-sdk/src/generated/pipelinerun_queued.rs +++ b/cdevents-sdk/src/generated/pipelinerun_queued.rs @@ -3,7 +3,7 @@ use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "pipelineName", default, skip_serializing_if = "Option::is_none",)] diff --git a/cdevents-sdk/src/generated/pipelinerun_started.rs b/cdevents-sdk/src/generated/pipelinerun_started.rs index 564eeb0..0939cd8 100644 --- a/cdevents-sdk/src/generated/pipelinerun_started.rs +++ b/cdevents-sdk/src/generated/pipelinerun_started.rs @@ -3,7 +3,7 @@ use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "pipelineName",)] diff --git a/cdevents-sdk/src/generated/repository_created.rs b/cdevents-sdk/src/generated/repository_created.rs index 8eeb683..85060ef 100644 --- a/cdevents-sdk/src/generated/repository_created.rs +++ b/cdevents-sdk/src/generated/repository_created.rs @@ -3,7 +3,7 @@ use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "name",)] diff --git a/cdevents-sdk/src/generated/repository_deleted.rs b/cdevents-sdk/src/generated/repository_deleted.rs index 82eb5c6..6334f12 100644 --- a/cdevents-sdk/src/generated/repository_deleted.rs +++ b/cdevents-sdk/src/generated/repository_deleted.rs @@ -3,7 +3,7 @@ use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "name", default, skip_serializing_if = "Option::is_none",)] diff --git a/cdevents-sdk/src/generated/repository_modified.rs b/cdevents-sdk/src/generated/repository_modified.rs index 82eb5c6..6334f12 100644 --- a/cdevents-sdk/src/generated/repository_modified.rs +++ b/cdevents-sdk/src/generated/repository_modified.rs @@ -3,7 +3,7 @@ use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "name", default, skip_serializing_if = "Option::is_none",)] diff --git a/cdevents-sdk/src/generated/service_deployed.rs b/cdevents-sdk/src/generated/service_deployed.rs index 048a691..868b9fe 100644 --- a/cdevents-sdk/src/generated/service_deployed.rs +++ b/cdevents-sdk/src/generated/service_deployed.rs @@ -3,7 +3,7 @@ use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "artifactId",)] @@ -12,12 +12,12 @@ pub struct Content { pub environment: Environment, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Environment { #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] - pub source: Option>, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] + pub source: Option, } diff --git a/cdevents-sdk/src/generated/service_published.rs b/cdevents-sdk/src/generated/service_published.rs index b894eaf..eaf2687 100644 --- a/cdevents-sdk/src/generated/service_published.rs +++ b/cdevents-sdk/src/generated/service_published.rs @@ -3,19 +3,19 @@ use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "environment", default, skip_serializing_if = "Option::is_none",)] pub environment: Option, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Environment { #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] - pub source: Option>, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] + pub source: Option, } diff --git a/cdevents-sdk/src/generated/service_removed.rs b/cdevents-sdk/src/generated/service_removed.rs index b894eaf..eaf2687 100644 --- a/cdevents-sdk/src/generated/service_removed.rs +++ b/cdevents-sdk/src/generated/service_removed.rs @@ -3,19 +3,19 @@ use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "environment", default, skip_serializing_if = "Option::is_none",)] pub environment: Option, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Environment { #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] - pub source: Option>, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] + pub source: Option, } diff --git a/cdevents-sdk/src/generated/service_rolledback.rs b/cdevents-sdk/src/generated/service_rolledback.rs index 048a691..868b9fe 100644 --- a/cdevents-sdk/src/generated/service_rolledback.rs +++ b/cdevents-sdk/src/generated/service_rolledback.rs @@ -3,7 +3,7 @@ use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "artifactId",)] @@ -12,12 +12,12 @@ pub struct Content { pub environment: Environment, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Environment { #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] - pub source: Option>, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] + pub source: Option, } diff --git a/cdevents-sdk/src/generated/service_upgraded.rs b/cdevents-sdk/src/generated/service_upgraded.rs index 048a691..868b9fe 100644 --- a/cdevents-sdk/src/generated/service_upgraded.rs +++ b/cdevents-sdk/src/generated/service_upgraded.rs @@ -3,7 +3,7 @@ use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "artifactId",)] @@ -12,12 +12,12 @@ pub struct Content { pub environment: Environment, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Environment { #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] - pub source: Option>, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] + pub source: Option, } diff --git a/cdevents-sdk/src/generated/taskrun_finished.rs b/cdevents-sdk/src/generated/taskrun_finished.rs index 9d2fa66..5259c46 100644 --- a/cdevents-sdk/src/generated/taskrun_finished.rs +++ b/cdevents-sdk/src/generated/taskrun_finished.rs @@ -3,7 +3,7 @@ use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "errors", default, skip_serializing_if = "Option::is_none",)] @@ -18,12 +18,12 @@ pub struct Content { pub url: Option, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct PipelineRun { #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] - pub source: Option>, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] + pub source: Option, } diff --git a/cdevents-sdk/src/generated/taskrun_started.rs b/cdevents-sdk/src/generated/taskrun_started.rs index 6600fd4..d294376 100644 --- a/cdevents-sdk/src/generated/taskrun_started.rs +++ b/cdevents-sdk/src/generated/taskrun_started.rs @@ -3,7 +3,7 @@ use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "pipelineRun", default, skip_serializing_if = "Option::is_none",)] @@ -14,12 +14,12 @@ pub struct Content { pub url: Option, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct PipelineRun { #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] - pub source: Option>, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] + pub source: Option, } diff --git a/cdevents-sdk/src/generated/testcaserun_finished.rs b/cdevents-sdk/src/generated/testcaserun_finished.rs index d812055..68bfcc2 100644 --- a/cdevents-sdk/src/generated/testcaserun_finished.rs +++ b/cdevents-sdk/src/generated/testcaserun_finished.rs @@ -3,7 +3,7 @@ use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "environment",)] @@ -20,7 +20,7 @@ pub struct Content { pub test_suite_run: Option, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct TestSuiteRun { #[serde(rename = "id",)] @@ -29,7 +29,7 @@ pub struct TestSuiteRun { pub source: Option, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct TestCase { #[serde(rename = "id",)] @@ -38,18 +38,18 @@ pub struct TestCase { pub name: Option, #[serde(rename = "type", default, skip_serializing_if = "Option::is_none",)] pub r#type: Option, - #[serde(rename = "uri", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_optional",)] - pub uri: Option>, + #[serde(rename = "uri", default, skip_serializing_if = "Option::is_none",)] + pub uri: Option, #[serde(rename = "version", default, skip_serializing_if = "Option::is_none",)] pub version: Option, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Environment { #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] - pub source: Option>, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] + pub source: Option, } diff --git a/cdevents-sdk/src/generated/testcaserun_queued.rs b/cdevents-sdk/src/generated/testcaserun_queued.rs index 06e1aff..eab0fd4 100644 --- a/cdevents-sdk/src/generated/testcaserun_queued.rs +++ b/cdevents-sdk/src/generated/testcaserun_queued.rs @@ -3,7 +3,7 @@ use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "environment",)] @@ -16,16 +16,16 @@ pub struct Content { pub trigger: Option, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Trigger { #[serde(rename = "type", default, skip_serializing_if = "Option::is_none",)] pub r#type: Option, - #[serde(rename = "uri", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_optional",)] - pub uri: Option>, + #[serde(rename = "uri", default, skip_serializing_if = "Option::is_none",)] + pub uri: Option, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct TestSuiteRun { #[serde(rename = "id",)] @@ -34,7 +34,7 @@ pub struct TestSuiteRun { pub source: Option, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct TestCase { #[serde(rename = "id",)] @@ -43,18 +43,18 @@ pub struct TestCase { pub name: Option, #[serde(rename = "type", default, skip_serializing_if = "Option::is_none",)] pub r#type: Option, - #[serde(rename = "uri", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_optional",)] - pub uri: Option>, + #[serde(rename = "uri", default, skip_serializing_if = "Option::is_none",)] + pub uri: Option, #[serde(rename = "version", default, skip_serializing_if = "Option::is_none",)] pub version: Option, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Environment { #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] - pub source: Option>, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] + pub source: Option, } diff --git a/cdevents-sdk/src/generated/testcaserun_started.rs b/cdevents-sdk/src/generated/testcaserun_started.rs index 06e1aff..eab0fd4 100644 --- a/cdevents-sdk/src/generated/testcaserun_started.rs +++ b/cdevents-sdk/src/generated/testcaserun_started.rs @@ -3,7 +3,7 @@ use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "environment",)] @@ -16,16 +16,16 @@ pub struct Content { pub trigger: Option, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Trigger { #[serde(rename = "type", default, skip_serializing_if = "Option::is_none",)] pub r#type: Option, - #[serde(rename = "uri", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_optional",)] - pub uri: Option>, + #[serde(rename = "uri", default, skip_serializing_if = "Option::is_none",)] + pub uri: Option, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct TestSuiteRun { #[serde(rename = "id",)] @@ -34,7 +34,7 @@ pub struct TestSuiteRun { pub source: Option, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct TestCase { #[serde(rename = "id",)] @@ -43,18 +43,18 @@ pub struct TestCase { pub name: Option, #[serde(rename = "type", default, skip_serializing_if = "Option::is_none",)] pub r#type: Option, - #[serde(rename = "uri", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_optional",)] - pub uri: Option>, + #[serde(rename = "uri", default, skip_serializing_if = "Option::is_none",)] + pub uri: Option, #[serde(rename = "version", default, skip_serializing_if = "Option::is_none",)] pub version: Option, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Environment { #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] - pub source: Option>, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] + pub source: Option, } diff --git a/cdevents-sdk/src/generated/testoutput_published.rs b/cdevents-sdk/src/generated/testoutput_published.rs index b244d46..c16158b 100644 --- a/cdevents-sdk/src/generated/testoutput_published.rs +++ b/cdevents-sdk/src/generated/testoutput_published.rs @@ -3,7 +3,7 @@ use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "format",)] @@ -12,11 +12,11 @@ pub struct Content { pub output_type: String, #[serde(rename = "testCaseRun", default, skip_serializing_if = "Option::is_none",)] pub test_case_run: Option, - #[serde(rename = "uri", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_optional",)] - pub uri: Option>, + #[serde(rename = "uri", default, skip_serializing_if = "Option::is_none",)] + pub uri: Option, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct TestCaseRun { #[serde(rename = "id",)] diff --git a/cdevents-sdk/src/generated/testsuiterun_finished.rs b/cdevents-sdk/src/generated/testsuiterun_finished.rs index aceeb10..9f384bc 100644 --- a/cdevents-sdk/src/generated/testsuiterun_finished.rs +++ b/cdevents-sdk/src/generated/testsuiterun_finished.rs @@ -3,7 +3,7 @@ use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "environment",)] @@ -18,25 +18,25 @@ pub struct Content { pub test_suite: Option, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct TestSuite { #[serde(rename = "id",)] pub id: String, #[serde(rename = "name", default, skip_serializing_if = "Option::is_none",)] pub name: Option, - #[serde(rename = "uri", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_optional",)] - pub uri: Option>, + #[serde(rename = "uri", default, skip_serializing_if = "Option::is_none",)] + pub uri: Option, #[serde(rename = "version", default, skip_serializing_if = "Option::is_none",)] pub version: Option, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Environment { #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] - pub source: Option>, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] + pub source: Option, } diff --git a/cdevents-sdk/src/generated/testsuiterun_queued.rs b/cdevents-sdk/src/generated/testsuiterun_queued.rs index 49265bf..15bb6bc 100644 --- a/cdevents-sdk/src/generated/testsuiterun_queued.rs +++ b/cdevents-sdk/src/generated/testsuiterun_queued.rs @@ -3,7 +3,7 @@ use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "environment",)] @@ -14,34 +14,34 @@ pub struct Content { pub trigger: Option, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Trigger { #[serde(rename = "type", default, skip_serializing_if = "Option::is_none",)] pub r#type: Option, - #[serde(rename = "uri", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_optional",)] - pub uri: Option>, + #[serde(rename = "uri", default, skip_serializing_if = "Option::is_none",)] + pub uri: Option, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct TestSuite { #[serde(rename = "id",)] pub id: String, #[serde(rename = "name", default, skip_serializing_if = "Option::is_none",)] pub name: Option, - #[serde(rename = "url", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_optional",)] - pub url: Option>, + #[serde(rename = "url", default, skip_serializing_if = "Option::is_none",)] + pub url: Option, #[serde(rename = "version", default, skip_serializing_if = "Option::is_none",)] pub version: Option, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Environment { #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] - pub source: Option>, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] + pub source: Option, } diff --git a/cdevents-sdk/src/generated/testsuiterun_started.rs b/cdevents-sdk/src/generated/testsuiterun_started.rs index cd88a72..dea3cb7 100644 --- a/cdevents-sdk/src/generated/testsuiterun_started.rs +++ b/cdevents-sdk/src/generated/testsuiterun_started.rs @@ -3,7 +3,7 @@ use serde::{Serialize, Deserialize}; -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "environment",)] @@ -14,34 +14,34 @@ pub struct Content { pub trigger: Option, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Trigger { #[serde(rename = "type", default, skip_serializing_if = "Option::is_none",)] pub r#type: Option, - #[serde(rename = "uri", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_optional",)] - pub uri: Option>, + #[serde(rename = "uri", default, skip_serializing_if = "Option::is_none",)] + pub uri: Option, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct TestSuite { #[serde(rename = "id",)] pub id: String, #[serde(rename = "name", default, skip_serializing_if = "Option::is_none",)] pub name: Option, - #[serde(rename = "uri", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_optional",)] - pub uri: Option>, + #[serde(rename = "uri", default, skip_serializing_if = "Option::is_none",)] + pub uri: Option, #[serde(rename = "version", default, skip_serializing_if = "Option::is_none",)] pub version: Option, } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Environment { #[serde(rename = "id",)] pub id: String, - #[serde(rename = "source", default, skip_serializing_if = "Option::is_none", with = "crate::serde::uri_reference_optional",)] - pub source: Option>, + #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] + pub source: Option, } diff --git a/cdevents-sdk/src/lib.rs b/cdevents-sdk/src/lib.rs index d4be46c..ea76d6c 100644 --- a/cdevents-sdk/src/lib.rs +++ b/cdevents-sdk/src/lib.rs @@ -2,11 +2,17 @@ // TODO reduce clone() mod cdevent; mod context; +mod error; mod generated; pub(crate) mod serde; mod subject; +mod uri; +mod uri_reference; pub use cdevent::*; pub use context::*; +pub use error::*; pub use generated::*; pub use subject::*; +pub use uri::*; +pub use uri_reference::*; diff --git a/cdevents-sdk/src/serde.rs b/cdevents-sdk/src/serde.rs index b0eca8a..6865b3d 100644 --- a/cdevents-sdk/src/serde.rs +++ b/cdevents-sdk/src/serde.rs @@ -26,38 +26,70 @@ pub(crate) mod datetime { } } -pub(crate) use uri_reference as uri; -pub(crate) use uri_reference_optional as uri_optional; +// pub(crate) fn ok_or_none<'de, D, T>(deserializer: D) -> Result, D::Error> +// where +// D: Deserializer<'de>, +// T: Deserialize<'de>, +// { +// let v = Value::deserialize(deserializer)?; +// Ok(T::deserialize(v).ok()) +// } -pub(crate) mod uri_reference_optional { - use serde::{Deserialize, Deserializer, Serializer}; +// pub(crate) mod ok_or_none { +// use serde::{Deserialize, Deserializer, Serializer}; - #[derive(Deserialize)] - struct Wrapper(#[serde(with = "crate::serde::uri_reference")] fluent_uri::Uri); +// pub fn deserialize<'de, D, T>(deserializer: D) -> Result, D::Error> +// where +// D: Deserializer<'de>, +// T: Deserialize<'de>, +// { +// let v = Option::deserialize(deserializer)?; +// Ok(T::deserialize(v).ok()) +// } - pub fn deserialize<'de, D>(deserializer: D) -> Result>, D::Error> - where - D: Deserializer<'de>, - { - let v = Option::deserialize(deserializer)?; - Ok(v.map(|Wrapper(a)| a)) - } +// pub fn serialize( +// input: &Option>, +// serializer: S, +// ) -> Result +// where +// S: Serializer, +// { +// match input { +// None => serializer.serialize_none(), +// Some(input) => crate::serde::uri_reference::serialize(input, serializer), +// } +// } +// } - pub fn serialize( - input: &Option>, - serializer: S, - ) -> Result - where - S: Serializer, - { - match input { - None => serializer.serialize_none(), - Some(input) => crate::serde::uri_reference::serialize(input, serializer), - } - } -} +// pub(crate) mod uri_reference_optional { +// use serde::{Deserialize, Deserializer, Serializer}; + +// #[derive(Deserialize)] +// struct Wrapper(#[serde(with = "crate::serde::uri_reference")] fluent_uri::Uri); + +// pub fn deserialize<'de, D>(deserializer: D) -> Result>, D::Error> +// where +// D: Deserializer<'de>, +// { +// let v = Option::deserialize(deserializer)?; +// Ok(v.map(|Wrapper(a)| a)) +// } + +// pub fn serialize( +// input: &Option>, +// serializer: S, +// ) -> Result +// where +// S: Serializer, +// { +// match input { +// None => serializer.serialize_none(), +// Some(input) => crate::serde::uri_reference::serialize(input, serializer), +// } +// } +// } -pub(crate) mod uri_reference { +pub(crate) mod fluent_uri { use serde::{de::Error, Deserialize, Deserializer, Serializer}; pub fn deserialize<'de, D>(deserializer: D) -> Result, D::Error> diff --git a/cdevents-sdk/src/subject.rs b/cdevents-sdk/src/subject.rs index 1108c5f..e91bc25 100644 --- a/cdevents-sdk/src/subject.rs +++ b/cdevents-sdk/src/subject.rs @@ -1,8 +1,10 @@ +use std::str::FromStr; + use serde::{Deserialize, Serialize}; -use crate::Content; +use crate::{Content, UriReference}; -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Subject { #[serde(rename = "content")] @@ -13,9 +15,8 @@ pub struct Subject { rename = "source", default, skip_serializing_if = "Option::is_none", - with = "crate::serde::uri_reference_optional" )] - pub source: Option>, + pub source: Option, #[serde(rename = "type")] pub r#type: String, } @@ -34,8 +35,7 @@ impl Subject { source: match json["source"].as_str() { None => None, Some(s) => Some( - fluent_uri::Uri::parse_from(s.to_owned()) - .map_err(|e| serde::de::Error::custom(e.1))?, + UriReference::from_str(s).map_err(serde::de::Error::custom)?, ), }, content: Content::from_json(ty, json["content"].clone())?, diff --git a/cdevents-sdk/src/uri.rs b/cdevents-sdk/src/uri.rs new file mode 100644 index 0000000..0c5fd4a --- /dev/null +++ b/cdevents-sdk/src/uri.rs @@ -0,0 +1,71 @@ +// wrapper for fluent_uri::Uri to allow for restristed set of operations +// and to complete currently missing features. +//TODO impl the check difference for URI and Uri + +use std::str::FromStr; + +use serde::{Serialize, Deserialize}; + +use crate::UriReference; + +#[derive(Debug, Clone, Default, Serialize, Deserialize)] +pub struct Uri(#[serde(with = "crate::serde::fluent_uri")] pub(crate) fluent_uri::Uri); + +impl PartialEq for Uri { + fn eq(&self, other: &Self) -> bool { + self.0.as_str() == other.0.as_str() + } +} + +impl Eq for Uri {} + +impl FromStr for Uri { + type Err = crate::Error; + + fn from_str(s: &str) -> Result { + //TODO check it's not a reference URI + fluent_uri::Uri::parse_from(s.to_owned()).map_err(|(_,e)| e.into()).map(Uri) + } +} + +impl TryFrom for Uri { + type Error = crate::Error; + + fn try_from(s: UriReference) -> Result { + Uri::from_str(s.as_str()) + } +} + +impl TryFrom<&str> for Uri { + type Error = crate::Error; + + fn try_from(s: &str) -> Result { + fluent_uri::Uri::parse_from(s.to_owned()).map_err(|(_,e)| e.into()).map(Uri) + } +} + +impl TryFrom for Uri { + type Error = crate::Error; + + fn try_from(s: String) -> Result { + fluent_uri::Uri::parse_from(s).map_err(|(_,e)| e.into()).map(Uri) + } +} + +impl ToString for Uri { + fn to_string(&self) -> String { + self.0.as_str().to_owned()//into_string() + } +} + +impl Uri { + pub fn as_str(&self) -> &str { + self.0.as_str() + } +} + +// impl From for fluent_uri::Uri { +// fn from(uri: Uri) -> Self { +// uri.0 +// } +// } diff --git a/cdevents-sdk/src/uri_reference.rs b/cdevents-sdk/src/uri_reference.rs new file mode 100644 index 0000000..4e910ba --- /dev/null +++ b/cdevents-sdk/src/uri_reference.rs @@ -0,0 +1,66 @@ +use std::str::FromStr; + +use serde::{Serialize, Deserialize}; + +use crate::Uri; + +#[derive(Debug, Clone, Default, Serialize, Deserialize)] +pub struct UriReference(#[serde(with = "crate::serde::fluent_uri")] pub(crate) fluent_uri::Uri); + +impl PartialEq for UriReference { + fn eq(&self, other: &Self) -> bool { + self.0.as_str() == other.0.as_str() + } +} + +impl Eq for UriReference {} + +impl FromStr for UriReference { + type Err = crate::Error; + + fn from_str(s: &str) -> Result { + fluent_uri::Uri::parse_from(s.to_owned()).map_err(|(_,e)| e.into()).map(UriReference) + } +} + +impl TryFrom for UriReference { + type Error = crate::Error; + + fn try_from(s: Uri) -> Result { + Ok(UriReference(s.0)) + } +} + +impl TryFrom<&str> for UriReference { + type Error = crate::Error; + + fn try_from(s: &str) -> Result { + fluent_uri::Uri::parse_from(s.to_owned()).map_err(|(_,e)| e.into()).map(UriReference) + } +} + +impl TryFrom for UriReference { + type Error = crate::Error; + + fn try_from(s: String) -> Result { + fluent_uri::Uri::parse_from(s).map_err(|(_,e)| e.into()).map(UriReference) + } +} + +impl ToString for UriReference { + fn to_string(&self) -> String { + self.0.as_str().to_owned()//into_string() + } +} + +impl UriReference { + pub fn as_str(&self) -> &str { + self.0.as_str() + } +} + +// impl From for fluent_uri::Uri { +// fn from(uri: UriReference) -> Self { +// uri.0 +// } +// } diff --git a/generator/src/main.rs b/generator/src/main.rs index 532d8c8..22f5e10 100644 --- a/generator/src/main.rs +++ b/generator/src/main.rs @@ -160,17 +160,16 @@ fn collect_structs( }, //TODO manage purl Some("uri-reference") => TypeInfo { - type_declaration: "fluent_uri::Uri".to_string(), - serde_with: Some("crate::serde::uri_reference".to_string()), + type_declaration: "crate::UriReference".to_string(), + serde_with: None, }, Some("uri") => TypeInfo { - type_declaration: "fluent_uri::Uri".to_string(), - serde_with: Some("crate::serde::uri".to_string()), + type_declaration: "crate::Uri".to_string(), + serde_with: None, }, // Some("uri") => TypeInfo { // type_declaration: "http::Uri".to_string(), // serde_with: Some("crate::serde::uri".to_string()), - // ..Default::default() // }, //TODO manage enum _ => TypeInfo { diff --git a/generator/templates/mod.hbs b/generator/templates/mod.hbs index e01a066..1384284 100644 --- a/generator/templates/mod.hbs +++ b/generator/templates/mod.hbs @@ -13,7 +13,7 @@ use serde::{Serialize, Deserialize}; pub const {{to_screaming_snake_case this.rust_module}}: &str = "{{ this.context_type }}"; {{/each}} -#[derive(Debug,Clone,Serialize,Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(untagged)] // TODO how to use content of context.type as discriminator ? pub enum Content { {{#each variants }} diff --git a/generator/templates/variant.hbs b/generator/templates/variant.hbs index 0b3fa2e..f98780a 100644 --- a/generator/templates/variant.hbs +++ b/generator/templates/variant.hbs @@ -4,7 +4,7 @@ use serde::{Serialize, Deserialize}; {{#each structs }} -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct {{ this.type_info.type_declaration }} { {{#each this.fields }} From 8d5586f360871511376edaa9995805e420b3f4e6 Mon Sep 17 00:00:00 2001 From: David Bernard Date: Sun, 21 Jan 2024 18:02:09 +0100 Subject: [PATCH 16/34] feat: introduce support for cloudevents Signed-off-by: David Bernard --- Cargo.toml | 2 +- README.md | 74 +++++++++--- cdevents-sdk/Cargo.toml | 11 +- cdevents-sdk/examples/pipelinerun_finished.rs | 50 +++++++++ cdevents-sdk/src/cloudevents.rs | 106 ++++++++++++++++++ cdevents-sdk/src/error.rs | 4 + cdevents-sdk/src/lib.rs | 4 + justfile | 14 ++- rust-toolchain.toml | 2 + 9 files changed, 240 insertions(+), 27 deletions(-) create mode 100644 cdevents-sdk/examples/pipelinerun_finished.rs create mode 100644 cdevents-sdk/src/cloudevents.rs create mode 100644 rust-toolchain.toml diff --git a/Cargo.toml b/Cargo.toml index cd66051..8609fad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ members = ["cdevents-sdk", "generator"] [workspace.package] edition = "2021" -version = "0.3.0" +version = "0.1.0" authors = ["David Bernard"] license = "ASL-2.0" repository = "https://github.com/cdevents/sdk-rust" diff --git a/README.md b/README.md index 3d9a5d2..e359630 100644 --- a/README.md +++ b/README.md @@ -4,32 +4,68 @@ Rust SDK to emit [CDEvents](https://cdevents.dev). The SDK can be used to create CDEvents and send them as CloudEvents, as well as parse a received CloudEvent into a CDEvent. -## Get started - -```rust -WIP -``` - -## Create your first CDEvent - -To create a CDEvent, for instance a [*pipelineRun queued*](https://cdevents.dev/docs/core/#pipelinerun-queued) one: - -```rust -WIP -``` - -## Send your first CDEvent as CloudEvent +## Create and send your first CDEvent as CloudEvent Import the modules in your code -```rust -WIP +```toml +cdevents = "0.1.0" ``` To send a CDEvent as CloudEvent: ```rust -WIP +// from examples/pipelinerun_finished.rs +use std::error::Error; + +use cdevents_sdk::{CDEvent, Context, Subject, pipelinerun_finished, Content}; +use cloudevents::{Event, AttributesReader}; +use time::OffsetDateTime; + +fn main() -> Result<(), Box> { + let cdevent = CDEvent { + context: Context { + version: "0.3.0".to_string(), + id: "271069a8-fc18-44f1-b38f-9d70a1695819".to_string(), + r#type: "dev.cdevents.pipelinerun.finished.0.1.1".to_string(), + source: "/event/source/123".try_into()?, + timestamp: OffsetDateTime::now_utc(), + }, + subject: Subject { + id: "/dev/pipeline/run/1".to_string(), + source: Some("https://dev.pipeline.run/source".try_into()?), + r#type: "build".to_string(), + content: Content::PipelinerunFinished(pipelinerun_finished::Content{ + errors: Some("pipelineErrors".into()), + outcome: Some("success".into()), + pipeline_name: Some("testPipeline".into()), + url: Some("https://dev.pipeline.run/source".into()) + }) + }, + custom_data: None, + custom_data_content_type: None, + }; + + let cdevent_expected = cdevent.clone(); + + // shortcut for creating cloudevents with + // + // ```rust + // use cloudevents::event::EventBuilderV10; + // use cdevents_sdk::cloudevents::BuilderExt; + // + // let mut cloudevent = EventBuilderV10::new().with_cdevent(cdevent.clone())?.build()?; + // ``` + let cloudevent: Event = cdevent.try_into()?; + + // zero transport, but cloning + let cloudevent_received: Event = cloudevent.clone(); + let cdevent_extracted: CDEvent = cloudevent_received.try_into()?; + + assert_eq!(cloudevent.id(), cdevent_extracted.context.id); + assert_eq!(cdevent_expected, cdevent_extracted); + Ok(()) +} ``` See the [CloudEvents](https://github.com/cloudevents/sdk-go#send-your-first-cloudevent) docs as well. @@ -41,3 +77,5 @@ If you would like to contribute, see our [development](DEVELOPMENT.md) guide. ## References - [CDEvents](https://cdevents.dev) +- [CDEvents Primer](https://cdevents.dev/docs/primer/) +- [CDFoundation Specification](https://cdevents.dev/docs/) diff --git a/cdevents-sdk/Cargo.toml b/cdevents-sdk/Cargo.toml index 10d5878..0369ffc 100644 --- a/cdevents-sdk/Cargo.toml +++ b/cdevents-sdk/Cargo.toml @@ -8,12 +8,11 @@ repository.workspace = true rust-version.workspace = true publish = true -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] -# http = "1" # doesn't support uri-reference +cloudevents-sdk = { version = "0.7", optional = true, default-features = false } +fluent-uri = "0.1" # support uri & uri-reference, preserve the original string, but young, doesn't impl PartialEq,... +# http = "1" # doesn't support uri-reference # http-serde = "2" -fluent-uri = "0.1" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" thiserror = "1.0" @@ -22,3 +21,7 @@ time = { version = "0.3", features = ["serde-human-readable"] } [dev-dependencies] rstest = "0.18" assert-json-diff = "2.0" + +[features] +default = ["cloudevents"] +cloudevents = ["dep:cloudevents-sdk"] diff --git a/cdevents-sdk/examples/pipelinerun_finished.rs b/cdevents-sdk/examples/pipelinerun_finished.rs new file mode 100644 index 0000000..f017b57 --- /dev/null +++ b/cdevents-sdk/examples/pipelinerun_finished.rs @@ -0,0 +1,50 @@ +use std::error::Error; + +use cdevents_sdk::{CDEvent, Context, Subject, pipelinerun_finished, Content}; +use cloudevents::{Event, AttributesReader}; +use time::OffsetDateTime; + +fn main() -> Result<(), Box> { + let cdevent = CDEvent { + context: Context { + version: "0.3.0".to_string(), + id: "271069a8-fc18-44f1-b38f-9d70a1695819".to_string(), + r#type: "dev.cdevents.pipelinerun .finished.0.1.1".to_string(), + source: "/event/source/123".try_into()?, + timestamp: OffsetDateTime::now_utc(), + }, + subject: Subject { + id: "/dev/pipeline/run/1".to_string(), + source: Some("https://dev.pipeline.run/source".try_into()?), + r#type: "build".to_string(), + content: Content::PipelinerunFinished(pipelinerun_finished::Content{ + errors: Some("pipelineErrors".into()), + outcome: Some("success".into()), + pipeline_name: Some("testPipeline".into()), + url: Some("https://dev.pipeline.run/source".into()) + }) + }, + custom_data: None, + custom_data_content_type: None, + }; + + let cdevent_expected = cdevent.clone(); + + // shortcut for creating cloudevents with + // + // ```rust + // use cloudevents::event::EventBuilderV10; + // use cdevents_sdk::cloudevents::BuilderExt; + // + // let mut cloudevent = EventBuilderV10::new().with_cdevent(cdevent.clone())?.build()?; + // ``` + let cloudevent: Event = cdevent.try_into()?; + + // zero transport, but cloning + let cloudevent_received: Event = cloudevent.clone(); + let cdevent_extracted: CDEvent = cloudevent_received.try_into()?; + + assert_eq!(cloudevent.id(), cdevent_extracted.context.id); + assert_eq!(cdevent_expected, cdevent_extracted); + Ok(()) +} diff --git a/cdevents-sdk/src/cloudevents.rs b/cdevents-sdk/src/cloudevents.rs new file mode 100644 index 0000000..074084e --- /dev/null +++ b/cdevents-sdk/src/cloudevents.rs @@ -0,0 +1,106 @@ +use cloudevents::{Data, Event}; +use time::format_description::well_known::Rfc3339; + +use crate::CDEvent; + +pub trait BuilderExt: Sized { + type Error; + fn with_cdevent(self, cdevent: CDEvent) -> Result; +} + +impl BuilderExt for cloudevents::EventBuilderV10 { + type Error = cloudevents::message::Error; + + fn with_cdevent(self, cdevent: CDEvent) -> Result { + Ok( + self.id(&cdevent.context.id) + .ty(&cdevent.context.r#type) + .source(cdevent.context.source.as_str()) + .subject(&cdevent.subject.id) + .time(cdevent.context.timestamp.format(&Rfc3339).map_err(|e| Self::Error::Other{source: Box::new(e)})?) + .data("application/json", serde_json::to_value(cdevent).map_err(Self::Error::from)?) + ) + } +} + +impl TryFrom for Event { + type Error = cloudevents::message::Error; + + fn try_from(value: CDEvent) -> Result { + use ::cloudevents::{EventBuilder, EventBuilderV10}; + EventBuilderV10::new() + .with_cdevent(value)? + .build().map_err(Self::Error::from) + } +} + +impl TryFrom for CDEvent { + type Error = serde_json::Error; + + fn try_from(value: Data) -> Result { + let json = match value { + Data::Binary(v) => serde_json::from_slice(&v)?, + Data::Json(v) => v, + Data::String(s) => serde_json::from_str(&s)?, + }; + serde_json::from_value(json) //doesn't work due to the unsupported variant definition + } +} + +impl TryFrom for CDEvent { + type Error = crate::Error; + + fn try_from(value: Event) -> Result { + let mut event = value; + let (_, _, data) = event.take_data(); + data.ok_or(Self::Error::DataNotFoundInCloudEvent)? + .try_into().map_err(Self::Error::from) + } +} + +#[cfg(test)] +mod tests { + use ::cloudevents::{AttributesReader, EventBuilder, EventBuilderV10}; + use ::time::OffsetDateTime; + + use crate::*; + + use super::*; + + #[test] + fn test_true() -> Result<(), Box> { + let cdevent = CDEvent { + context: Context { + version: "0.3.0".to_string(), + id: "271069a8-fc18-44f1-b38f-9d70a1695819".to_string(), + r#type: "dev.cdevents.build.queued.0.1.1".to_string(), + source: "/event/source/123".try_into()?, + timestamp: OffsetDateTime::now_utc(), + }, + subject: Subject { + id: "subject123".to_string(), + source: Some("/event/source/123".try_into()?), + r#type: "build".to_string(), + content: Content::BuildQueued(build_queued::Content{}) + }, + custom_data: None, + custom_data_content_type: None, + }; + + + let cloudevent_via_builder = EventBuilderV10::new() + .with_cdevent(cdevent.clone())? + .build()?; + let mut cloudevent: Event = cdevent.clone().try_into()?; + assert_eq!(cloudevent_via_builder, cloudevent); + + assert_eq!(cloudevent.id(), "271069a8-fc18-44f1-b38f-9d70a1695819"); + assert_eq!(cloudevent.id(), cdevent.context.id); + + let (_, _, data) = cloudevent.take_data(); + let cdevent_extracted: CDEvent = data.ok_or(Error::DataNotFoundInCloudEvent)?.try_into()?; + assert_eq!(cloudevent.id(), cdevent_extracted.context.id); + assert_eq!(cdevent, cdevent_extracted); + Ok(()) + } +} diff --git a/cdevents-sdk/src/error.rs b/cdevents-sdk/src/error.rs index a5afdc5..5d7260b 100644 --- a/cdevents-sdk/src/error.rs +++ b/cdevents-sdk/src/error.rs @@ -2,8 +2,12 @@ use thiserror::Error; #[derive(Error, Debug)] pub enum Error { + #[error("Empty data in cloudevent")] + DataNotFoundInCloudEvent, #[error(transparent)] UriParseError( #[from] fluent_uri::ParseError), + #[error(transparent)] + SerdeJsonError( #[from] serde_json::Error), #[error("unknown error")] Unknown, } diff --git a/cdevents-sdk/src/lib.rs b/cdevents-sdk/src/lib.rs index ea76d6c..dada526 100644 --- a/cdevents-sdk/src/lib.rs +++ b/cdevents-sdk/src/lib.rs @@ -1,7 +1,11 @@ +#![doc = include_str!("../../README.md")] +//#![warn(missing_docs)] // TODO remove unwrap(), expect(...) // TODO reduce clone() mod cdevent; mod context; +#[cfg(feature = "cloudevents")] +pub mod cloudevents; mod error; mod generated; pub(crate) mod serde; diff --git a/justfile b/justfile index 91e64ee..82bdee5 100644 --- a/justfile +++ b/justfile @@ -1,3 +1,5 @@ +# TODO add a task to automatically update the README with the content of examples + default: @just --list --unsorted @@ -38,7 +40,7 @@ alias fmt := format # Format the code and sort dependencies format: cargo fmt - # cargo sort --workspace --grouped + @# cargo sort --workspace --grouped just --unstable --fmt deny: _install_cargo-deny @@ -63,8 +65,9 @@ megalinter: # Launch tests test: _install_cargo-nextest cargo nextest run - # cargo test --doc - # cargo hack nextest --each-feature -- --test-threads=1 + cargo test --doc + @# cargo hack test --each-feature + @# cargo hack nextest --each-feature -- --test-threads=1 # [cargo-hack and cargo-nextest don't compose well](https://github.com/nextest-rs/nextest/issues/1029) changelog: _install_git-cliff git-cliff -o "CHANGELOG.md" @@ -72,6 +75,9 @@ changelog: _install_git-cliff release *arguments: _install_cargo-release _install_git-cliff cargo release --workspace --execute {{ arguments }} - # git-cliff could not be used as `pre-release-hook` of cargo-release because it uses tag + @# git-cliff could not be used as `pre-release-hook` of cargo-release because it uses tag git-cliff -o "CHANGELOG.md" git add CHANGELOG.md && git commit -m "📝 update CHANGELOG" && git push + +run_examples: + cargo run --example pipelinerun_finished diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..7897a24 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "1.75.0" From ba31fb9fc32cc57fd08ed3cf639fddf6e83284f6 Mon Sep 17 00:00:00 2001 From: David Bernard Date: Sun, 21 Jan 2024 23:02:15 +0100 Subject: [PATCH 17/34] feat: enforce mutation to only create coherente cdevents (type match subject.content) - hide context - provide accessor and mutator to restrict access Signed-off-by: David Bernard --- README.md | 40 +-- cdevents-sdk/examples/pipelinerun_finished.rs | 41 +-- cdevents-sdk/src/cdevent.rs | 104 +++++- cdevents-sdk/src/cloudevents.rs | 45 +-- cdevents-sdk/src/context.rs | 14 +- cdevents-sdk/src/generated/mod.rs | 327 +++++++++++++++--- .../src/generated/testcaserun_finished.rs | 2 +- .../src/generated/testcaserun_queued.rs | 4 +- .../src/generated/testcaserun_started.rs | 4 +- .../src/generated/testsuiterun_queued.rs | 2 +- .../src/generated/testsuiterun_started.rs | 2 +- cdevents-sdk/src/lib.rs | 2 +- cdevents-sdk/src/subject.rs | 56 ++- generator/src/main.rs | 2 +- generator/templates/mod.hbs | 27 +- 15 files changed, 526 insertions(+), 146 deletions(-) diff --git a/README.md b/README.md index e359630..5dc967b 100644 --- a/README.md +++ b/README.md @@ -18,33 +18,23 @@ To send a CDEvent as CloudEvent: // from examples/pipelinerun_finished.rs use std::error::Error; -use cdevents_sdk::{CDEvent, Context, Subject, pipelinerun_finished, Content}; +use cdevents_sdk::{CDEvent, Subject, pipelinerun_finished, Content}; use cloudevents::{Event, AttributesReader}; -use time::OffsetDateTime; fn main() -> Result<(), Box> { - let cdevent = CDEvent { - context: Context { - version: "0.3.0".to_string(), - id: "271069a8-fc18-44f1-b38f-9d70a1695819".to_string(), - r#type: "dev.cdevents.pipelinerun.finished.0.1.1".to_string(), - source: "/event/source/123".try_into()?, - timestamp: OffsetDateTime::now_utc(), - }, - subject: Subject { - id: "/dev/pipeline/run/1".to_string(), - source: Some("https://dev.pipeline.run/source".try_into()?), - r#type: "build".to_string(), - content: Content::PipelinerunFinished(pipelinerun_finished::Content{ - errors: Some("pipelineErrors".into()), - outcome: Some("success".into()), - pipeline_name: Some("testPipeline".into()), - url: Some("https://dev.pipeline.run/source".into()) - }) - }, - custom_data: None, - custom_data_content_type: None, - }; + let cdevent = CDEvent::from( + Subject::from(pipelinerun_finished::Content{ + errors: Some("pipelineErrors".into()), + outcome: Some("success".into()), + pipeline_name: Some("testPipeline".into()), + url: Some("https://dev.pipeline.run/url".into()) + }) + .with_id("/dev/pipeline/run/1") + .with_source("https://dev.pipeline.run/source".try_into()?) + ) + .with_id("271069a8-fc18-44f1-b38f-9d70a1695819") + .with_source("https://dev.cdevents".try_into()?) + ; let cdevent_expected = cdevent.clone(); @@ -62,7 +52,7 @@ fn main() -> Result<(), Box> { let cloudevent_received: Event = cloudevent.clone(); let cdevent_extracted: CDEvent = cloudevent_received.try_into()?; - assert_eq!(cloudevent.id(), cdevent_extracted.context.id); + assert_eq!(cloudevent.id(), cdevent_extracted.id()); assert_eq!(cdevent_expected, cdevent_extracted); Ok(()) } diff --git a/cdevents-sdk/examples/pipelinerun_finished.rs b/cdevents-sdk/examples/pipelinerun_finished.rs index f017b57..4bfdef6 100644 --- a/cdevents-sdk/examples/pipelinerun_finished.rs +++ b/cdevents-sdk/examples/pipelinerun_finished.rs @@ -1,32 +1,22 @@ use std::error::Error; -use cdevents_sdk::{CDEvent, Context, Subject, pipelinerun_finished, Content}; +use cdevents_sdk::{CDEvent, Subject, pipelinerun_finished}; use cloudevents::{Event, AttributesReader}; -use time::OffsetDateTime; fn main() -> Result<(), Box> { - let cdevent = CDEvent { - context: Context { - version: "0.3.0".to_string(), - id: "271069a8-fc18-44f1-b38f-9d70a1695819".to_string(), - r#type: "dev.cdevents.pipelinerun .finished.0.1.1".to_string(), - source: "/event/source/123".try_into()?, - timestamp: OffsetDateTime::now_utc(), - }, - subject: Subject { - id: "/dev/pipeline/run/1".to_string(), - source: Some("https://dev.pipeline.run/source".try_into()?), - r#type: "build".to_string(), - content: Content::PipelinerunFinished(pipelinerun_finished::Content{ - errors: Some("pipelineErrors".into()), - outcome: Some("success".into()), - pipeline_name: Some("testPipeline".into()), - url: Some("https://dev.pipeline.run/source".into()) - }) - }, - custom_data: None, - custom_data_content_type: None, - }; + let cdevent = CDEvent::from( + Subject::from(pipelinerun_finished::Content{ + errors: Some("pipelineErrors".into()), + outcome: Some("success".into()), + pipeline_name: Some("testPipeline".into()), + url: Some("https://dev.pipeline.run/url".into()) + }) + .with_id("/dev/pipeline/run/1") + .with_source("https://dev.pipeline.run/source".try_into()?) + ) + .with_id("271069a8-fc18-44f1-b38f-9d70a1695819") + .with_source("https://dev.cdevents".try_into()?) + ; let cdevent_expected = cdevent.clone(); @@ -44,7 +34,8 @@ fn main() -> Result<(), Box> { let cloudevent_received: Event = cloudevent.clone(); let cdevent_extracted: CDEvent = cloudevent_received.try_into()?; - assert_eq!(cloudevent.id(), cdevent_extracted.context.id); + assert_eq!(cloudevent.id(), cdevent_extracted.id()); assert_eq!(cdevent_expected, cdevent_extracted); Ok(()) } + diff --git a/cdevents-sdk/src/cdevent.rs b/cdevents-sdk/src/cdevent.rs index 6325762..258bff3 100644 --- a/cdevents-sdk/src/cdevent.rs +++ b/cdevents-sdk/src/cdevent.rs @@ -1,4 +1,4 @@ -use crate::{Context, Subject}; +use crate::{Context, Subject, UriReference}; use serde::{ de::{self, Deserializer, MapAccess, Visitor}, Deserialize, Serialize, @@ -8,15 +8,107 @@ use std::fmt; #[derive(Debug, Clone, Serialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct CDEvent { - pub context: Context, - pub subject: Subject, + context: Context, + subject: Subject, #[serde(rename = "customData", skip_serializing_if = "Option::is_none")] - pub custom_data: Option, + custom_data: Option, #[serde( rename = "customDataContentType", skip_serializing_if = "Option::is_none" )] - pub custom_data_content_type: Option, + custom_data_content_type: Option, +} + +impl From for CDEvent { + fn from(subject: Subject) -> Self { + let context = Context { + ty: subject.ty().into(), + ..Default::default() + }; + Self { + context, + subject, + custom_data: None, + custom_data_content_type: None, + } + } +} + +impl CDEvent { + /// see + pub fn version(&self) -> &str { + self.context.version.as_str() + } + + pub fn with_version(mut self, v: T) -> Self where T: Into { + self.context.version = v.into(); + self + } + + /// see + pub fn id(&self) -> &str { + self.context.id.as_str() + } + + pub fn with_id(mut self, v: T) -> Self where T: Into { + self.context.id = v.into(); + self + } + + /// see + pub fn source(&self) -> &UriReference { + &self.context.source + } + + pub fn with_source(mut self, v: UriReference) -> Self { + self.context.source = v; + self + } + + /// see + pub fn timestamp(&self) -> &time::OffsetDateTime { + &self.context.timestamp + } + + pub fn with_timestamp(mut self, v: time::OffsetDateTime) -> Self { + self.context.timestamp = v; + self + } + + /// see + pub fn subject(&self) -> &Subject { + &self.subject + } + + /// see + /// derived from subject.content + pub fn ty(&self) -> &str { + //self.context.ty() + self.subject.ty() + } + + /// see + pub fn custom_data(&self) -> &Option { + &self.custom_data + } + + pub fn with_custom_data(mut self, custom_data: serde_json::Value) -> Self { + self.custom_data = Some(custom_data); + self + } + + /// see + pub fn custom_data_content_type(&self) -> &Option { + &self.custom_data_content_type + } + + pub fn with_custom_data_content_type( + mut self, + custom_data_content_type: String, + ) -> Self { + self.custom_data_content_type = Some(custom_data_content_type); + self + } } impl<'de> Deserialize<'de> for CDEvent { @@ -82,7 +174,7 @@ impl<'de> Deserialize<'de> for CDEvent { let subject_json = subject_json.ok_or_else(|| de::Error::missing_field("subject"))?; let subject = - Subject::from_json(&context.r#type, subject_json).map_err(de::Error::custom)?; + Subject::from_json(&context.ty, subject_json).map_err(de::Error::custom)?; Ok(CDEvent { context, diff --git a/cdevents-sdk/src/cloudevents.rs b/cdevents-sdk/src/cloudevents.rs index 074084e..f7fc72d 100644 --- a/cdevents-sdk/src/cloudevents.rs +++ b/cdevents-sdk/src/cloudevents.rs @@ -13,11 +13,11 @@ impl BuilderExt for cloudevents::EventBuilderV10 { fn with_cdevent(self, cdevent: CDEvent) -> Result { Ok( - self.id(&cdevent.context.id) - .ty(&cdevent.context.r#type) - .source(cdevent.context.source.as_str()) - .subject(&cdevent.subject.id) - .time(cdevent.context.timestamp.format(&Rfc3339).map_err(|e| Self::Error::Other{source: Box::new(e)})?) + self.id(cdevent.id()) + .ty(cdevent.ty()) + .source(cdevent.source().as_str()) + .subject(cdevent.subject().id()) + .time(cdevent.timestamp().format(&Rfc3339).map_err(|e| Self::Error::Other{source: Box::new(e)})?) .data("application/json", serde_json::to_value(cdevent).map_err(Self::Error::from)?) ) } @@ -61,32 +61,19 @@ impl TryFrom for CDEvent { #[cfg(test)] mod tests { use ::cloudevents::{AttributesReader, EventBuilder, EventBuilderV10}; - use ::time::OffsetDateTime; - use crate::*; - use super::*; #[test] - fn test_true() -> Result<(), Box> { - let cdevent = CDEvent { - context: Context { - version: "0.3.0".to_string(), - id: "271069a8-fc18-44f1-b38f-9d70a1695819".to_string(), - r#type: "dev.cdevents.build.queued.0.1.1".to_string(), - source: "/event/source/123".try_into()?, - timestamp: OffsetDateTime::now_utc(), - }, - subject: Subject { - id: "subject123".to_string(), - source: Some("/event/source/123".try_into()?), - r#type: "build".to_string(), - content: Content::BuildQueued(build_queued::Content{}) - }, - custom_data: None, - custom_data_content_type: None, - }; - + fn test_into_cloudevent() -> Result<(), Box> { + let cdevent = CDEvent::from( + Subject::from(build_queued::Content{}) + .with_id("subject123") + .with_source("/event/source/123".try_into()?) + ) + .with_id("271069a8-fc18-44f1-b38f-9d70a1695819") + .with_source("https://dev.cdevents".try_into()?) + ; let cloudevent_via_builder = EventBuilderV10::new() .with_cdevent(cdevent.clone())? @@ -95,11 +82,11 @@ mod tests { assert_eq!(cloudevent_via_builder, cloudevent); assert_eq!(cloudevent.id(), "271069a8-fc18-44f1-b38f-9d70a1695819"); - assert_eq!(cloudevent.id(), cdevent.context.id); + assert_eq!(cloudevent.id(), cdevent.id()); let (_, _, data) = cloudevent.take_data(); let cdevent_extracted: CDEvent = data.ok_or(Error::DataNotFoundInCloudEvent)?.try_into()?; - assert_eq!(cloudevent.id(), cdevent_extracted.context.id); + assert_eq!(cloudevent.id(), cdevent_extracted.id()); assert_eq!(cdevent, cdevent_extracted); Ok(()) } diff --git a/cdevents-sdk/src/context.rs b/cdevents-sdk/src/context.rs index 5d7658c..cd891f4 100644 --- a/cdevents-sdk/src/context.rs +++ b/cdevents-sdk/src/context.rs @@ -4,14 +4,14 @@ use crate::UriReference; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] -pub struct Context { - pub version: String, - pub id: String, - pub source: UriReference, +pub(crate) struct Context { + pub(crate) version: String, + pub(crate) id: String, + pub(crate) source: UriReference, #[serde(rename = "type")] - pub r#type: String, + pub(crate) ty: String, #[serde(with = "crate::serde::datetime")] - pub timestamp: time::OffsetDateTime, + pub(crate) timestamp: time::OffsetDateTime, } impl Default for Context { @@ -20,7 +20,7 @@ impl Default for Context { version: "0.3.0".into(), id: "00000000-0000-0000-0000-000000000000".into(), source: UriReference::default(), - r#type: "dev.cdevents.undef.undef.0.0.0".into(), + ty: "dev.cdevents.undef.undef.0.0.0".into(), timestamp: time::OffsetDateTime::now_utc(), } } diff --git a/cdevents-sdk/src/generated/mod.rs b/cdevents-sdk/src/generated/mod.rs index 3facfa3..0cd19d9 100644 --- a/cdevents-sdk/src/generated/mod.rs +++ b/cdevents-sdk/src/generated/mod.rs @@ -134,159 +134,159 @@ impl Content { match ty { ARTIFACT_PACKAGED => { let variant: artifact_packaged::Content = serde_json::from_value(json)?; - Ok(Self::ArtifactPackaged(variant)) + Ok(variant.into()) }, ARTIFACT_PUBLISHED => { let variant: artifact_published::Content = serde_json::from_value(json)?; - Ok(Self::ArtifactPublished(variant)) + Ok(variant.into()) }, ARTIFACT_SIGNED => { let variant: artifact_signed::Content = serde_json::from_value(json)?; - Ok(Self::ArtifactSigned(variant)) + Ok(variant.into()) }, BRANCH_CREATED => { let variant: branch_created::Content = serde_json::from_value(json)?; - Ok(Self::BranchCreated(variant)) + Ok(variant.into()) }, BRANCH_DELETED => { let variant: branch_deleted::Content = serde_json::from_value(json)?; - Ok(Self::BranchDeleted(variant)) + Ok(variant.into()) }, BUILD_FINISHED => { let variant: build_finished::Content = serde_json::from_value(json)?; - Ok(Self::BuildFinished(variant)) + Ok(variant.into()) }, BUILD_QUEUED => { let variant: build_queued::Content = serde_json::from_value(json)?; - Ok(Self::BuildQueued(variant)) + Ok(variant.into()) }, BUILD_STARTED => { let variant: build_started::Content = serde_json::from_value(json)?; - Ok(Self::BuildStarted(variant)) + Ok(variant.into()) }, CHANGE_ABANDONED => { let variant: change_abandoned::Content = serde_json::from_value(json)?; - Ok(Self::ChangeAbandoned(variant)) + Ok(variant.into()) }, CHANGE_CREATED => { let variant: change_created::Content = serde_json::from_value(json)?; - Ok(Self::ChangeCreated(variant)) + Ok(variant.into()) }, CHANGE_MERGED => { let variant: change_merged::Content = serde_json::from_value(json)?; - Ok(Self::ChangeMerged(variant)) + Ok(variant.into()) }, CHANGE_REVIEWED => { let variant: change_reviewed::Content = serde_json::from_value(json)?; - Ok(Self::ChangeReviewed(variant)) + Ok(variant.into()) }, CHANGE_UPDATED => { let variant: change_updated::Content = serde_json::from_value(json)?; - Ok(Self::ChangeUpdated(variant)) + Ok(variant.into()) }, ENVIRONMENT_CREATED => { let variant: environment_created::Content = serde_json::from_value(json)?; - Ok(Self::EnvironmentCreated(variant)) + Ok(variant.into()) }, ENVIRONMENT_DELETED => { let variant: environment_deleted::Content = serde_json::from_value(json)?; - Ok(Self::EnvironmentDeleted(variant)) + Ok(variant.into()) }, ENVIRONMENT_MODIFIED => { let variant: environment_modified::Content = serde_json::from_value(json)?; - Ok(Self::EnvironmentModified(variant)) + Ok(variant.into()) }, INCIDENT_DETECTED => { let variant: incident_detected::Content = serde_json::from_value(json)?; - Ok(Self::IncidentDetected(variant)) + Ok(variant.into()) }, INCIDENT_REPORTED => { let variant: incident_reported::Content = serde_json::from_value(json)?; - Ok(Self::IncidentReported(variant)) + Ok(variant.into()) }, INCIDENT_RESOLVED => { let variant: incident_resolved::Content = serde_json::from_value(json)?; - Ok(Self::IncidentResolved(variant)) + Ok(variant.into()) }, PIPELINERUN_FINISHED => { let variant: pipelinerun_finished::Content = serde_json::from_value(json)?; - Ok(Self::PipelinerunFinished(variant)) + Ok(variant.into()) }, PIPELINERUN_QUEUED => { let variant: pipelinerun_queued::Content = serde_json::from_value(json)?; - Ok(Self::PipelinerunQueued(variant)) + Ok(variant.into()) }, PIPELINERUN_STARTED => { let variant: pipelinerun_started::Content = serde_json::from_value(json)?; - Ok(Self::PipelinerunStarted(variant)) + Ok(variant.into()) }, REPOSITORY_CREATED => { let variant: repository_created::Content = serde_json::from_value(json)?; - Ok(Self::RepositoryCreated(variant)) + Ok(variant.into()) }, REPOSITORY_DELETED => { let variant: repository_deleted::Content = serde_json::from_value(json)?; - Ok(Self::RepositoryDeleted(variant)) + Ok(variant.into()) }, REPOSITORY_MODIFIED => { let variant: repository_modified::Content = serde_json::from_value(json)?; - Ok(Self::RepositoryModified(variant)) + Ok(variant.into()) }, SERVICE_DEPLOYED => { let variant: service_deployed::Content = serde_json::from_value(json)?; - Ok(Self::ServiceDeployed(variant)) + Ok(variant.into()) }, SERVICE_PUBLISHED => { let variant: service_published::Content = serde_json::from_value(json)?; - Ok(Self::ServicePublished(variant)) + Ok(variant.into()) }, SERVICE_REMOVED => { let variant: service_removed::Content = serde_json::from_value(json)?; - Ok(Self::ServiceRemoved(variant)) + Ok(variant.into()) }, SERVICE_ROLLEDBACK => { let variant: service_rolledback::Content = serde_json::from_value(json)?; - Ok(Self::ServiceRolledback(variant)) + Ok(variant.into()) }, SERVICE_UPGRADED => { let variant: service_upgraded::Content = serde_json::from_value(json)?; - Ok(Self::ServiceUpgraded(variant)) + Ok(variant.into()) }, TASKRUN_FINISHED => { let variant: taskrun_finished::Content = serde_json::from_value(json)?; - Ok(Self::TaskrunFinished(variant)) + Ok(variant.into()) }, TASKRUN_STARTED => { let variant: taskrun_started::Content = serde_json::from_value(json)?; - Ok(Self::TaskrunStarted(variant)) + Ok(variant.into()) }, TESTCASERUN_FINISHED => { let variant: testcaserun_finished::Content = serde_json::from_value(json)?; - Ok(Self::TestcaserunFinished(variant)) + Ok(variant.into()) }, TESTCASERUN_QUEUED => { let variant: testcaserun_queued::Content = serde_json::from_value(json)?; - Ok(Self::TestcaserunQueued(variant)) + Ok(variant.into()) }, TESTCASERUN_STARTED => { let variant: testcaserun_started::Content = serde_json::from_value(json)?; - Ok(Self::TestcaserunStarted(variant)) + Ok(variant.into()) }, TESTOUTPUT_PUBLISHED => { let variant: testoutput_published::Content = serde_json::from_value(json)?; - Ok(Self::TestoutputPublished(variant)) + Ok(variant.into()) }, TESTSUITERUN_FINISHED => { let variant: testsuiterun_finished::Content = serde_json::from_value(json)?; - Ok(Self::TestsuiterunFinished(variant)) + Ok(variant.into()) }, TESTSUITERUN_QUEUED => { let variant: testsuiterun_queued::Content = serde_json::from_value(json)?; - Ok(Self::TestsuiterunQueued(variant)) + Ok(variant.into()) }, TESTSUITERUN_STARTED => { let variant: testsuiterun_started::Content = serde_json::from_value(json)?; - Ok(Self::TestsuiterunStarted(variant)) + Ok(variant.into()) }, variant => Err(serde_json::Error::custom(format_args!( "unknown variant `{}`, expected 'dev.cdevents.{{subject}}.{{predicate}}.{{version}}'", @@ -294,4 +294,253 @@ impl Content { ))), } } + + pub fn ty(&self) -> &'static str { + match self { + Self::ArtifactPackaged(_) => ARTIFACT_PACKAGED, + Self::ArtifactPublished(_) => ARTIFACT_PUBLISHED, + Self::ArtifactSigned(_) => ARTIFACT_SIGNED, + Self::BranchCreated(_) => BRANCH_CREATED, + Self::BranchDeleted(_) => BRANCH_DELETED, + Self::BuildFinished(_) => BUILD_FINISHED, + Self::BuildQueued(_) => BUILD_QUEUED, + Self::BuildStarted(_) => BUILD_STARTED, + Self::ChangeAbandoned(_) => CHANGE_ABANDONED, + Self::ChangeCreated(_) => CHANGE_CREATED, + Self::ChangeMerged(_) => CHANGE_MERGED, + Self::ChangeReviewed(_) => CHANGE_REVIEWED, + Self::ChangeUpdated(_) => CHANGE_UPDATED, + Self::EnvironmentCreated(_) => ENVIRONMENT_CREATED, + Self::EnvironmentDeleted(_) => ENVIRONMENT_DELETED, + Self::EnvironmentModified(_) => ENVIRONMENT_MODIFIED, + Self::IncidentDetected(_) => INCIDENT_DETECTED, + Self::IncidentReported(_) => INCIDENT_REPORTED, + Self::IncidentResolved(_) => INCIDENT_RESOLVED, + Self::PipelinerunFinished(_) => PIPELINERUN_FINISHED, + Self::PipelinerunQueued(_) => PIPELINERUN_QUEUED, + Self::PipelinerunStarted(_) => PIPELINERUN_STARTED, + Self::RepositoryCreated(_) => REPOSITORY_CREATED, + Self::RepositoryDeleted(_) => REPOSITORY_DELETED, + Self::RepositoryModified(_) => REPOSITORY_MODIFIED, + Self::ServiceDeployed(_) => SERVICE_DEPLOYED, + Self::ServicePublished(_) => SERVICE_PUBLISHED, + Self::ServiceRemoved(_) => SERVICE_REMOVED, + Self::ServiceRolledback(_) => SERVICE_ROLLEDBACK, + Self::ServiceUpgraded(_) => SERVICE_UPGRADED, + Self::TaskrunFinished(_) => TASKRUN_FINISHED, + Self::TaskrunStarted(_) => TASKRUN_STARTED, + Self::TestcaserunFinished(_) => TESTCASERUN_FINISHED, + Self::TestcaserunQueued(_) => TESTCASERUN_QUEUED, + Self::TestcaserunStarted(_) => TESTCASERUN_STARTED, + Self::TestoutputPublished(_) => TESTOUTPUT_PUBLISHED, + Self::TestsuiterunFinished(_) => TESTSUITERUN_FINISHED, + Self::TestsuiterunQueued(_) => TESTSUITERUN_QUEUED, + Self::TestsuiterunStarted(_) => TESTSUITERUN_STARTED, + } + } + + pub fn subject_predicate(&self) -> (&'static str, &'static str){ + let mut split = self.ty().split('.'); + ( + split.nth(2).expect("fargment 2 of ty should always exists"), + split.nth(3).expect("fargment 3 of ty should always exists") + ) + } + +} + +impl From for Content { + fn from(value: artifact_packaged::Content) -> Self { + Self::ArtifactPackaged(value) + } +} +impl From for Content { + fn from(value: artifact_published::Content) -> Self { + Self::ArtifactPublished(value) + } +} +impl From for Content { + fn from(value: artifact_signed::Content) -> Self { + Self::ArtifactSigned(value) + } +} +impl From for Content { + fn from(value: branch_created::Content) -> Self { + Self::BranchCreated(value) + } +} +impl From for Content { + fn from(value: branch_deleted::Content) -> Self { + Self::BranchDeleted(value) + } +} +impl From for Content { + fn from(value: build_finished::Content) -> Self { + Self::BuildFinished(value) + } +} +impl From for Content { + fn from(value: build_queued::Content) -> Self { + Self::BuildQueued(value) + } +} +impl From for Content { + fn from(value: build_started::Content) -> Self { + Self::BuildStarted(value) + } +} +impl From for Content { + fn from(value: change_abandoned::Content) -> Self { + Self::ChangeAbandoned(value) + } +} +impl From for Content { + fn from(value: change_created::Content) -> Self { + Self::ChangeCreated(value) + } +} +impl From for Content { + fn from(value: change_merged::Content) -> Self { + Self::ChangeMerged(value) + } +} +impl From for Content { + fn from(value: change_reviewed::Content) -> Self { + Self::ChangeReviewed(value) + } +} +impl From for Content { + fn from(value: change_updated::Content) -> Self { + Self::ChangeUpdated(value) + } +} +impl From for Content { + fn from(value: environment_created::Content) -> Self { + Self::EnvironmentCreated(value) + } +} +impl From for Content { + fn from(value: environment_deleted::Content) -> Self { + Self::EnvironmentDeleted(value) + } +} +impl From for Content { + fn from(value: environment_modified::Content) -> Self { + Self::EnvironmentModified(value) + } +} +impl From for Content { + fn from(value: incident_detected::Content) -> Self { + Self::IncidentDetected(value) + } +} +impl From for Content { + fn from(value: incident_reported::Content) -> Self { + Self::IncidentReported(value) + } +} +impl From for Content { + fn from(value: incident_resolved::Content) -> Self { + Self::IncidentResolved(value) + } +} +impl From for Content { + fn from(value: pipelinerun_finished::Content) -> Self { + Self::PipelinerunFinished(value) + } +} +impl From for Content { + fn from(value: pipelinerun_queued::Content) -> Self { + Self::PipelinerunQueued(value) + } +} +impl From for Content { + fn from(value: pipelinerun_started::Content) -> Self { + Self::PipelinerunStarted(value) + } +} +impl From for Content { + fn from(value: repository_created::Content) -> Self { + Self::RepositoryCreated(value) + } +} +impl From for Content { + fn from(value: repository_deleted::Content) -> Self { + Self::RepositoryDeleted(value) + } +} +impl From for Content { + fn from(value: repository_modified::Content) -> Self { + Self::RepositoryModified(value) + } +} +impl From for Content { + fn from(value: service_deployed::Content) -> Self { + Self::ServiceDeployed(value) + } +} +impl From for Content { + fn from(value: service_published::Content) -> Self { + Self::ServicePublished(value) + } +} +impl From for Content { + fn from(value: service_removed::Content) -> Self { + Self::ServiceRemoved(value) + } +} +impl From for Content { + fn from(value: service_rolledback::Content) -> Self { + Self::ServiceRolledback(value) + } +} +impl From for Content { + fn from(value: service_upgraded::Content) -> Self { + Self::ServiceUpgraded(value) + } +} +impl From for Content { + fn from(value: taskrun_finished::Content) -> Self { + Self::TaskrunFinished(value) + } +} +impl From for Content { + fn from(value: taskrun_started::Content) -> Self { + Self::TaskrunStarted(value) + } +} +impl From for Content { + fn from(value: testcaserun_finished::Content) -> Self { + Self::TestcaserunFinished(value) + } +} +impl From for Content { + fn from(value: testcaserun_queued::Content) -> Self { + Self::TestcaserunQueued(value) + } +} +impl From for Content { + fn from(value: testcaserun_started::Content) -> Self { + Self::TestcaserunStarted(value) + } +} +impl From for Content { + fn from(value: testoutput_published::Content) -> Self { + Self::TestoutputPublished(value) + } +} +impl From for Content { + fn from(value: testsuiterun_finished::Content) -> Self { + Self::TestsuiterunFinished(value) + } +} +impl From for Content { + fn from(value: testsuiterun_queued::Content) -> Self { + Self::TestsuiterunQueued(value) + } +} +impl From for Content { + fn from(value: testsuiterun_started::Content) -> Self { + Self::TestsuiterunStarted(value) + } } diff --git a/cdevents-sdk/src/generated/testcaserun_finished.rs b/cdevents-sdk/src/generated/testcaserun_finished.rs index 68bfcc2..018e348 100644 --- a/cdevents-sdk/src/generated/testcaserun_finished.rs +++ b/cdevents-sdk/src/generated/testcaserun_finished.rs @@ -37,7 +37,7 @@ pub struct TestCase { #[serde(rename = "name", default, skip_serializing_if = "Option::is_none",)] pub name: Option, #[serde(rename = "type", default, skip_serializing_if = "Option::is_none",)] - pub r#type: Option, + pub ty: Option, #[serde(rename = "uri", default, skip_serializing_if = "Option::is_none",)] pub uri: Option, #[serde(rename = "version", default, skip_serializing_if = "Option::is_none",)] diff --git a/cdevents-sdk/src/generated/testcaserun_queued.rs b/cdevents-sdk/src/generated/testcaserun_queued.rs index eab0fd4..72c1cf2 100644 --- a/cdevents-sdk/src/generated/testcaserun_queued.rs +++ b/cdevents-sdk/src/generated/testcaserun_queued.rs @@ -20,7 +20,7 @@ pub struct Content { #[serde(deny_unknown_fields)] pub struct Trigger { #[serde(rename = "type", default, skip_serializing_if = "Option::is_none",)] - pub r#type: Option, + pub ty: Option, #[serde(rename = "uri", default, skip_serializing_if = "Option::is_none",)] pub uri: Option, } @@ -42,7 +42,7 @@ pub struct TestCase { #[serde(rename = "name", default, skip_serializing_if = "Option::is_none",)] pub name: Option, #[serde(rename = "type", default, skip_serializing_if = "Option::is_none",)] - pub r#type: Option, + pub ty: Option, #[serde(rename = "uri", default, skip_serializing_if = "Option::is_none",)] pub uri: Option, #[serde(rename = "version", default, skip_serializing_if = "Option::is_none",)] diff --git a/cdevents-sdk/src/generated/testcaserun_started.rs b/cdevents-sdk/src/generated/testcaserun_started.rs index eab0fd4..72c1cf2 100644 --- a/cdevents-sdk/src/generated/testcaserun_started.rs +++ b/cdevents-sdk/src/generated/testcaserun_started.rs @@ -20,7 +20,7 @@ pub struct Content { #[serde(deny_unknown_fields)] pub struct Trigger { #[serde(rename = "type", default, skip_serializing_if = "Option::is_none",)] - pub r#type: Option, + pub ty: Option, #[serde(rename = "uri", default, skip_serializing_if = "Option::is_none",)] pub uri: Option, } @@ -42,7 +42,7 @@ pub struct TestCase { #[serde(rename = "name", default, skip_serializing_if = "Option::is_none",)] pub name: Option, #[serde(rename = "type", default, skip_serializing_if = "Option::is_none",)] - pub r#type: Option, + pub ty: Option, #[serde(rename = "uri", default, skip_serializing_if = "Option::is_none",)] pub uri: Option, #[serde(rename = "version", default, skip_serializing_if = "Option::is_none",)] diff --git a/cdevents-sdk/src/generated/testsuiterun_queued.rs b/cdevents-sdk/src/generated/testsuiterun_queued.rs index 15bb6bc..db1a1f7 100644 --- a/cdevents-sdk/src/generated/testsuiterun_queued.rs +++ b/cdevents-sdk/src/generated/testsuiterun_queued.rs @@ -18,7 +18,7 @@ pub struct Content { #[serde(deny_unknown_fields)] pub struct Trigger { #[serde(rename = "type", default, skip_serializing_if = "Option::is_none",)] - pub r#type: Option, + pub ty: Option, #[serde(rename = "uri", default, skip_serializing_if = "Option::is_none",)] pub uri: Option, } diff --git a/cdevents-sdk/src/generated/testsuiterun_started.rs b/cdevents-sdk/src/generated/testsuiterun_started.rs index dea3cb7..f2c3ff4 100644 --- a/cdevents-sdk/src/generated/testsuiterun_started.rs +++ b/cdevents-sdk/src/generated/testsuiterun_started.rs @@ -18,7 +18,7 @@ pub struct Content { #[serde(deny_unknown_fields)] pub struct Trigger { #[serde(rename = "type", default, skip_serializing_if = "Option::is_none",)] - pub r#type: Option, + pub ty: Option, #[serde(rename = "uri", default, skip_serializing_if = "Option::is_none",)] pub uri: Option, } diff --git a/cdevents-sdk/src/lib.rs b/cdevents-sdk/src/lib.rs index dada526..819f4f8 100644 --- a/cdevents-sdk/src/lib.rs +++ b/cdevents-sdk/src/lib.rs @@ -14,7 +14,7 @@ mod uri; mod uri_reference; pub use cdevent::*; -pub use context::*; +pub(crate) use context::*; pub use error::*; pub use generated::*; pub use subject::*; diff --git a/cdevents-sdk/src/subject.rs b/cdevents-sdk/src/subject.rs index e91bc25..887b156 100644 --- a/cdevents-sdk/src/subject.rs +++ b/cdevents-sdk/src/subject.rs @@ -4,31 +4,64 @@ use serde::{Deserialize, Serialize}; use crate::{Content, UriReference}; +/// see #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct Subject { #[serde(rename = "content")] - pub content: Content, + content: Content, #[serde(rename = "id")] - pub id: String, + id: String, #[serde( rename = "source", default, skip_serializing_if = "Option::is_none", )] - pub source: Option, + source: Option, #[serde(rename = "type")] - pub r#type: String, + ty: String, } impl Subject { + /// see + pub fn id(&self) -> &str { + &self.id + } + + pub fn with_id(mut self, id: T) -> Self + where T: Into { + self.id = id.into(); + self + } + + /// see + pub fn source(&self) -> &Option { + &self.source + } + + pub fn with_source(mut self, source: UriReference) -> Self { + self.source = Some(source); + self + } + + /// see + /// derived from content + pub fn ty(&self) -> &str { + &self.ty + } + + /// see + pub fn content(&self) -> &Content { + &self.content + } + pub fn from_json(ty: &str, json: serde_json::Value) -> Result { Ok(Subject { id: json["id"] .as_str() .ok_or_else(|| serde::de::Error::missing_field("id"))? .to_string(), - r#type: json["type"] + ty: json["type"] .as_str() .ok_or_else(|| serde::de::Error::missing_field("type"))? .to_string(), @@ -42,3 +75,16 @@ impl Subject { }) } } + +impl From for Subject where T: Into{ + fn from(content: T) -> Self { + let content = content.into(); + let ty = content.ty().to_owned(); + Self { + content, + id: String::new(), + source: None, + ty, + } + } +} diff --git a/generator/src/main.rs b/generator/src/main.rs index 22f5e10..40ffdc1 100644 --- a/generator/src/main.rs +++ b/generator/src/main.rs @@ -189,7 +189,7 @@ fn collect_structs( .map(|field| { let serde_name = field.0.to_string(); let rust_name = if serde_name == "type" { - "r#type".to_string() + "ty".to_string() } else { serde_name.to_snake_case() }; diff --git a/generator/templates/mod.hbs b/generator/templates/mod.hbs index 1384284..5d3ef83 100644 --- a/generator/templates/mod.hbs +++ b/generator/templates/mod.hbs @@ -27,7 +27,7 @@ impl Content { {{#each variants }} {{to_screaming_snake_case this.rust_module}} => { let variant: {{this.rust_module}}::Content = serde_json::from_value(json)?; - Ok(Self::{{to_class_case this.rust_module}}(variant)) + Ok(variant.into()) }, {{/each}} variant => Err(serde_json::Error::custom(format_args!( @@ -36,4 +36,29 @@ impl Content { ))), } } + + pub fn ty(&self) -> &'static str { + match self { + {{#each variants }} + Self::{{to_class_case this.rust_module}}(_) => {{to_screaming_snake_case this.rust_module}}, + {{/each}} + } + } + + pub fn subject_predicate(&self) -> (&'static str, &'static str){ + let mut split = self.ty().split('.'); + ( + split.nth(2).expect("fargment 2 of ty should always exists"), + split.nth(3).expect("fargment 3 of ty should always exists") + ) + } + +} + +{{#each variants }} +impl From<{{this.rust_module}}::Content> for Content { + fn from(value: {{this.rust_module}}::Content) -> Self { + Self::{{to_class_case this.rust_module}}(value) + } } +{{/each}} From 7efb1c495a27c7a55704fb175b4d7a2b83d24f40 Mon Sep 17 00:00:00 2001 From: David Bernard Date: Tue, 23 Jan 2024 21:21:26 +0100 Subject: [PATCH 18/34] build: migrate to `mise` (formaly `rtx`) Signed-off-by: David Bernard --- .mise.toml | 15 +++++++++++++++ .rtx.toml | 8 -------- 2 files changed, 15 insertions(+), 8 deletions(-) create mode 100644 .mise.toml delete mode 100644 .rtx.toml diff --git a/.mise.toml b/.mise.toml new file mode 100644 index 0000000..e71067d --- /dev/null +++ b/.mise.toml @@ -0,0 +1,15 @@ +[env] +# RUSTC_WRAPPER = "sccache" +RUST_WITHOUT = "rust-docs" +# ASDF_RUST_PROFILE = "minimal" +MISE_CARGO_BINSTALL = "true" + +[tools] +rust = "1.75" +make = "latest" +# # experimental +# "cargo:cargo-binstall" = "latest" +# "cargo:cargo-nextest" = "latest" +# "cargo:cargo-hack" = "latest" +# "cargo:cargo-deny" = "latest" +# "cargo:git-cliff" = "latest" diff --git a/.rtx.toml b/.rtx.toml deleted file mode 100644 index 4b21953..0000000 --- a/.rtx.toml +++ /dev/null @@ -1,8 +0,0 @@ -[env] -# RUSTC_WRAPPER = "sccache" -RUST_WITHOUT = "rust-docs" -# ASDF_RUST_PROFILE = "minimal" - -[tools] -rust = '1.75' -just = '1' From 449948db8c74ade9f0ca412917e97d8f954fc0f9 Mon Sep 17 00:00:00 2001 From: David Bernard Date: Tue, 23 Jan 2024 21:23:07 +0100 Subject: [PATCH 19/34] revert: remove CI (wrong PR) Signed-off-by: David Bernard --- .github/workflows/ci.yml | 39 ------- .github/workflows/mega-linter.yml | 173 ------------------------------ justfile | 83 -------------- 3 files changed, 295 deletions(-) delete mode 100644 .github/workflows/ci.yml delete mode 100644 .github/workflows/mega-linter.yml delete mode 100644 justfile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index ae254b4..0000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,39 +0,0 @@ ---- -name: ci - -on: - push: - workflow_dispatch: - -permissions: - contents: read - -jobs: - tests: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest] - env: - CARGO_TERM_COLOR: always - RUST_BACKTRACE: full - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - submodules: "true" - - uses: jdx/rtx-action@v1 - - name: Cache cargo registry - uses: actions/cache@v3 - continue-on-error: false - with: - path: | - ~/.cargo/registry - ~/.cargo/git - key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - restore-keys: | - ${{ runner.os }}-cargo- - - run: just check - - run: just lint_rust # megalinter is running via an other workflow - - run: just test diff --git a/.github/workflows/mega-linter.yml b/.github/workflows/mega-linter.yml deleted file mode 100644 index 190c18b..0000000 --- a/.github/workflows/mega-linter.yml +++ /dev/null @@ -1,173 +0,0 @@ -# MegaLinter GitHub Action configuration file -# More info at https://megalinter.io ---- -name: MegaLinter - -# Trigger mega-linter at every push. Action will also be visible from Pull -# Requests to main -on: - # Comment this line to trigger action only on pull-requests - # (not recommended if you don't pay for GH Actions) - push: - - # pull_request: - # branches: - # - main - # - master - -# Comment env block if you do not want to apply fixes -env: - # Apply linter fixes configuration - # - # When active, APPLY_FIXES must also be defined as environment variable - # (in github/workflows/mega-linter.yml or other CI tool) - APPLY_FIXES: all - - # Decide which event triggers application of fixes in a commit or a PR - # (pull_request, push, all) - APPLY_FIXES_EVENT: pull_request - - # If APPLY_FIXES is used, defines if the fixes are directly committed (commit) - # or posted in a PR (pull_request) - APPLY_FIXES_MODE: commit - -concurrency: - group: ${{ github.ref }}-${{ github.workflow }} - cancel-in-progress: true - -# Give the default GITHUB_TOKEN write permission to commit and push, comment -# issues & post new PR; remove the ones you do not need -permissions: - contents: write - issues: write - pull-requests: write - -jobs: - megalinter: - name: MegaLinter - runs-on: ubuntu-latest - - steps: - # Git Checkout - - name: Checkout Code - uses: actions/checkout@v4 - with: - token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }} - - # If you use VALIDATE_ALL_CODEBASE = true, you can remove this line to - # improve performance - fetch-depth: 0 - - # MegaLinter - - name: MegaLinter - - # You can override MegaLinter flavor used to have faster performances - # More info at https://megalinter.io/flavors/ - uses: oxsecurity/megalinter@v7 - - id: ml - - # All available variables are described in documentation - # https://megalinter.io/configuration/ - env: - # Validates all source when push on main, else just the git diff with - # main. Override with true if you always want to lint all sources - # - # To validate the entire codebase, set to: - # VALIDATE_ALL_CODEBASE: true - # - # To validate only diff with main, set to: - # VALIDATE_ALL_CODEBASE: >- - # ${{ - # github.event_name == 'push' && - # contains(fromJSON('["refs/heads/main", "refs/heads/master"]'), github.ref) - # }} - VALIDATE_ALL_CODEBASE: >- - ${{ - github.event_name == 'push' && - contains(fromJSON('["refs/heads/main", "refs/heads/master"]'), github.ref) - }} - - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - # ADD YOUR CUSTOM ENV VARIABLES HERE OR DEFINE THEM IN A FILE - # .mega-linter.yml AT THE ROOT OF YOUR REPOSITORY - - # Uncomment to disable copy-paste and spell checks - # DISABLE: COPYPASTE,SPELL - - # Upload MegaLinter artifacts - - name: Archive production artifacts - uses: actions/upload-artifact@v4 - if: success() || failure() - with: - name: MegaLinter reports - path: | - megalinter-reports - mega-linter.log - - # Set APPLY_FIXES_IF var for use in future steps - - name: Set APPLY_FIXES_IF var - run: | - printf 'APPLY_FIXES_IF=%s\n' "${{ - steps.ml.outputs.has_updated_sources == 1 && - ( - env.APPLY_FIXES_EVENT == 'all' || - env.APPLY_FIXES_EVENT == github.event_name - ) && - ( - github.event_name == 'push' || - github.event.pull_request.head.repo.full_name == github.repository - ) - }}" >> "${GITHUB_ENV}" - - # Set APPLY_FIXES_IF_* vars for use in future steps - - name: Set APPLY_FIXES_IF_* vars - run: | - printf 'APPLY_FIXES_IF_PR=%s\n' "${{ - env.APPLY_FIXES_IF == 'true' && - env.APPLY_FIXES_MODE == 'pull_request' - }}" >> "${GITHUB_ENV}" - printf 'APPLY_FIXES_IF_COMMIT=%s\n' "${{ - env.APPLY_FIXES_IF == 'true' && - env.APPLY_FIXES_MODE == 'commit' && - (!contains(fromJSON('["refs/heads/main", "refs/heads/master"]'), github.ref)) - }}" >> "${GITHUB_ENV}" - - # Create pull request if applicable - # (for now works only on PR from same repository, not from forks) - - name: Create Pull Request with applied fixes - uses: peter-evans/create-pull-request@v5 - id: cpr - if: env.APPLY_FIXES_IF_PR == 'true' - with: - token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }} - commit-message: "[MegaLinter] Apply linters automatic fixes" - title: "[MegaLinter] Apply linters automatic fixes" - labels: bot - - - name: Create PR output - if: env.APPLY_FIXES_IF_PR == 'true' - run: | - echo "PR Number - ${{ steps.cpr.outputs.pull-request-number }}" - echo "PR URL - ${{ steps.cpr.outputs.pull-request-url }}" - - # Push new commit if applicable - # (for now works only on PR from same repository, not from forks) - - name: Prepare commit - if: env.APPLY_FIXES_IF_COMMIT == 'true' - run: sudo chown -Rc $UID .git/ - - - name: Commit and push applied linter fixes - uses: stefanzweifel/git-auto-commit-action@v5 - if: env.APPLY_FIXES_IF_COMMIT == 'true' - with: - branch: >- - ${{ - github.event.pull_request.head.ref || - github.head_ref || - github.ref - }} - commit_message: "[MegaLinter] Apply linters fixes" - commit_user_name: megalinter-bot - commit_user_email: nicolas.vuillamy@ox.security diff --git a/justfile b/justfile deleted file mode 100644 index 82bdee5..0000000 --- a/justfile +++ /dev/null @@ -1,83 +0,0 @@ -# TODO add a task to automatically update the README with the content of examples - -default: - @just --list --unsorted - -_install_cargo-binstall: - # cargo install cargo-binstall - cargo binstall -V || curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash - -_install_cargo-nextest: _install_cargo-binstall - cargo binstall cargo-nextest -y - -_install_cargo-insta: _install_cargo-binstall - cargo binstall cargo-insta -y - -_install_cargo-release: _install_cargo-binstall - cargo binstall cargo-release -y - -_install_cargo-hack: _install_cargo-binstall - cargo binstall cargo-hack -y - -_install_cargo-deny: _install_cargo-binstall - cargo binstall cargo-deny -y - -_install_git-cliff: _install_cargo-binstall - cargo binstall git-cliff -y - -check: _install_cargo-hack - cargo hack check --each-feature --no-dev-deps - -generate: - # cd generator; cargo run - cargo run -p generator -- --templates-dir "generator/templates" --jsonschema-dir "cdevents-spec/schemas" --dest "cdevents-sdk/src/generated" - -build: - cargo build - -alias fmt := format - -# Format the code and sort dependencies -format: - cargo fmt - @# cargo sort --workspace --grouped - just --unstable --fmt - -deny: _install_cargo-deny - cargo deny check advisories - cargo deny check bans licenses sources - -# Lint all the code (megalinter + lint_rust) -lint: lint_rust megalinter - -# Lint the rust code -lint_rust: - just --unstable --fmt --check - cargo fmt --all -- --check # generated code is not formatted - # cargo sort --workspace --grouped --check - cargo clippy --workspace --all-features --all-targets -- --deny warnings --allow deprecated --allow unknown-lints - -# Lint with megalinter (locally via docker) -megalinter: - # rm -rf megalinter-reports - docker run --rm --name megalinter -it --env "DEFAULT_WORKSPACE=/tmp/lint" -v "${DOCKER_HOST:-/var/run/docker.sock}:/var/run/docker.sock:rw" -v "$PWD:/tmp/lint:rw" "oxsecurity/megalinter:v7" - -# Launch tests -test: _install_cargo-nextest - cargo nextest run - cargo test --doc - @# cargo hack test --each-feature - @# cargo hack nextest --each-feature -- --test-threads=1 # [cargo-hack and cargo-nextest don't compose well](https://github.com/nextest-rs/nextest/issues/1029) - -changelog: _install_git-cliff - git-cliff -o "CHANGELOG.md" - git add CHANGELOG.md && git commit -m "📝 update CHANGELOG" - -release *arguments: _install_cargo-release _install_git-cliff - cargo release --workspace --execute {{ arguments }} - @# git-cliff could not be used as `pre-release-hook` of cargo-release because it uses tag - git-cliff -o "CHANGELOG.md" - git add CHANGELOG.md && git commit -m "📝 update CHANGELOG" && git push - -run_examples: - cargo run --example pipelinerun_finished From 2a0d7327558a02bf5b812cf31b6f0f4ce6b76470 Mon Sep 17 00:00:00 2001 From: David Bernard Date: Tue, 23 Jan 2024 21:24:57 +0100 Subject: [PATCH 20/34] style: update typo, remove commented code, move comments,... apply review suggestion Signed-off-by: David Bernard --- .editorconfig | 12 -------- Cargo.toml | 5 +++- README.md | 2 +- cdevents-sdk/Cargo.toml | 4 +-- cdevents-sdk/src/serde.rs | 63 --------------------------------------- cdevents-sdk/src/uri.rs | 5 +++- generator/README.md | 4 +-- 7 files changed, 12 insertions(+), 83 deletions(-) diff --git a/.editorconfig b/.editorconfig index 8f411f9..e221a3c 100644 --- a/.editorconfig +++ b/.editorconfig @@ -17,13 +17,6 @@ indent_size = 2 #inside code block, indentation could be anything indent_size = unset -[*.py] -indent_size = 4 -# 88 is the default for black formatter -# 79 is PEP8's recommendation -# 119 is django's recommendation -max_line_length = 88 - [*.rs] # https://github.com/rust-dev-tools/fmt-rfcs/blob/master/guide/guide.md indent_size = 4 @@ -33,11 +26,6 @@ max_line_length = 200 [{*.bazel,*.bzl,BUILD,WORKSPACE}] indent_size = 4 -[*.java] -# try to align with https://github.com/diffplug/spotless (https://github.com/google/google-java-format) -indent_size = 4 -max_line_length = 100 - # The JSON files contain newlines inconsistently [*.json] insert_final_newline = unset diff --git a/Cargo.toml b/Cargo.toml index 8609fad..d01b1f1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,10 @@ members = ["cdevents-sdk", "generator"] [workspace.package] edition = "2021" version = "0.1.0" -authors = ["David Bernard"] +authors = [ + # The actual list of contributors can be retrieved from the git log + "The CDEvents Rust SDK Authors", +] license = "ASL-2.0" repository = "https://github.com/cdevents/sdk-rust" rust-version = "1.75" diff --git a/README.md b/README.md index 5dc967b..3905ac3 100644 --- a/README.md +++ b/README.md @@ -68,4 +68,4 @@ If you would like to contribute, see our [development](DEVELOPMENT.md) guide. - [CDEvents](https://cdevents.dev) - [CDEvents Primer](https://cdevents.dev/docs/primer/) -- [CDFoundation Specification](https://cdevents.dev/docs/) +- [CDEvents Specification](https://cdevents.dev/docs/) diff --git a/cdevents-sdk/Cargo.toml b/cdevents-sdk/Cargo.toml index 0369ffc..715aafb 100644 --- a/cdevents-sdk/Cargo.toml +++ b/cdevents-sdk/Cargo.toml @@ -10,9 +10,7 @@ publish = true [dependencies] cloudevents-sdk = { version = "0.7", optional = true, default-features = false } -fluent-uri = "0.1" # support uri & uri-reference, preserve the original string, but young, doesn't impl PartialEq,... -# http = "1" # doesn't support uri-reference -# http-serde = "2" +fluent-uri = "0.1" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" thiserror = "1.0" diff --git a/cdevents-sdk/src/serde.rs b/cdevents-sdk/src/serde.rs index 6865b3d..e225c2f 100644 --- a/cdevents-sdk/src/serde.rs +++ b/cdevents-sdk/src/serde.rs @@ -26,69 +26,6 @@ pub(crate) mod datetime { } } -// pub(crate) fn ok_or_none<'de, D, T>(deserializer: D) -> Result, D::Error> -// where -// D: Deserializer<'de>, -// T: Deserialize<'de>, -// { -// let v = Value::deserialize(deserializer)?; -// Ok(T::deserialize(v).ok()) -// } - -// pub(crate) mod ok_or_none { -// use serde::{Deserialize, Deserializer, Serializer}; - -// pub fn deserialize<'de, D, T>(deserializer: D) -> Result, D::Error> -// where -// D: Deserializer<'de>, -// T: Deserialize<'de>, -// { -// let v = Option::deserialize(deserializer)?; -// Ok(T::deserialize(v).ok()) -// } - -// pub fn serialize( -// input: &Option>, -// serializer: S, -// ) -> Result -// where -// S: Serializer, -// { -// match input { -// None => serializer.serialize_none(), -// Some(input) => crate::serde::uri_reference::serialize(input, serializer), -// } -// } -// } - -// pub(crate) mod uri_reference_optional { -// use serde::{Deserialize, Deserializer, Serializer}; - -// #[derive(Deserialize)] -// struct Wrapper(#[serde(with = "crate::serde::uri_reference")] fluent_uri::Uri); - -// pub fn deserialize<'de, D>(deserializer: D) -> Result>, D::Error> -// where -// D: Deserializer<'de>, -// { -// let v = Option::deserialize(deserializer)?; -// Ok(v.map(|Wrapper(a)| a)) -// } - -// pub fn serialize( -// input: &Option>, -// serializer: S, -// ) -> Result -// where -// S: Serializer, -// { -// match input { -// None => serializer.serialize_none(), -// Some(input) => crate::serde::uri_reference::serialize(input, serializer), -// } -// } -// } - pub(crate) mod fluent_uri { use serde::{de::Error, Deserialize, Deserializer, Serializer}; diff --git a/cdevents-sdk/src/uri.rs b/cdevents-sdk/src/uri.rs index 0c5fd4a..bf65638 100644 --- a/cdevents-sdk/src/uri.rs +++ b/cdevents-sdk/src/uri.rs @@ -1,6 +1,9 @@ // wrapper for fluent_uri::Uri to allow for restristed set of operations // and to complete currently missing features. -//TODO impl the check difference for URI and Uri +// Why fluent_uri? +// - support uri & uri-reference, preserve the original string, but young, doesn't impl PartialEq,... +// - http::Uri, more mature, but doesn't support uri-reference, and normalize url when generate string +//TODO impl the check difference for Uri and Uri-reference use std::str::FromStr; diff --git a/generator/README.md b/generator/README.md index 3760e75..fe1efa0 100644 --- a/generator/README.md +++ b/generator/README.md @@ -8,8 +8,8 @@ Goals: generate rust code for cdevents from jsonschema provided as part of cdeve ## Why not use a jsonschema to rust generator? -- I tried some (like ) and they failed (no error), maybe too early, not support for the version of jsonschema used by cdevents (often they support jsonschema draft-4) -- The json schema (v0.3) are not connected, so lot of duplication (context,...), so classical generator will create as many Context type as Event type,... +- I tried some and they failed (no error), maybe too early, not support for the version of jsonschema used by cdevents (often they support jsonschema draft-4) +- The json schema (v0.3) are not connected, so lot of duplication (context,...), so classical generators will create as many Context type as Event type,... Our implementation only part of the schema is extracted to generate what is different aka the `content` of subjects. ## Run From 865ebf278ece1f9a12962bfd111c92f990139ac4 Mon Sep 17 00:00:00 2001 From: David Bernard Date: Tue, 23 Jan 2024 21:52:13 +0100 Subject: [PATCH 21/34] build: update Makefile (to replace justfile) - remove `--locked`, no command to generate .lock, .lock should not be committed for a lib, and check with .lock is dangerous for a lib - add `generate` target - add `test` target Signed-off-by: David Bernard --- Makefile | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index bdac2d6..a325b62 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,31 @@ +build_docs: + cargo doc --no-deps +build_examples: + cargo build --examples +build: + cargo build +build_release: + cargo build --release +build_release_%: + cargo build --release --package $* +build_%: + cargo build --package $* + +check: + cargo check +check_no_std: + cargo --version + cargo check --target thumbv7em-none-eabihf -p ockam --no-default-features --features 'no_std alloc software_vault' + # no_std example project + cd examples/rust/example_projects/no_std + cargo check --example hello +check_cargo_update: + cargo --version + # TODO: uncomment when tauri version is updated + # rm -rf Cargo.lock + # cargo update + # cargo check + lint: lint_cargo_fmt_check lint_cargo_deny lint_cargo_clippy lint_cargo_fmt_check: @@ -20,7 +48,15 @@ lint_cargo_toml_check_files: clean: cargo clean +generate: + cargo run -p generator -- --templates-dir "generator/templates" --jsonschema-dir "cdevents-spec/schemas" --dest "cdevents-sdk/src/generated" + +test: + cargo nextest run + cargo test --doc + .PHONY: - check \ + generate \ + check test \ lint lint_cargo_fmt_check lint_cargo_deny lint_cargo_clippy lint_cargo_toml_files lint_cargo_readme lint_cargo_readme_% lint_cargo_toml_files \ clean clean_% very_clean format From de04bb21c46d7a9bfd5da8e81feca2d5a7dde4bf Mon Sep 17 00:00:00 2001 From: David Bernard Date: Tue, 23 Jan 2024 22:58:18 +0100 Subject: [PATCH 22/34] style: reformat Cargo.toml Signed-off-by: David Bernard --- Cargo.toml | 2 +- cdevents-sdk/Cargo.toml | 7 ++++--- generator/Cargo.toml | 12 ++++++------ 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d01b1f1..165a472 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ authors = [ # The actual list of contributors can be retrieved from the git log "The CDEvents Rust SDK Authors", ] -license = "ASL-2.0" +license = "Apache-2.0" repository = "https://github.com/cdevents/sdk-rust" rust-version = "1.75" publish = false diff --git a/cdevents-sdk/Cargo.toml b/cdevents-sdk/Cargo.toml index 715aafb..f5f3624 100644 --- a/cdevents-sdk/Cargo.toml +++ b/cdevents-sdk/Cargo.toml @@ -1,12 +1,13 @@ [package] name = "cdevents-sdk" -edition.workspace = true version.workspace = true authors.workspace = true +edition.workspace = true license.workspace = true +publish = true repository.workspace = true rust-version.workspace = true -publish = true +description = "A Rust SDK for CDEvents" [dependencies] cloudevents-sdk = { version = "0.7", optional = true, default-features = false } @@ -17,8 +18,8 @@ thiserror = "1.0" time = { version = "0.3", features = ["serde-human-readable"] } [dev-dependencies] -rstest = "0.18" assert-json-diff = "2.0" +rstest = "0.18" [features] default = ["cloudevents"] diff --git a/generator/Cargo.toml b/generator/Cargo.toml index f2b8cf3..fdddb63 100644 --- a/generator/Cargo.toml +++ b/generator/Cargo.toml @@ -1,23 +1,23 @@ # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [package] name = "generator" -description = "generate cdevents type from json schema on cdevents-spec" -edition.workspace = true version.workspace = true authors.workspace = true -repository.workspace = true +edition.workspace = true license.workspace = true publish.workspace = true +repository.workspace = true +description = "generate cdevents type from json schema on cdevents-spec" [dependencies] anyhow = "1.0" clap = { version = "4", features = ["derive"] } cruet = "0.14" handlebars = { version = "5", features = ["dir_source"] } -serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" -url = "2.5" handlebars_misc_helpers = { version = "0.15", default-features = false, features = [ "string", "json", ] } +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" +url = "2.5" From e0d9e948c30690b23addf6d8678cf02774f1bb0f Mon Sep 17 00:00:00 2001 From: David Bernard Date: Tue, 23 Jan 2024 23:06:01 +0100 Subject: [PATCH 23/34] build: add missing tool to `mise` configuration Signed-off-by: David Bernard --- .mise.toml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.mise.toml b/.mise.toml index e71067d..5cb09ed 100644 --- a/.mise.toml +++ b/.mise.toml @@ -8,8 +8,9 @@ MISE_CARGO_BINSTALL = "true" rust = "1.75" make = "latest" # # experimental -# "cargo:cargo-binstall" = "latest" -# "cargo:cargo-nextest" = "latest" +"cargo:cargo-binstall" = "latest" +"cargo:cargo-nextest" = "0.9" # "cargo:cargo-hack" = "latest" -# "cargo:cargo-deny" = "latest" +"cargo:cargo-deny" = "0.14" # "cargo:git-cliff" = "latest" +"cargo:dprint" = "0.45" From 184e70fb463e490e484f1089ade723e1a6befb64 Mon Sep 17 00:00:00 2001 From: David Bernard Date: Sun, 28 Jan 2024 13:59:12 +0100 Subject: [PATCH 24/34] feat: string enum are defined as rust Enum Signed-off-by: David Bernard --- .../src/generated/artifact_packaged.rs | 5 +- .../src/generated/artifact_published.rs | 1 - cdevents-sdk/src/generated/artifact_signed.rs | 1 - cdevents-sdk/src/generated/branch_created.rs | 5 +- cdevents-sdk/src/generated/branch_deleted.rs | 5 +- cdevents-sdk/src/generated/build_finished.rs | 1 - cdevents-sdk/src/generated/build_queued.rs | 1 - cdevents-sdk/src/generated/build_started.rs | 1 - .../src/generated/change_abandoned.rs | 5 +- cdevents-sdk/src/generated/change_created.rs | 5 +- cdevents-sdk/src/generated/change_merged.rs | 5 +- cdevents-sdk/src/generated/change_reviewed.rs | 5 +- cdevents-sdk/src/generated/change_updated.rs | 5 +- .../src/generated/environment_created.rs | 1 - .../src/generated/environment_deleted.rs | 1 - .../src/generated/environment_modified.rs | 1 - .../src/generated/incident_detected.rs | 9 ++- .../src/generated/incident_reported.rs | 9 ++- .../src/generated/incident_resolved.rs | 9 ++- .../src/generated/pipelinerun_finished.rs | 1 - .../src/generated/pipelinerun_queued.rs | 1 - .../src/generated/pipelinerun_started.rs | 1 - .../src/generated/repository_created.rs | 1 - .../src/generated/repository_deleted.rs | 1 - .../src/generated/repository_modified.rs | 1 - .../src/generated/service_deployed.rs | 5 +- .../src/generated/service_published.rs | 5 +- cdevents-sdk/src/generated/service_removed.rs | 5 +- .../src/generated/service_rolledback.rs | 5 +- .../src/generated/service_upgraded.rs | 5 +- .../src/generated/taskrun_finished.rs | 5 +- cdevents-sdk/src/generated/taskrun_started.rs | 5 +- .../src/generated/testcaserun_finished.rs | 61 ++++++++++++++++--- .../src/generated/testcaserun_queued.rs | 53 +++++++++++++--- .../src/generated/testcaserun_started.rs | 53 +++++++++++++--- .../src/generated/testoutput_published.rs | 19 +++++- .../src/generated/testsuiterun_finished.rs | 35 +++++++++-- .../src/generated/testsuiterun_queued.rs | 27 +++++--- .../src/generated/testsuiterun_started.rs | 27 +++++--- generator/src/main.rs | 56 ++++++++++++++--- generator/templates/variant.hbs | 12 +++- 41 files changed, 324 insertions(+), 135 deletions(-) diff --git a/cdevents-sdk/src/generated/artifact_packaged.rs b/cdevents-sdk/src/generated/artifact_packaged.rs index a8fe025..0466685 100644 --- a/cdevents-sdk/src/generated/artifact_packaged.rs +++ b/cdevents-sdk/src/generated/artifact_packaged.rs @@ -7,15 +7,14 @@ use serde::{Serialize, Deserialize}; #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "change",)] - pub change: Change, + pub change: ContentChange, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] -pub struct Change { +pub struct ContentChange { #[serde(rename = "id",)] pub id: String, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } - diff --git a/cdevents-sdk/src/generated/artifact_published.rs b/cdevents-sdk/src/generated/artifact_published.rs index e80c34f..5aed7a4 100644 --- a/cdevents-sdk/src/generated/artifact_published.rs +++ b/cdevents-sdk/src/generated/artifact_published.rs @@ -7,4 +7,3 @@ use serde::{Serialize, Deserialize}; #[serde(deny_unknown_fields)] pub struct Content { } - diff --git a/cdevents-sdk/src/generated/artifact_signed.rs b/cdevents-sdk/src/generated/artifact_signed.rs index 25a9d3b..2026353 100644 --- a/cdevents-sdk/src/generated/artifact_signed.rs +++ b/cdevents-sdk/src/generated/artifact_signed.rs @@ -9,4 +9,3 @@ pub struct Content { #[serde(rename = "signature",)] pub signature: String, } - diff --git a/cdevents-sdk/src/generated/branch_created.rs b/cdevents-sdk/src/generated/branch_created.rs index 65e29b9..8576819 100644 --- a/cdevents-sdk/src/generated/branch_created.rs +++ b/cdevents-sdk/src/generated/branch_created.rs @@ -7,15 +7,14 @@ use serde::{Serialize, Deserialize}; #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "repository", default, skip_serializing_if = "Option::is_none",)] - pub repository: Option, + pub repository: Option, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] -pub struct Repository { +pub struct ContentRepository { #[serde(rename = "id",)] pub id: String, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } - diff --git a/cdevents-sdk/src/generated/branch_deleted.rs b/cdevents-sdk/src/generated/branch_deleted.rs index 65e29b9..8576819 100644 --- a/cdevents-sdk/src/generated/branch_deleted.rs +++ b/cdevents-sdk/src/generated/branch_deleted.rs @@ -7,15 +7,14 @@ use serde::{Serialize, Deserialize}; #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "repository", default, skip_serializing_if = "Option::is_none",)] - pub repository: Option, + pub repository: Option, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] -pub struct Repository { +pub struct ContentRepository { #[serde(rename = "id",)] pub id: String, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } - diff --git a/cdevents-sdk/src/generated/build_finished.rs b/cdevents-sdk/src/generated/build_finished.rs index 1141db9..caad769 100644 --- a/cdevents-sdk/src/generated/build_finished.rs +++ b/cdevents-sdk/src/generated/build_finished.rs @@ -9,4 +9,3 @@ pub struct Content { #[serde(rename = "artifactId", default, skip_serializing_if = "Option::is_none",)] pub artifact_id: Option, } - diff --git a/cdevents-sdk/src/generated/build_queued.rs b/cdevents-sdk/src/generated/build_queued.rs index e80c34f..5aed7a4 100644 --- a/cdevents-sdk/src/generated/build_queued.rs +++ b/cdevents-sdk/src/generated/build_queued.rs @@ -7,4 +7,3 @@ use serde::{Serialize, Deserialize}; #[serde(deny_unknown_fields)] pub struct Content { } - diff --git a/cdevents-sdk/src/generated/build_started.rs b/cdevents-sdk/src/generated/build_started.rs index e80c34f..5aed7a4 100644 --- a/cdevents-sdk/src/generated/build_started.rs +++ b/cdevents-sdk/src/generated/build_started.rs @@ -7,4 +7,3 @@ use serde::{Serialize, Deserialize}; #[serde(deny_unknown_fields)] pub struct Content { } - diff --git a/cdevents-sdk/src/generated/change_abandoned.rs b/cdevents-sdk/src/generated/change_abandoned.rs index 65e29b9..8576819 100644 --- a/cdevents-sdk/src/generated/change_abandoned.rs +++ b/cdevents-sdk/src/generated/change_abandoned.rs @@ -7,15 +7,14 @@ use serde::{Serialize, Deserialize}; #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "repository", default, skip_serializing_if = "Option::is_none",)] - pub repository: Option, + pub repository: Option, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] -pub struct Repository { +pub struct ContentRepository { #[serde(rename = "id",)] pub id: String, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } - diff --git a/cdevents-sdk/src/generated/change_created.rs b/cdevents-sdk/src/generated/change_created.rs index 65e29b9..8576819 100644 --- a/cdevents-sdk/src/generated/change_created.rs +++ b/cdevents-sdk/src/generated/change_created.rs @@ -7,15 +7,14 @@ use serde::{Serialize, Deserialize}; #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "repository", default, skip_serializing_if = "Option::is_none",)] - pub repository: Option, + pub repository: Option, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] -pub struct Repository { +pub struct ContentRepository { #[serde(rename = "id",)] pub id: String, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } - diff --git a/cdevents-sdk/src/generated/change_merged.rs b/cdevents-sdk/src/generated/change_merged.rs index 65e29b9..8576819 100644 --- a/cdevents-sdk/src/generated/change_merged.rs +++ b/cdevents-sdk/src/generated/change_merged.rs @@ -7,15 +7,14 @@ use serde::{Serialize, Deserialize}; #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "repository", default, skip_serializing_if = "Option::is_none",)] - pub repository: Option, + pub repository: Option, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] -pub struct Repository { +pub struct ContentRepository { #[serde(rename = "id",)] pub id: String, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } - diff --git a/cdevents-sdk/src/generated/change_reviewed.rs b/cdevents-sdk/src/generated/change_reviewed.rs index 65e29b9..8576819 100644 --- a/cdevents-sdk/src/generated/change_reviewed.rs +++ b/cdevents-sdk/src/generated/change_reviewed.rs @@ -7,15 +7,14 @@ use serde::{Serialize, Deserialize}; #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "repository", default, skip_serializing_if = "Option::is_none",)] - pub repository: Option, + pub repository: Option, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] -pub struct Repository { +pub struct ContentRepository { #[serde(rename = "id",)] pub id: String, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } - diff --git a/cdevents-sdk/src/generated/change_updated.rs b/cdevents-sdk/src/generated/change_updated.rs index 65e29b9..8576819 100644 --- a/cdevents-sdk/src/generated/change_updated.rs +++ b/cdevents-sdk/src/generated/change_updated.rs @@ -7,15 +7,14 @@ use serde::{Serialize, Deserialize}; #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "repository", default, skip_serializing_if = "Option::is_none",)] - pub repository: Option, + pub repository: Option, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] -pub struct Repository { +pub struct ContentRepository { #[serde(rename = "id",)] pub id: String, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } - diff --git a/cdevents-sdk/src/generated/environment_created.rs b/cdevents-sdk/src/generated/environment_created.rs index e2f42cc..1ac2d85 100644 --- a/cdevents-sdk/src/generated/environment_created.rs +++ b/cdevents-sdk/src/generated/environment_created.rs @@ -11,4 +11,3 @@ pub struct Content { #[serde(rename = "url", default, skip_serializing_if = "Option::is_none",)] pub url: Option, } - diff --git a/cdevents-sdk/src/generated/environment_deleted.rs b/cdevents-sdk/src/generated/environment_deleted.rs index d436795..c21a2fa 100644 --- a/cdevents-sdk/src/generated/environment_deleted.rs +++ b/cdevents-sdk/src/generated/environment_deleted.rs @@ -9,4 +9,3 @@ pub struct Content { #[serde(rename = "name", default, skip_serializing_if = "Option::is_none",)] pub name: Option, } - diff --git a/cdevents-sdk/src/generated/environment_modified.rs b/cdevents-sdk/src/generated/environment_modified.rs index e2f42cc..1ac2d85 100644 --- a/cdevents-sdk/src/generated/environment_modified.rs +++ b/cdevents-sdk/src/generated/environment_modified.rs @@ -11,4 +11,3 @@ pub struct Content { #[serde(rename = "url", default, skip_serializing_if = "Option::is_none",)] pub url: Option, } - diff --git a/cdevents-sdk/src/generated/incident_detected.rs b/cdevents-sdk/src/generated/incident_detected.rs index a2f4d67..5a91da9 100644 --- a/cdevents-sdk/src/generated/incident_detected.rs +++ b/cdevents-sdk/src/generated/incident_detected.rs @@ -11,14 +11,14 @@ pub struct Content { #[serde(rename = "description", default, skip_serializing_if = "Option::is_none",)] pub description: Option, #[serde(rename = "environment",)] - pub environment: Environment, + pub environment: ContentEnvironment, #[serde(rename = "service", default, skip_serializing_if = "Option::is_none",)] - pub service: Option, + pub service: Option, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] -pub struct Service { +pub struct ContentService { #[serde(rename = "id",)] pub id: String, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] @@ -27,10 +27,9 @@ pub struct Service { #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] -pub struct Environment { +pub struct ContentEnvironment { #[serde(rename = "id",)] pub id: String, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } - diff --git a/cdevents-sdk/src/generated/incident_reported.rs b/cdevents-sdk/src/generated/incident_reported.rs index fb70170..ec30ed6 100644 --- a/cdevents-sdk/src/generated/incident_reported.rs +++ b/cdevents-sdk/src/generated/incident_reported.rs @@ -11,16 +11,16 @@ pub struct Content { #[serde(rename = "description", default, skip_serializing_if = "Option::is_none",)] pub description: Option, #[serde(rename = "environment",)] - pub environment: Environment, + pub environment: ContentEnvironment, #[serde(rename = "service", default, skip_serializing_if = "Option::is_none",)] - pub service: Option, + pub service: Option, #[serde(rename = "ticketURI",)] pub ticket_uri: crate::Uri, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] -pub struct Service { +pub struct ContentService { #[serde(rename = "id",)] pub id: String, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] @@ -29,10 +29,9 @@ pub struct Service { #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] -pub struct Environment { +pub struct ContentEnvironment { #[serde(rename = "id",)] pub id: String, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } - diff --git a/cdevents-sdk/src/generated/incident_resolved.rs b/cdevents-sdk/src/generated/incident_resolved.rs index a2f4d67..5a91da9 100644 --- a/cdevents-sdk/src/generated/incident_resolved.rs +++ b/cdevents-sdk/src/generated/incident_resolved.rs @@ -11,14 +11,14 @@ pub struct Content { #[serde(rename = "description", default, skip_serializing_if = "Option::is_none",)] pub description: Option, #[serde(rename = "environment",)] - pub environment: Environment, + pub environment: ContentEnvironment, #[serde(rename = "service", default, skip_serializing_if = "Option::is_none",)] - pub service: Option, + pub service: Option, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] -pub struct Service { +pub struct ContentService { #[serde(rename = "id",)] pub id: String, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] @@ -27,10 +27,9 @@ pub struct Service { #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] -pub struct Environment { +pub struct ContentEnvironment { #[serde(rename = "id",)] pub id: String, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } - diff --git a/cdevents-sdk/src/generated/pipelinerun_finished.rs b/cdevents-sdk/src/generated/pipelinerun_finished.rs index 953e175..bbad121 100644 --- a/cdevents-sdk/src/generated/pipelinerun_finished.rs +++ b/cdevents-sdk/src/generated/pipelinerun_finished.rs @@ -15,4 +15,3 @@ pub struct Content { #[serde(rename = "url", default, skip_serializing_if = "Option::is_none",)] pub url: Option, } - diff --git a/cdevents-sdk/src/generated/pipelinerun_queued.rs b/cdevents-sdk/src/generated/pipelinerun_queued.rs index f949258..45a82fc 100644 --- a/cdevents-sdk/src/generated/pipelinerun_queued.rs +++ b/cdevents-sdk/src/generated/pipelinerun_queued.rs @@ -11,4 +11,3 @@ pub struct Content { #[serde(rename = "url", default, skip_serializing_if = "Option::is_none",)] pub url: Option, } - diff --git a/cdevents-sdk/src/generated/pipelinerun_started.rs b/cdevents-sdk/src/generated/pipelinerun_started.rs index 0939cd8..d69896d 100644 --- a/cdevents-sdk/src/generated/pipelinerun_started.rs +++ b/cdevents-sdk/src/generated/pipelinerun_started.rs @@ -11,4 +11,3 @@ pub struct Content { #[serde(rename = "url",)] pub url: String, } - diff --git a/cdevents-sdk/src/generated/repository_created.rs b/cdevents-sdk/src/generated/repository_created.rs index 85060ef..5523ece 100644 --- a/cdevents-sdk/src/generated/repository_created.rs +++ b/cdevents-sdk/src/generated/repository_created.rs @@ -15,4 +15,3 @@ pub struct Content { #[serde(rename = "viewUrl", default, skip_serializing_if = "Option::is_none",)] pub view_url: Option, } - diff --git a/cdevents-sdk/src/generated/repository_deleted.rs b/cdevents-sdk/src/generated/repository_deleted.rs index 6334f12..e02fea0 100644 --- a/cdevents-sdk/src/generated/repository_deleted.rs +++ b/cdevents-sdk/src/generated/repository_deleted.rs @@ -15,4 +15,3 @@ pub struct Content { #[serde(rename = "viewUrl", default, skip_serializing_if = "Option::is_none",)] pub view_url: Option, } - diff --git a/cdevents-sdk/src/generated/repository_modified.rs b/cdevents-sdk/src/generated/repository_modified.rs index 6334f12..e02fea0 100644 --- a/cdevents-sdk/src/generated/repository_modified.rs +++ b/cdevents-sdk/src/generated/repository_modified.rs @@ -15,4 +15,3 @@ pub struct Content { #[serde(rename = "viewUrl", default, skip_serializing_if = "Option::is_none",)] pub view_url: Option, } - diff --git a/cdevents-sdk/src/generated/service_deployed.rs b/cdevents-sdk/src/generated/service_deployed.rs index 868b9fe..0f6dc2c 100644 --- a/cdevents-sdk/src/generated/service_deployed.rs +++ b/cdevents-sdk/src/generated/service_deployed.rs @@ -9,15 +9,14 @@ pub struct Content { #[serde(rename = "artifactId",)] pub artifact_id: String, #[serde(rename = "environment",)] - pub environment: Environment, + pub environment: ContentEnvironment, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] -pub struct Environment { +pub struct ContentEnvironment { #[serde(rename = "id",)] pub id: String, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } - diff --git a/cdevents-sdk/src/generated/service_published.rs b/cdevents-sdk/src/generated/service_published.rs index eaf2687..02e23c7 100644 --- a/cdevents-sdk/src/generated/service_published.rs +++ b/cdevents-sdk/src/generated/service_published.rs @@ -7,15 +7,14 @@ use serde::{Serialize, Deserialize}; #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "environment", default, skip_serializing_if = "Option::is_none",)] - pub environment: Option, + pub environment: Option, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] -pub struct Environment { +pub struct ContentEnvironment { #[serde(rename = "id",)] pub id: String, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } - diff --git a/cdevents-sdk/src/generated/service_removed.rs b/cdevents-sdk/src/generated/service_removed.rs index eaf2687..02e23c7 100644 --- a/cdevents-sdk/src/generated/service_removed.rs +++ b/cdevents-sdk/src/generated/service_removed.rs @@ -7,15 +7,14 @@ use serde::{Serialize, Deserialize}; #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "environment", default, skip_serializing_if = "Option::is_none",)] - pub environment: Option, + pub environment: Option, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] -pub struct Environment { +pub struct ContentEnvironment { #[serde(rename = "id",)] pub id: String, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } - diff --git a/cdevents-sdk/src/generated/service_rolledback.rs b/cdevents-sdk/src/generated/service_rolledback.rs index 868b9fe..0f6dc2c 100644 --- a/cdevents-sdk/src/generated/service_rolledback.rs +++ b/cdevents-sdk/src/generated/service_rolledback.rs @@ -9,15 +9,14 @@ pub struct Content { #[serde(rename = "artifactId",)] pub artifact_id: String, #[serde(rename = "environment",)] - pub environment: Environment, + pub environment: ContentEnvironment, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] -pub struct Environment { +pub struct ContentEnvironment { #[serde(rename = "id",)] pub id: String, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } - diff --git a/cdevents-sdk/src/generated/service_upgraded.rs b/cdevents-sdk/src/generated/service_upgraded.rs index 868b9fe..0f6dc2c 100644 --- a/cdevents-sdk/src/generated/service_upgraded.rs +++ b/cdevents-sdk/src/generated/service_upgraded.rs @@ -9,15 +9,14 @@ pub struct Content { #[serde(rename = "artifactId",)] pub artifact_id: String, #[serde(rename = "environment",)] - pub environment: Environment, + pub environment: ContentEnvironment, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] -pub struct Environment { +pub struct ContentEnvironment { #[serde(rename = "id",)] pub id: String, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } - diff --git a/cdevents-sdk/src/generated/taskrun_finished.rs b/cdevents-sdk/src/generated/taskrun_finished.rs index 5259c46..27b4338 100644 --- a/cdevents-sdk/src/generated/taskrun_finished.rs +++ b/cdevents-sdk/src/generated/taskrun_finished.rs @@ -11,7 +11,7 @@ pub struct Content { #[serde(rename = "outcome", default, skip_serializing_if = "Option::is_none",)] pub outcome: Option, #[serde(rename = "pipelineRun", default, skip_serializing_if = "Option::is_none",)] - pub pipeline_run: Option, + pub pipeline_run: Option, #[serde(rename = "taskName", default, skip_serializing_if = "Option::is_none",)] pub task_name: Option, #[serde(rename = "url", default, skip_serializing_if = "Option::is_none",)] @@ -20,10 +20,9 @@ pub struct Content { #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] -pub struct PipelineRun { +pub struct ContentPipelineRun { #[serde(rename = "id",)] pub id: String, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } - diff --git a/cdevents-sdk/src/generated/taskrun_started.rs b/cdevents-sdk/src/generated/taskrun_started.rs index d294376..13cba66 100644 --- a/cdevents-sdk/src/generated/taskrun_started.rs +++ b/cdevents-sdk/src/generated/taskrun_started.rs @@ -7,7 +7,7 @@ use serde::{Serialize, Deserialize}; #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "pipelineRun", default, skip_serializing_if = "Option::is_none",)] - pub pipeline_run: Option, + pub pipeline_run: Option, #[serde(rename = "taskName", default, skip_serializing_if = "Option::is_none",)] pub task_name: Option, #[serde(rename = "url", default, skip_serializing_if = "Option::is_none",)] @@ -16,10 +16,9 @@ pub struct Content { #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] -pub struct PipelineRun { +pub struct ContentPipelineRun { #[serde(rename = "id",)] pub id: String, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } - diff --git a/cdevents-sdk/src/generated/testcaserun_finished.rs b/cdevents-sdk/src/generated/testcaserun_finished.rs index 018e348..46656e1 100644 --- a/cdevents-sdk/src/generated/testcaserun_finished.rs +++ b/cdevents-sdk/src/generated/testcaserun_finished.rs @@ -7,22 +7,22 @@ use serde::{Serialize, Deserialize}; #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "environment",)] - pub environment: Environment, + pub environment: ContentEnvironment, #[serde(rename = "outcome",)] - pub outcome: String, + pub outcome: ContentOutcome, #[serde(rename = "reason", default, skip_serializing_if = "Option::is_none",)] pub reason: Option, #[serde(rename = "severity", default, skip_serializing_if = "Option::is_none",)] - pub severity: Option, + pub severity: Option, #[serde(rename = "testCase", default, skip_serializing_if = "Option::is_none",)] - pub test_case: Option, + pub test_case: Option, #[serde(rename = "testSuiteRun", default, skip_serializing_if = "Option::is_none",)] - pub test_suite_run: Option, + pub test_suite_run: Option, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] -pub struct TestSuiteRun { +pub struct ContentTestSuiteRun { #[serde(rename = "id",)] pub id: String, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] @@ -31,13 +31,13 @@ pub struct TestSuiteRun { #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] -pub struct TestCase { +pub struct ContentTestCase { #[serde(rename = "id",)] pub id: String, #[serde(rename = "name", default, skip_serializing_if = "Option::is_none",)] pub name: Option, #[serde(rename = "type", default, skip_serializing_if = "Option::is_none",)] - pub ty: Option, + pub ty: Option, #[serde(rename = "uri", default, skip_serializing_if = "Option::is_none",)] pub uri: Option, #[serde(rename = "version", default, skip_serializing_if = "Option::is_none",)] @@ -46,10 +46,53 @@ pub struct TestCase { #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] -pub struct Environment { +pub struct ContentEnvironment { #[serde(rename = "id",)] pub id: String, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } +#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)] +pub enum ContentOutcome { + #[serde(rename = "pass")] + Pass, + #[serde(rename = "fail")] + Fail, + #[serde(rename = "cancel")] + Cancel, + #[serde(rename = "error")] + Error, +} + +#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)] +pub enum ContentSeverity { + #[serde(rename = "low")] + Low, + #[serde(rename = "medium")] + Medium, + #[serde(rename = "high")] + High, + #[serde(rename = "critical")] + Critical, +} + +#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)] +pub enum ContentTestCaseType { + #[serde(rename = "performance")] + Performance, + #[serde(rename = "functional")] + Functional, + #[serde(rename = "unit")] + Unit, + #[serde(rename = "security")] + Security, + #[serde(rename = "compliance")] + Compliance, + #[serde(rename = "integration")] + Integration, + #[serde(rename = "e2e")] + E2E, + #[serde(rename = "other")] + Other, +} diff --git a/cdevents-sdk/src/generated/testcaserun_queued.rs b/cdevents-sdk/src/generated/testcaserun_queued.rs index 72c1cf2..1c65fdb 100644 --- a/cdevents-sdk/src/generated/testcaserun_queued.rs +++ b/cdevents-sdk/src/generated/testcaserun_queued.rs @@ -7,27 +7,27 @@ use serde::{Serialize, Deserialize}; #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "environment",)] - pub environment: Environment, + pub environment: ContentEnvironment, #[serde(rename = "testCase", default, skip_serializing_if = "Option::is_none",)] - pub test_case: Option, + pub test_case: Option, #[serde(rename = "testSuiteRun", default, skip_serializing_if = "Option::is_none",)] - pub test_suite_run: Option, + pub test_suite_run: Option, #[serde(rename = "trigger", default, skip_serializing_if = "Option::is_none",)] - pub trigger: Option, + pub trigger: Option, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] -pub struct Trigger { +pub struct ContentTrigger { #[serde(rename = "type", default, skip_serializing_if = "Option::is_none",)] - pub ty: Option, + pub ty: Option, #[serde(rename = "uri", default, skip_serializing_if = "Option::is_none",)] pub uri: Option, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] -pub struct TestSuiteRun { +pub struct ContentTestSuiteRun { #[serde(rename = "id",)] pub id: String, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] @@ -36,13 +36,13 @@ pub struct TestSuiteRun { #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] -pub struct TestCase { +pub struct ContentTestCase { #[serde(rename = "id",)] pub id: String, #[serde(rename = "name", default, skip_serializing_if = "Option::is_none",)] pub name: Option, #[serde(rename = "type", default, skip_serializing_if = "Option::is_none",)] - pub ty: Option, + pub ty: Option, #[serde(rename = "uri", default, skip_serializing_if = "Option::is_none",)] pub uri: Option, #[serde(rename = "version", default, skip_serializing_if = "Option::is_none",)] @@ -51,10 +51,43 @@ pub struct TestCase { #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] -pub struct Environment { +pub struct ContentEnvironment { #[serde(rename = "id",)] pub id: String, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } +#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)] +pub enum ContentTestCaseType { + #[serde(rename = "performance")] + Performance, + #[serde(rename = "functional")] + Functional, + #[serde(rename = "unit")] + Unit, + #[serde(rename = "security")] + Security, + #[serde(rename = "compliance")] + Compliance, + #[serde(rename = "integration")] + Integration, + #[serde(rename = "e2e")] + E2E, + #[serde(rename = "other")] + Other, +} + +#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)] +pub enum ContentTriggerType { + #[serde(rename = "manual")] + Manual, + #[serde(rename = "pipeline")] + Pipeline, + #[serde(rename = "event")] + Event, + #[serde(rename = "schedule")] + Schedule, + #[serde(rename = "other")] + Other, +} diff --git a/cdevents-sdk/src/generated/testcaserun_started.rs b/cdevents-sdk/src/generated/testcaserun_started.rs index 72c1cf2..1c65fdb 100644 --- a/cdevents-sdk/src/generated/testcaserun_started.rs +++ b/cdevents-sdk/src/generated/testcaserun_started.rs @@ -7,27 +7,27 @@ use serde::{Serialize, Deserialize}; #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "environment",)] - pub environment: Environment, + pub environment: ContentEnvironment, #[serde(rename = "testCase", default, skip_serializing_if = "Option::is_none",)] - pub test_case: Option, + pub test_case: Option, #[serde(rename = "testSuiteRun", default, skip_serializing_if = "Option::is_none",)] - pub test_suite_run: Option, + pub test_suite_run: Option, #[serde(rename = "trigger", default, skip_serializing_if = "Option::is_none",)] - pub trigger: Option, + pub trigger: Option, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] -pub struct Trigger { +pub struct ContentTrigger { #[serde(rename = "type", default, skip_serializing_if = "Option::is_none",)] - pub ty: Option, + pub ty: Option, #[serde(rename = "uri", default, skip_serializing_if = "Option::is_none",)] pub uri: Option, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] -pub struct TestSuiteRun { +pub struct ContentTestSuiteRun { #[serde(rename = "id",)] pub id: String, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] @@ -36,13 +36,13 @@ pub struct TestSuiteRun { #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] -pub struct TestCase { +pub struct ContentTestCase { #[serde(rename = "id",)] pub id: String, #[serde(rename = "name", default, skip_serializing_if = "Option::is_none",)] pub name: Option, #[serde(rename = "type", default, skip_serializing_if = "Option::is_none",)] - pub ty: Option, + pub ty: Option, #[serde(rename = "uri", default, skip_serializing_if = "Option::is_none",)] pub uri: Option, #[serde(rename = "version", default, skip_serializing_if = "Option::is_none",)] @@ -51,10 +51,43 @@ pub struct TestCase { #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] -pub struct Environment { +pub struct ContentEnvironment { #[serde(rename = "id",)] pub id: String, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } +#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)] +pub enum ContentTestCaseType { + #[serde(rename = "performance")] + Performance, + #[serde(rename = "functional")] + Functional, + #[serde(rename = "unit")] + Unit, + #[serde(rename = "security")] + Security, + #[serde(rename = "compliance")] + Compliance, + #[serde(rename = "integration")] + Integration, + #[serde(rename = "e2e")] + E2E, + #[serde(rename = "other")] + Other, +} + +#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)] +pub enum ContentTriggerType { + #[serde(rename = "manual")] + Manual, + #[serde(rename = "pipeline")] + Pipeline, + #[serde(rename = "event")] + Event, + #[serde(rename = "schedule")] + Schedule, + #[serde(rename = "other")] + Other, +} diff --git a/cdevents-sdk/src/generated/testoutput_published.rs b/cdevents-sdk/src/generated/testoutput_published.rs index c16158b..e673427 100644 --- a/cdevents-sdk/src/generated/testoutput_published.rs +++ b/cdevents-sdk/src/generated/testoutput_published.rs @@ -9,19 +9,32 @@ pub struct Content { #[serde(rename = "format",)] pub format: String, #[serde(rename = "outputType",)] - pub output_type: String, + pub output_type: ContentOutputType, #[serde(rename = "testCaseRun", default, skip_serializing_if = "Option::is_none",)] - pub test_case_run: Option, + pub test_case_run: Option, #[serde(rename = "uri", default, skip_serializing_if = "Option::is_none",)] pub uri: Option, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] -pub struct TestCaseRun { +pub struct ContentTestCaseRun { #[serde(rename = "id",)] pub id: String, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } +#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)] +pub enum ContentOutputType { + #[serde(rename = "report")] + Report, + #[serde(rename = "video")] + Video, + #[serde(rename = "image")] + Image, + #[serde(rename = "log")] + Log, + #[serde(rename = "other")] + Other, +} diff --git a/cdevents-sdk/src/generated/testsuiterun_finished.rs b/cdevents-sdk/src/generated/testsuiterun_finished.rs index 9f384bc..40496ef 100644 --- a/cdevents-sdk/src/generated/testsuiterun_finished.rs +++ b/cdevents-sdk/src/generated/testsuiterun_finished.rs @@ -7,20 +7,20 @@ use serde::{Serialize, Deserialize}; #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "environment",)] - pub environment: Environment, + pub environment: ContentEnvironment, #[serde(rename = "outcome",)] - pub outcome: String, + pub outcome: ContentOutcome, #[serde(rename = "reason", default, skip_serializing_if = "Option::is_none",)] pub reason: Option, #[serde(rename = "severity", default, skip_serializing_if = "Option::is_none",)] - pub severity: Option, + pub severity: Option, #[serde(rename = "testSuite", default, skip_serializing_if = "Option::is_none",)] - pub test_suite: Option, + pub test_suite: Option, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] -pub struct TestSuite { +pub struct ContentTestSuite { #[serde(rename = "id",)] pub id: String, #[serde(rename = "name", default, skip_serializing_if = "Option::is_none",)] @@ -33,10 +33,33 @@ pub struct TestSuite { #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] -pub struct Environment { +pub struct ContentEnvironment { #[serde(rename = "id",)] pub id: String, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } +#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)] +pub enum ContentOutcome { + #[serde(rename = "pass")] + Pass, + #[serde(rename = "fail")] + Fail, + #[serde(rename = "cancel")] + Cancel, + #[serde(rename = "error")] + Error, +} + +#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)] +pub enum ContentSeverity { + #[serde(rename = "low")] + Low, + #[serde(rename = "medium")] + Medium, + #[serde(rename = "high")] + High, + #[serde(rename = "critical")] + Critical, +} diff --git a/cdevents-sdk/src/generated/testsuiterun_queued.rs b/cdevents-sdk/src/generated/testsuiterun_queued.rs index db1a1f7..1b2e244 100644 --- a/cdevents-sdk/src/generated/testsuiterun_queued.rs +++ b/cdevents-sdk/src/generated/testsuiterun_queued.rs @@ -7,25 +7,25 @@ use serde::{Serialize, Deserialize}; #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "environment",)] - pub environment: Environment, + pub environment: ContentEnvironment, #[serde(rename = "testSuite", default, skip_serializing_if = "Option::is_none",)] - pub test_suite: Option, + pub test_suite: Option, #[serde(rename = "trigger", default, skip_serializing_if = "Option::is_none",)] - pub trigger: Option, + pub trigger: Option, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] -pub struct Trigger { +pub struct ContentTrigger { #[serde(rename = "type", default, skip_serializing_if = "Option::is_none",)] - pub ty: Option, + pub ty: Option, #[serde(rename = "uri", default, skip_serializing_if = "Option::is_none",)] pub uri: Option, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] -pub struct TestSuite { +pub struct ContentTestSuite { #[serde(rename = "id",)] pub id: String, #[serde(rename = "name", default, skip_serializing_if = "Option::is_none",)] @@ -38,10 +38,23 @@ pub struct TestSuite { #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] -pub struct Environment { +pub struct ContentEnvironment { #[serde(rename = "id",)] pub id: String, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } +#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)] +pub enum ContentTriggerType { + #[serde(rename = "manual")] + Manual, + #[serde(rename = "pipeline")] + Pipeline, + #[serde(rename = "event")] + Event, + #[serde(rename = "schedule")] + Schedule, + #[serde(rename = "other")] + Other, +} diff --git a/cdevents-sdk/src/generated/testsuiterun_started.rs b/cdevents-sdk/src/generated/testsuiterun_started.rs index f2c3ff4..3591ca1 100644 --- a/cdevents-sdk/src/generated/testsuiterun_started.rs +++ b/cdevents-sdk/src/generated/testsuiterun_started.rs @@ -7,25 +7,25 @@ use serde::{Serialize, Deserialize}; #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "environment",)] - pub environment: Environment, + pub environment: ContentEnvironment, #[serde(rename = "testSuite", default, skip_serializing_if = "Option::is_none",)] - pub test_suite: Option, + pub test_suite: Option, #[serde(rename = "trigger", default, skip_serializing_if = "Option::is_none",)] - pub trigger: Option, + pub trigger: Option, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] -pub struct Trigger { +pub struct ContentTrigger { #[serde(rename = "type", default, skip_serializing_if = "Option::is_none",)] - pub ty: Option, + pub ty: Option, #[serde(rename = "uri", default, skip_serializing_if = "Option::is_none",)] pub uri: Option, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] -pub struct TestSuite { +pub struct ContentTestSuite { #[serde(rename = "id",)] pub id: String, #[serde(rename = "name", default, skip_serializing_if = "Option::is_none",)] @@ -38,10 +38,23 @@ pub struct TestSuite { #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] -pub struct Environment { +pub struct ContentEnvironment { #[serde(rename = "id",)] pub id: String, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } +#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)] +pub enum ContentTriggerType { + #[serde(rename = "manual")] + Manual, + #[serde(rename = "pipeline")] + Pipeline, + #[serde(rename = "event")] + Event, + #[serde(rename = "schedule")] + Schedule, + #[serde(rename = "other")] + Other, +} diff --git a/generator/src/main.rs b/generator/src/main.rs index 40ffdc1..2cf0425 100644 --- a/generator/src/main.rs +++ b/generator/src/main.rs @@ -107,15 +107,18 @@ fn generate_module(hbs: &Handlebars, variants: &[VariantInfo]) -> Result<(String fn build_data_for_variants(jsonschema: Value) -> Value { let mut structs = vec![]; + let mut enums = vec![]; collect_structs( &mut structs, - "content", + &mut enums, + &["content"], &jsonschema["properties"]["subject"]["properties"]["content"], ); structs.reverse(); json!({ "structs": structs, + "enums": enums, "jsonschema": jsonschema, }) } @@ -139,6 +142,14 @@ struct StructDef { fields: Vec, } +#[derive(Debug, Clone, Serialize, Deserialize)] +struct EnumDef { + type_info: TypeInfo, + json_definition: Value, + /// (is_default, value as string) + values: Vec<(bool, String)>, +} + #[derive(Debug, Clone, Serialize, Deserialize)] struct FieldDef { rust_name: String, @@ -149,7 +160,8 @@ struct FieldDef { fn collect_structs( structs: &mut Vec, - field_name: &str, + enums: &mut Vec, + field_names: &[&str], json_definition: &Value, ) -> TypeInfo { match json_definition["type"].as_str() { @@ -172,9 +184,29 @@ fn collect_structs( // serde_with: Some("crate::serde::uri".to_string()), // }, //TODO manage enum - _ => TypeInfo { - type_declaration: "String".to_string(), - ..Default::default() + _ => match json_definition["enum"].as_array() { + None => TypeInfo { + type_declaration: "String".to_string(), + ..Default::default() + }, + Some(values) => { + let default_value = json_definition["default"].as_str(); + let values = values + .iter() + .map(|v| v.as_str().unwrap_or_default().to_string()) + .map(|v| (default_value == Some(&v), v)) + .collect::>(); + let type_info = TypeInfo { + type_declaration: to_type_name(field_names), + ..Default::default() + }; + enums.push(EnumDef { + type_info: type_info.clone(), + json_definition: json_definition.clone(), + values, + }); + type_info + } }, }, Some("object") => match json_definition["properties"].as_object() { @@ -193,7 +225,11 @@ fn collect_structs( } else { serde_name.to_snake_case() }; - let mut type_info = collect_structs(structs, &serde_name, field.1); + let mut children_field_names = vec![]; + children_field_names.extend_from_slice(field_names); + children_field_names.push(&serde_name); + let mut type_info = + collect_structs(structs, enums, &children_field_names, field.1); let field_name = json!(&serde_name); let is_optional = required.map(|a| !a.contains(&field_name)).unwrap_or(true); @@ -210,7 +246,7 @@ fn collect_structs( }) .collect::>(); let type_info = TypeInfo { - type_declaration: field_name.to_class_case(), + type_declaration: to_type_name(field_names), ..Default::default() }; structs.push(StructDef { @@ -222,6 +258,10 @@ fn collect_structs( } }, Some(x) => todo!("impl for type='{}'", x), - None => unimplemented!("expected key 'type' in field '{}'", field_name), + None => unimplemented!("expected key 'type' in field '{}'", field_names.join(".")), } } + +fn to_type_name(fied_names: &[&str]) -> String { + fied_names.join("_").to_class_case() +} diff --git a/generator/templates/variant.hbs b/generator/templates/variant.hbs index f98780a..1cddc8b 100644 --- a/generator/templates/variant.hbs +++ b/generator/templates/variant.hbs @@ -2,8 +2,8 @@ // by cdevents/sdk-rust/generator (subject.hbs) use serde::{Serialize, Deserialize}; - {{#each structs }} + #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub struct {{ this.type_info.type_declaration }} { @@ -15,5 +15,15 @@ pub struct {{ this.type_info.type_declaration }} { pub {{ this.rust_name }}: {{this.type_info.type_declaration }}, {{/each}} } +{{/each}} +{{#each enums }} +#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)] +pub enum {{ this.type_info.type_declaration }} { + {{#each this.values }} + #[serde(rename = "{{this.1}}")]{{#if this.0}} + #[default]{{/if}} + {{to_class_case this.1}}, + {{/each}} +} {{/each}} From d9527529bfb9a99a69a61e8d5293668f0d1a0a88 Mon Sep 17 00:00:00 2001 From: David Bernard Date: Sun, 28 Jan 2024 18:01:14 +0100 Subject: [PATCH 25/34] feat(testkit): provide proptest 's arbitraies to generate samples Signed-off-by: David Bernard --- Makefile | 4 +- cdevents-sdk/Cargo.toml | 6 +++ cdevents-sdk/src/cdevent.rs | 37 ++++++++++++++ .../src/generated/artifact_packaged.rs | 19 +++++++ .../src/generated/artifact_published.rs | 18 +++++++ cdevents-sdk/src/generated/artifact_signed.rs | 18 +++++++ cdevents-sdk/src/generated/branch_created.rs | 19 +++++++ cdevents-sdk/src/generated/branch_deleted.rs | 19 +++++++ cdevents-sdk/src/generated/build_finished.rs | 18 +++++++ cdevents-sdk/src/generated/build_queued.rs | 18 +++++++ cdevents-sdk/src/generated/build_started.rs | 18 +++++++ .../src/generated/change_abandoned.rs | 19 +++++++ cdevents-sdk/src/generated/change_created.rs | 19 +++++++ cdevents-sdk/src/generated/change_merged.rs | 19 +++++++ cdevents-sdk/src/generated/change_reviewed.rs | 19 +++++++ cdevents-sdk/src/generated/change_updated.rs | 19 +++++++ .../src/generated/environment_created.rs | 18 +++++++ .../src/generated/environment_deleted.rs | 18 +++++++ .../src/generated/environment_modified.rs | 18 +++++++ .../src/generated/incident_detected.rs | 20 ++++++++ .../src/generated/incident_reported.rs | 20 ++++++++ .../src/generated/incident_resolved.rs | 20 ++++++++ cdevents-sdk/src/generated/mod.rs | 51 +++++++++++++++++++ .../src/generated/pipelinerun_finished.rs | 18 +++++++ .../src/generated/pipelinerun_queued.rs | 18 +++++++ .../src/generated/pipelinerun_started.rs | 18 +++++++ .../src/generated/repository_created.rs | 18 +++++++ .../src/generated/repository_deleted.rs | 18 +++++++ .../src/generated/repository_modified.rs | 18 +++++++ .../src/generated/service_deployed.rs | 19 +++++++ .../src/generated/service_published.rs | 19 +++++++ cdevents-sdk/src/generated/service_removed.rs | 19 +++++++ .../src/generated/service_rolledback.rs | 19 +++++++ .../src/generated/service_upgraded.rs | 19 +++++++ .../src/generated/taskrun_finished.rs | 19 +++++++ cdevents-sdk/src/generated/taskrun_started.rs | 19 +++++++ .../src/generated/testcaserun_finished.rs | 24 +++++++++ .../src/generated/testcaserun_queued.rs | 24 +++++++++ .../src/generated/testcaserun_started.rs | 24 +++++++++ .../src/generated/testoutput_published.rs | 20 ++++++++ .../src/generated/testsuiterun_finished.rs | 22 ++++++++ .../src/generated/testsuiterun_queued.rs | 22 ++++++++ .../src/generated/testsuiterun_started.rs | 22 ++++++++ cdevents-sdk/src/subject.rs | 37 ++++++++++++++ cdevents-sdk/src/uri.rs | 25 ++++++++- cdevents-sdk/src/uri_reference.rs | 36 ++++++++++++- generator/templates/mod.hbs | 15 ++++++ generator/templates/variant.hbs | 19 +++++++ 48 files changed, 979 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index a325b62..a5d16a5 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ build_%: cargo build --package $* check: - cargo check + cargo hack check --each-feature check_no_std: cargo --version cargo check --target thumbv7em-none-eabihf -p ockam --no-default-features --features 'no_std alloc software_vault' @@ -52,7 +52,7 @@ generate: cargo run -p generator -- --templates-dir "generator/templates" --jsonschema-dir "cdevents-spec/schemas" --dest "cdevents-sdk/src/generated" test: - cargo nextest run + cargo nextest run --all-features cargo test --doc .PHONY: diff --git a/cdevents-sdk/Cargo.toml b/cdevents-sdk/Cargo.toml index f5f3624..9cc5395 100644 --- a/cdevents-sdk/Cargo.toml +++ b/cdevents-sdk/Cargo.toml @@ -12,6 +12,8 @@ description = "A Rust SDK for CDEvents" [dependencies] cloudevents-sdk = { version = "0.7", optional = true, default-features = false } fluent-uri = "0.1" +proptest = { version = "1.4", optional = true } +proptest-derive = { version = "0.4", optional = true } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" thiserror = "1.0" @@ -19,8 +21,12 @@ time = { version = "0.3", features = ["serde-human-readable"] } [dev-dependencies] assert-json-diff = "2.0" +proptest = "1" rstest = "0.18" [features] default = ["cloudevents"] +# provide cloudevents helpers and extensions cloudevents = ["dep:cloudevents-sdk"] +# provide test helpers (proptest'strategies and arbitraries for struct generation) +testkit = ["dep:proptest", "dep:proptest-derive"] diff --git a/cdevents-sdk/src/cdevent.rs b/cdevents-sdk/src/cdevent.rs index 258bff3..885da56 100644 --- a/cdevents-sdk/src/cdevent.rs +++ b/cdevents-sdk/src/cdevent.rs @@ -189,3 +189,40 @@ impl<'de> Deserialize<'de> for CDEvent { deserializer.deserialize_struct("CDEvent", FIELDS, CDEventVisitor) } } + +#[cfg(feature = "testkit")] +impl<> proptest::arbitrary::Arbitrary for CDEvent { + type Parameters = (); + type Strategy = proptest::strategy::BoxedStrategy; + + fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy { + use proptest::prelude::*; + ( + any::(), + "\\PC*", + any::>(), + ).prop_map(|(subject, id, source)| { + let mut cdevent = CDEvent::from(subject).with_id(id); + if let Some(source) = source { + cdevent = cdevent.with_source(source); + } + cdevent + }).boxed() + } +} + +#[cfg(test)] +mod tests { + use crate::CDEvent; + use proptest::prelude::*; + + proptest! { + #[test] + #[cfg(feature = "testkit")] + fn arbitraries_are_json_valid(s in any::()) { + let json_str = serde_json::to_string(&s).unwrap(); + let actual = serde_json::from_str::(&json_str).unwrap(); + assert_eq!(s, actual); + } + } +} \ No newline at end of file diff --git a/cdevents-sdk/src/generated/artifact_packaged.rs b/cdevents-sdk/src/generated/artifact_packaged.rs index 0466685..3900f77 100644 --- a/cdevents-sdk/src/generated/artifact_packaged.rs +++ b/cdevents-sdk/src/generated/artifact_packaged.rs @@ -1,9 +1,11 @@ // @generated // by cdevents/sdk-rust/generator (subject.hbs) +#[cfg(feature = "testkit")] use proptest_derive::Arbitrary; use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "change",)] @@ -11,6 +13,7 @@ pub struct Content { } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct ContentChange { #[serde(rename = "id",)] @@ -18,3 +21,19 @@ pub struct ContentChange { #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } + +#[cfg(test)] +mod tests { + use proptest::prelude::*; + use super::*; + + proptest! { + #[test] + #[cfg(feature = "testkit")] + fn arbitraries_are_json_valid(s in any::()) { + let json_str = serde_json::to_string(&s).unwrap(); + let actual = serde_json::from_str::(&json_str).unwrap(); + assert_eq!(s, actual); + } + } +} diff --git a/cdevents-sdk/src/generated/artifact_published.rs b/cdevents-sdk/src/generated/artifact_published.rs index 5aed7a4..c1162a8 100644 --- a/cdevents-sdk/src/generated/artifact_published.rs +++ b/cdevents-sdk/src/generated/artifact_published.rs @@ -1,9 +1,27 @@ // @generated // by cdevents/sdk-rust/generator (subject.hbs) +#[cfg(feature = "testkit")] use proptest_derive::Arbitrary; use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct Content { } + +#[cfg(test)] +mod tests { + use proptest::prelude::*; + use super::*; + + proptest! { + #[test] + #[cfg(feature = "testkit")] + fn arbitraries_are_json_valid(s in any::()) { + let json_str = serde_json::to_string(&s).unwrap(); + let actual = serde_json::from_str::(&json_str).unwrap(); + assert_eq!(s, actual); + } + } +} diff --git a/cdevents-sdk/src/generated/artifact_signed.rs b/cdevents-sdk/src/generated/artifact_signed.rs index 2026353..b7b700e 100644 --- a/cdevents-sdk/src/generated/artifact_signed.rs +++ b/cdevents-sdk/src/generated/artifact_signed.rs @@ -1,11 +1,29 @@ // @generated // by cdevents/sdk-rust/generator (subject.hbs) +#[cfg(feature = "testkit")] use proptest_derive::Arbitrary; use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "signature",)] pub signature: String, } + +#[cfg(test)] +mod tests { + use proptest::prelude::*; + use super::*; + + proptest! { + #[test] + #[cfg(feature = "testkit")] + fn arbitraries_are_json_valid(s in any::()) { + let json_str = serde_json::to_string(&s).unwrap(); + let actual = serde_json::from_str::(&json_str).unwrap(); + assert_eq!(s, actual); + } + } +} diff --git a/cdevents-sdk/src/generated/branch_created.rs b/cdevents-sdk/src/generated/branch_created.rs index 8576819..8c479f9 100644 --- a/cdevents-sdk/src/generated/branch_created.rs +++ b/cdevents-sdk/src/generated/branch_created.rs @@ -1,9 +1,11 @@ // @generated // by cdevents/sdk-rust/generator (subject.hbs) +#[cfg(feature = "testkit")] use proptest_derive::Arbitrary; use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "repository", default, skip_serializing_if = "Option::is_none",)] @@ -11,6 +13,7 @@ pub struct Content { } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct ContentRepository { #[serde(rename = "id",)] @@ -18,3 +21,19 @@ pub struct ContentRepository { #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } + +#[cfg(test)] +mod tests { + use proptest::prelude::*; + use super::*; + + proptest! { + #[test] + #[cfg(feature = "testkit")] + fn arbitraries_are_json_valid(s in any::()) { + let json_str = serde_json::to_string(&s).unwrap(); + let actual = serde_json::from_str::(&json_str).unwrap(); + assert_eq!(s, actual); + } + } +} diff --git a/cdevents-sdk/src/generated/branch_deleted.rs b/cdevents-sdk/src/generated/branch_deleted.rs index 8576819..8c479f9 100644 --- a/cdevents-sdk/src/generated/branch_deleted.rs +++ b/cdevents-sdk/src/generated/branch_deleted.rs @@ -1,9 +1,11 @@ // @generated // by cdevents/sdk-rust/generator (subject.hbs) +#[cfg(feature = "testkit")] use proptest_derive::Arbitrary; use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "repository", default, skip_serializing_if = "Option::is_none",)] @@ -11,6 +13,7 @@ pub struct Content { } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct ContentRepository { #[serde(rename = "id",)] @@ -18,3 +21,19 @@ pub struct ContentRepository { #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } + +#[cfg(test)] +mod tests { + use proptest::prelude::*; + use super::*; + + proptest! { + #[test] + #[cfg(feature = "testkit")] + fn arbitraries_are_json_valid(s in any::()) { + let json_str = serde_json::to_string(&s).unwrap(); + let actual = serde_json::from_str::(&json_str).unwrap(); + assert_eq!(s, actual); + } + } +} diff --git a/cdevents-sdk/src/generated/build_finished.rs b/cdevents-sdk/src/generated/build_finished.rs index caad769..ed7d960 100644 --- a/cdevents-sdk/src/generated/build_finished.rs +++ b/cdevents-sdk/src/generated/build_finished.rs @@ -1,11 +1,29 @@ // @generated // by cdevents/sdk-rust/generator (subject.hbs) +#[cfg(feature = "testkit")] use proptest_derive::Arbitrary; use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "artifactId", default, skip_serializing_if = "Option::is_none",)] pub artifact_id: Option, } + +#[cfg(test)] +mod tests { + use proptest::prelude::*; + use super::*; + + proptest! { + #[test] + #[cfg(feature = "testkit")] + fn arbitraries_are_json_valid(s in any::()) { + let json_str = serde_json::to_string(&s).unwrap(); + let actual = serde_json::from_str::(&json_str).unwrap(); + assert_eq!(s, actual); + } + } +} diff --git a/cdevents-sdk/src/generated/build_queued.rs b/cdevents-sdk/src/generated/build_queued.rs index 5aed7a4..c1162a8 100644 --- a/cdevents-sdk/src/generated/build_queued.rs +++ b/cdevents-sdk/src/generated/build_queued.rs @@ -1,9 +1,27 @@ // @generated // by cdevents/sdk-rust/generator (subject.hbs) +#[cfg(feature = "testkit")] use proptest_derive::Arbitrary; use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct Content { } + +#[cfg(test)] +mod tests { + use proptest::prelude::*; + use super::*; + + proptest! { + #[test] + #[cfg(feature = "testkit")] + fn arbitraries_are_json_valid(s in any::()) { + let json_str = serde_json::to_string(&s).unwrap(); + let actual = serde_json::from_str::(&json_str).unwrap(); + assert_eq!(s, actual); + } + } +} diff --git a/cdevents-sdk/src/generated/build_started.rs b/cdevents-sdk/src/generated/build_started.rs index 5aed7a4..c1162a8 100644 --- a/cdevents-sdk/src/generated/build_started.rs +++ b/cdevents-sdk/src/generated/build_started.rs @@ -1,9 +1,27 @@ // @generated // by cdevents/sdk-rust/generator (subject.hbs) +#[cfg(feature = "testkit")] use proptest_derive::Arbitrary; use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct Content { } + +#[cfg(test)] +mod tests { + use proptest::prelude::*; + use super::*; + + proptest! { + #[test] + #[cfg(feature = "testkit")] + fn arbitraries_are_json_valid(s in any::()) { + let json_str = serde_json::to_string(&s).unwrap(); + let actual = serde_json::from_str::(&json_str).unwrap(); + assert_eq!(s, actual); + } + } +} diff --git a/cdevents-sdk/src/generated/change_abandoned.rs b/cdevents-sdk/src/generated/change_abandoned.rs index 8576819..8c479f9 100644 --- a/cdevents-sdk/src/generated/change_abandoned.rs +++ b/cdevents-sdk/src/generated/change_abandoned.rs @@ -1,9 +1,11 @@ // @generated // by cdevents/sdk-rust/generator (subject.hbs) +#[cfg(feature = "testkit")] use proptest_derive::Arbitrary; use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "repository", default, skip_serializing_if = "Option::is_none",)] @@ -11,6 +13,7 @@ pub struct Content { } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct ContentRepository { #[serde(rename = "id",)] @@ -18,3 +21,19 @@ pub struct ContentRepository { #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } + +#[cfg(test)] +mod tests { + use proptest::prelude::*; + use super::*; + + proptest! { + #[test] + #[cfg(feature = "testkit")] + fn arbitraries_are_json_valid(s in any::()) { + let json_str = serde_json::to_string(&s).unwrap(); + let actual = serde_json::from_str::(&json_str).unwrap(); + assert_eq!(s, actual); + } + } +} diff --git a/cdevents-sdk/src/generated/change_created.rs b/cdevents-sdk/src/generated/change_created.rs index 8576819..8c479f9 100644 --- a/cdevents-sdk/src/generated/change_created.rs +++ b/cdevents-sdk/src/generated/change_created.rs @@ -1,9 +1,11 @@ // @generated // by cdevents/sdk-rust/generator (subject.hbs) +#[cfg(feature = "testkit")] use proptest_derive::Arbitrary; use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "repository", default, skip_serializing_if = "Option::is_none",)] @@ -11,6 +13,7 @@ pub struct Content { } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct ContentRepository { #[serde(rename = "id",)] @@ -18,3 +21,19 @@ pub struct ContentRepository { #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } + +#[cfg(test)] +mod tests { + use proptest::prelude::*; + use super::*; + + proptest! { + #[test] + #[cfg(feature = "testkit")] + fn arbitraries_are_json_valid(s in any::()) { + let json_str = serde_json::to_string(&s).unwrap(); + let actual = serde_json::from_str::(&json_str).unwrap(); + assert_eq!(s, actual); + } + } +} diff --git a/cdevents-sdk/src/generated/change_merged.rs b/cdevents-sdk/src/generated/change_merged.rs index 8576819..8c479f9 100644 --- a/cdevents-sdk/src/generated/change_merged.rs +++ b/cdevents-sdk/src/generated/change_merged.rs @@ -1,9 +1,11 @@ // @generated // by cdevents/sdk-rust/generator (subject.hbs) +#[cfg(feature = "testkit")] use proptest_derive::Arbitrary; use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "repository", default, skip_serializing_if = "Option::is_none",)] @@ -11,6 +13,7 @@ pub struct Content { } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct ContentRepository { #[serde(rename = "id",)] @@ -18,3 +21,19 @@ pub struct ContentRepository { #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } + +#[cfg(test)] +mod tests { + use proptest::prelude::*; + use super::*; + + proptest! { + #[test] + #[cfg(feature = "testkit")] + fn arbitraries_are_json_valid(s in any::()) { + let json_str = serde_json::to_string(&s).unwrap(); + let actual = serde_json::from_str::(&json_str).unwrap(); + assert_eq!(s, actual); + } + } +} diff --git a/cdevents-sdk/src/generated/change_reviewed.rs b/cdevents-sdk/src/generated/change_reviewed.rs index 8576819..8c479f9 100644 --- a/cdevents-sdk/src/generated/change_reviewed.rs +++ b/cdevents-sdk/src/generated/change_reviewed.rs @@ -1,9 +1,11 @@ // @generated // by cdevents/sdk-rust/generator (subject.hbs) +#[cfg(feature = "testkit")] use proptest_derive::Arbitrary; use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "repository", default, skip_serializing_if = "Option::is_none",)] @@ -11,6 +13,7 @@ pub struct Content { } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct ContentRepository { #[serde(rename = "id",)] @@ -18,3 +21,19 @@ pub struct ContentRepository { #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } + +#[cfg(test)] +mod tests { + use proptest::prelude::*; + use super::*; + + proptest! { + #[test] + #[cfg(feature = "testkit")] + fn arbitraries_are_json_valid(s in any::()) { + let json_str = serde_json::to_string(&s).unwrap(); + let actual = serde_json::from_str::(&json_str).unwrap(); + assert_eq!(s, actual); + } + } +} diff --git a/cdevents-sdk/src/generated/change_updated.rs b/cdevents-sdk/src/generated/change_updated.rs index 8576819..8c479f9 100644 --- a/cdevents-sdk/src/generated/change_updated.rs +++ b/cdevents-sdk/src/generated/change_updated.rs @@ -1,9 +1,11 @@ // @generated // by cdevents/sdk-rust/generator (subject.hbs) +#[cfg(feature = "testkit")] use proptest_derive::Arbitrary; use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "repository", default, skip_serializing_if = "Option::is_none",)] @@ -11,6 +13,7 @@ pub struct Content { } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct ContentRepository { #[serde(rename = "id",)] @@ -18,3 +21,19 @@ pub struct ContentRepository { #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } + +#[cfg(test)] +mod tests { + use proptest::prelude::*; + use super::*; + + proptest! { + #[test] + #[cfg(feature = "testkit")] + fn arbitraries_are_json_valid(s in any::()) { + let json_str = serde_json::to_string(&s).unwrap(); + let actual = serde_json::from_str::(&json_str).unwrap(); + assert_eq!(s, actual); + } + } +} diff --git a/cdevents-sdk/src/generated/environment_created.rs b/cdevents-sdk/src/generated/environment_created.rs index 1ac2d85..804f4be 100644 --- a/cdevents-sdk/src/generated/environment_created.rs +++ b/cdevents-sdk/src/generated/environment_created.rs @@ -1,9 +1,11 @@ // @generated // by cdevents/sdk-rust/generator (subject.hbs) +#[cfg(feature = "testkit")] use proptest_derive::Arbitrary; use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "name", default, skip_serializing_if = "Option::is_none",)] @@ -11,3 +13,19 @@ pub struct Content { #[serde(rename = "url", default, skip_serializing_if = "Option::is_none",)] pub url: Option, } + +#[cfg(test)] +mod tests { + use proptest::prelude::*; + use super::*; + + proptest! { + #[test] + #[cfg(feature = "testkit")] + fn arbitraries_are_json_valid(s in any::()) { + let json_str = serde_json::to_string(&s).unwrap(); + let actual = serde_json::from_str::(&json_str).unwrap(); + assert_eq!(s, actual); + } + } +} diff --git a/cdevents-sdk/src/generated/environment_deleted.rs b/cdevents-sdk/src/generated/environment_deleted.rs index c21a2fa..a10c7d6 100644 --- a/cdevents-sdk/src/generated/environment_deleted.rs +++ b/cdevents-sdk/src/generated/environment_deleted.rs @@ -1,11 +1,29 @@ // @generated // by cdevents/sdk-rust/generator (subject.hbs) +#[cfg(feature = "testkit")] use proptest_derive::Arbitrary; use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "name", default, skip_serializing_if = "Option::is_none",)] pub name: Option, } + +#[cfg(test)] +mod tests { + use proptest::prelude::*; + use super::*; + + proptest! { + #[test] + #[cfg(feature = "testkit")] + fn arbitraries_are_json_valid(s in any::()) { + let json_str = serde_json::to_string(&s).unwrap(); + let actual = serde_json::from_str::(&json_str).unwrap(); + assert_eq!(s, actual); + } + } +} diff --git a/cdevents-sdk/src/generated/environment_modified.rs b/cdevents-sdk/src/generated/environment_modified.rs index 1ac2d85..804f4be 100644 --- a/cdevents-sdk/src/generated/environment_modified.rs +++ b/cdevents-sdk/src/generated/environment_modified.rs @@ -1,9 +1,11 @@ // @generated // by cdevents/sdk-rust/generator (subject.hbs) +#[cfg(feature = "testkit")] use proptest_derive::Arbitrary; use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "name", default, skip_serializing_if = "Option::is_none",)] @@ -11,3 +13,19 @@ pub struct Content { #[serde(rename = "url", default, skip_serializing_if = "Option::is_none",)] pub url: Option, } + +#[cfg(test)] +mod tests { + use proptest::prelude::*; + use super::*; + + proptest! { + #[test] + #[cfg(feature = "testkit")] + fn arbitraries_are_json_valid(s in any::()) { + let json_str = serde_json::to_string(&s).unwrap(); + let actual = serde_json::from_str::(&json_str).unwrap(); + assert_eq!(s, actual); + } + } +} diff --git a/cdevents-sdk/src/generated/incident_detected.rs b/cdevents-sdk/src/generated/incident_detected.rs index 5a91da9..6d0c62a 100644 --- a/cdevents-sdk/src/generated/incident_detected.rs +++ b/cdevents-sdk/src/generated/incident_detected.rs @@ -1,9 +1,11 @@ // @generated // by cdevents/sdk-rust/generator (subject.hbs) +#[cfg(feature = "testkit")] use proptest_derive::Arbitrary; use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "artifactId", default, skip_serializing_if = "Option::is_none",)] @@ -17,6 +19,7 @@ pub struct Content { } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct ContentService { #[serde(rename = "id",)] @@ -26,6 +29,7 @@ pub struct ContentService { } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct ContentEnvironment { #[serde(rename = "id",)] @@ -33,3 +37,19 @@ pub struct ContentEnvironment { #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } + +#[cfg(test)] +mod tests { + use proptest::prelude::*; + use super::*; + + proptest! { + #[test] + #[cfg(feature = "testkit")] + fn arbitraries_are_json_valid(s in any::()) { + let json_str = serde_json::to_string(&s).unwrap(); + let actual = serde_json::from_str::(&json_str).unwrap(); + assert_eq!(s, actual); + } + } +} diff --git a/cdevents-sdk/src/generated/incident_reported.rs b/cdevents-sdk/src/generated/incident_reported.rs index ec30ed6..ee90dae 100644 --- a/cdevents-sdk/src/generated/incident_reported.rs +++ b/cdevents-sdk/src/generated/incident_reported.rs @@ -1,9 +1,11 @@ // @generated // by cdevents/sdk-rust/generator (subject.hbs) +#[cfg(feature = "testkit")] use proptest_derive::Arbitrary; use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "artifactId", default, skip_serializing_if = "Option::is_none",)] @@ -19,6 +21,7 @@ pub struct Content { } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct ContentService { #[serde(rename = "id",)] @@ -28,6 +31,7 @@ pub struct ContentService { } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct ContentEnvironment { #[serde(rename = "id",)] @@ -35,3 +39,19 @@ pub struct ContentEnvironment { #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } + +#[cfg(test)] +mod tests { + use proptest::prelude::*; + use super::*; + + proptest! { + #[test] + #[cfg(feature = "testkit")] + fn arbitraries_are_json_valid(s in any::()) { + let json_str = serde_json::to_string(&s).unwrap(); + let actual = serde_json::from_str::(&json_str).unwrap(); + assert_eq!(s, actual); + } + } +} diff --git a/cdevents-sdk/src/generated/incident_resolved.rs b/cdevents-sdk/src/generated/incident_resolved.rs index 5a91da9..6d0c62a 100644 --- a/cdevents-sdk/src/generated/incident_resolved.rs +++ b/cdevents-sdk/src/generated/incident_resolved.rs @@ -1,9 +1,11 @@ // @generated // by cdevents/sdk-rust/generator (subject.hbs) +#[cfg(feature = "testkit")] use proptest_derive::Arbitrary; use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "artifactId", default, skip_serializing_if = "Option::is_none",)] @@ -17,6 +19,7 @@ pub struct Content { } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct ContentService { #[serde(rename = "id",)] @@ -26,6 +29,7 @@ pub struct ContentService { } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct ContentEnvironment { #[serde(rename = "id",)] @@ -33,3 +37,19 @@ pub struct ContentEnvironment { #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } + +#[cfg(test)] +mod tests { + use proptest::prelude::*; + use super::*; + + proptest! { + #[test] + #[cfg(feature = "testkit")] + fn arbitraries_are_json_valid(s in any::()) { + let json_str = serde_json::to_string(&s).unwrap(); + let actual = serde_json::from_str::(&json_str).unwrap(); + assert_eq!(s, actual); + } + } +} diff --git a/cdevents-sdk/src/generated/mod.rs b/cdevents-sdk/src/generated/mod.rs index 0cd19d9..c64f14e 100644 --- a/cdevents-sdk/src/generated/mod.rs +++ b/cdevents-sdk/src/generated/mod.rs @@ -544,3 +544,54 @@ impl From for Content { Self::TestsuiterunStarted(value) } } + +#[cfg(feature = "testkit")] +impl<> proptest::arbitrary::Arbitrary for Content { + type Parameters = (); + type Strategy = proptest::strategy::BoxedStrategy; + + fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy { + use proptest::prelude::*; + prop_oneof![ + any::().prop_map(Content::from), + any::().prop_map(Content::from), + any::().prop_map(Content::from), + any::().prop_map(Content::from), + any::().prop_map(Content::from), + any::().prop_map(Content::from), + any::().prop_map(Content::from), + any::().prop_map(Content::from), + any::().prop_map(Content::from), + any::().prop_map(Content::from), + any::().prop_map(Content::from), + any::().prop_map(Content::from), + any::().prop_map(Content::from), + any::().prop_map(Content::from), + any::().prop_map(Content::from), + any::().prop_map(Content::from), + any::().prop_map(Content::from), + any::().prop_map(Content::from), + any::().prop_map(Content::from), + any::().prop_map(Content::from), + any::().prop_map(Content::from), + any::().prop_map(Content::from), + any::().prop_map(Content::from), + any::().prop_map(Content::from), + any::().prop_map(Content::from), + any::().prop_map(Content::from), + any::().prop_map(Content::from), + any::().prop_map(Content::from), + any::().prop_map(Content::from), + any::().prop_map(Content::from), + any::().prop_map(Content::from), + any::().prop_map(Content::from), + any::().prop_map(Content::from), + any::().prop_map(Content::from), + any::().prop_map(Content::from), + any::().prop_map(Content::from), + any::().prop_map(Content::from), + any::().prop_map(Content::from), + any::().prop_map(Content::from), + ].boxed() + } +} diff --git a/cdevents-sdk/src/generated/pipelinerun_finished.rs b/cdevents-sdk/src/generated/pipelinerun_finished.rs index bbad121..7839d5e 100644 --- a/cdevents-sdk/src/generated/pipelinerun_finished.rs +++ b/cdevents-sdk/src/generated/pipelinerun_finished.rs @@ -1,9 +1,11 @@ // @generated // by cdevents/sdk-rust/generator (subject.hbs) +#[cfg(feature = "testkit")] use proptest_derive::Arbitrary; use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "errors", default, skip_serializing_if = "Option::is_none",)] @@ -15,3 +17,19 @@ pub struct Content { #[serde(rename = "url", default, skip_serializing_if = "Option::is_none",)] pub url: Option, } + +#[cfg(test)] +mod tests { + use proptest::prelude::*; + use super::*; + + proptest! { + #[test] + #[cfg(feature = "testkit")] + fn arbitraries_are_json_valid(s in any::()) { + let json_str = serde_json::to_string(&s).unwrap(); + let actual = serde_json::from_str::(&json_str).unwrap(); + assert_eq!(s, actual); + } + } +} diff --git a/cdevents-sdk/src/generated/pipelinerun_queued.rs b/cdevents-sdk/src/generated/pipelinerun_queued.rs index 45a82fc..5f42f00 100644 --- a/cdevents-sdk/src/generated/pipelinerun_queued.rs +++ b/cdevents-sdk/src/generated/pipelinerun_queued.rs @@ -1,9 +1,11 @@ // @generated // by cdevents/sdk-rust/generator (subject.hbs) +#[cfg(feature = "testkit")] use proptest_derive::Arbitrary; use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "pipelineName", default, skip_serializing_if = "Option::is_none",)] @@ -11,3 +13,19 @@ pub struct Content { #[serde(rename = "url", default, skip_serializing_if = "Option::is_none",)] pub url: Option, } + +#[cfg(test)] +mod tests { + use proptest::prelude::*; + use super::*; + + proptest! { + #[test] + #[cfg(feature = "testkit")] + fn arbitraries_are_json_valid(s in any::()) { + let json_str = serde_json::to_string(&s).unwrap(); + let actual = serde_json::from_str::(&json_str).unwrap(); + assert_eq!(s, actual); + } + } +} diff --git a/cdevents-sdk/src/generated/pipelinerun_started.rs b/cdevents-sdk/src/generated/pipelinerun_started.rs index d69896d..3270b0a 100644 --- a/cdevents-sdk/src/generated/pipelinerun_started.rs +++ b/cdevents-sdk/src/generated/pipelinerun_started.rs @@ -1,9 +1,11 @@ // @generated // by cdevents/sdk-rust/generator (subject.hbs) +#[cfg(feature = "testkit")] use proptest_derive::Arbitrary; use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "pipelineName",)] @@ -11,3 +13,19 @@ pub struct Content { #[serde(rename = "url",)] pub url: String, } + +#[cfg(test)] +mod tests { + use proptest::prelude::*; + use super::*; + + proptest! { + #[test] + #[cfg(feature = "testkit")] + fn arbitraries_are_json_valid(s in any::()) { + let json_str = serde_json::to_string(&s).unwrap(); + let actual = serde_json::from_str::(&json_str).unwrap(); + assert_eq!(s, actual); + } + } +} diff --git a/cdevents-sdk/src/generated/repository_created.rs b/cdevents-sdk/src/generated/repository_created.rs index 5523ece..7f2ed30 100644 --- a/cdevents-sdk/src/generated/repository_created.rs +++ b/cdevents-sdk/src/generated/repository_created.rs @@ -1,9 +1,11 @@ // @generated // by cdevents/sdk-rust/generator (subject.hbs) +#[cfg(feature = "testkit")] use proptest_derive::Arbitrary; use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "name",)] @@ -15,3 +17,19 @@ pub struct Content { #[serde(rename = "viewUrl", default, skip_serializing_if = "Option::is_none",)] pub view_url: Option, } + +#[cfg(test)] +mod tests { + use proptest::prelude::*; + use super::*; + + proptest! { + #[test] + #[cfg(feature = "testkit")] + fn arbitraries_are_json_valid(s in any::()) { + let json_str = serde_json::to_string(&s).unwrap(); + let actual = serde_json::from_str::(&json_str).unwrap(); + assert_eq!(s, actual); + } + } +} diff --git a/cdevents-sdk/src/generated/repository_deleted.rs b/cdevents-sdk/src/generated/repository_deleted.rs index e02fea0..0fa5c4d 100644 --- a/cdevents-sdk/src/generated/repository_deleted.rs +++ b/cdevents-sdk/src/generated/repository_deleted.rs @@ -1,9 +1,11 @@ // @generated // by cdevents/sdk-rust/generator (subject.hbs) +#[cfg(feature = "testkit")] use proptest_derive::Arbitrary; use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "name", default, skip_serializing_if = "Option::is_none",)] @@ -15,3 +17,19 @@ pub struct Content { #[serde(rename = "viewUrl", default, skip_serializing_if = "Option::is_none",)] pub view_url: Option, } + +#[cfg(test)] +mod tests { + use proptest::prelude::*; + use super::*; + + proptest! { + #[test] + #[cfg(feature = "testkit")] + fn arbitraries_are_json_valid(s in any::()) { + let json_str = serde_json::to_string(&s).unwrap(); + let actual = serde_json::from_str::(&json_str).unwrap(); + assert_eq!(s, actual); + } + } +} diff --git a/cdevents-sdk/src/generated/repository_modified.rs b/cdevents-sdk/src/generated/repository_modified.rs index e02fea0..0fa5c4d 100644 --- a/cdevents-sdk/src/generated/repository_modified.rs +++ b/cdevents-sdk/src/generated/repository_modified.rs @@ -1,9 +1,11 @@ // @generated // by cdevents/sdk-rust/generator (subject.hbs) +#[cfg(feature = "testkit")] use proptest_derive::Arbitrary; use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "name", default, skip_serializing_if = "Option::is_none",)] @@ -15,3 +17,19 @@ pub struct Content { #[serde(rename = "viewUrl", default, skip_serializing_if = "Option::is_none",)] pub view_url: Option, } + +#[cfg(test)] +mod tests { + use proptest::prelude::*; + use super::*; + + proptest! { + #[test] + #[cfg(feature = "testkit")] + fn arbitraries_are_json_valid(s in any::()) { + let json_str = serde_json::to_string(&s).unwrap(); + let actual = serde_json::from_str::(&json_str).unwrap(); + assert_eq!(s, actual); + } + } +} diff --git a/cdevents-sdk/src/generated/service_deployed.rs b/cdevents-sdk/src/generated/service_deployed.rs index 0f6dc2c..1499d5c 100644 --- a/cdevents-sdk/src/generated/service_deployed.rs +++ b/cdevents-sdk/src/generated/service_deployed.rs @@ -1,9 +1,11 @@ // @generated // by cdevents/sdk-rust/generator (subject.hbs) +#[cfg(feature = "testkit")] use proptest_derive::Arbitrary; use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "artifactId",)] @@ -13,6 +15,7 @@ pub struct Content { } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct ContentEnvironment { #[serde(rename = "id",)] @@ -20,3 +23,19 @@ pub struct ContentEnvironment { #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } + +#[cfg(test)] +mod tests { + use proptest::prelude::*; + use super::*; + + proptest! { + #[test] + #[cfg(feature = "testkit")] + fn arbitraries_are_json_valid(s in any::()) { + let json_str = serde_json::to_string(&s).unwrap(); + let actual = serde_json::from_str::(&json_str).unwrap(); + assert_eq!(s, actual); + } + } +} diff --git a/cdevents-sdk/src/generated/service_published.rs b/cdevents-sdk/src/generated/service_published.rs index 02e23c7..2740c04 100644 --- a/cdevents-sdk/src/generated/service_published.rs +++ b/cdevents-sdk/src/generated/service_published.rs @@ -1,9 +1,11 @@ // @generated // by cdevents/sdk-rust/generator (subject.hbs) +#[cfg(feature = "testkit")] use proptest_derive::Arbitrary; use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "environment", default, skip_serializing_if = "Option::is_none",)] @@ -11,6 +13,7 @@ pub struct Content { } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct ContentEnvironment { #[serde(rename = "id",)] @@ -18,3 +21,19 @@ pub struct ContentEnvironment { #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } + +#[cfg(test)] +mod tests { + use proptest::prelude::*; + use super::*; + + proptest! { + #[test] + #[cfg(feature = "testkit")] + fn arbitraries_are_json_valid(s in any::()) { + let json_str = serde_json::to_string(&s).unwrap(); + let actual = serde_json::from_str::(&json_str).unwrap(); + assert_eq!(s, actual); + } + } +} diff --git a/cdevents-sdk/src/generated/service_removed.rs b/cdevents-sdk/src/generated/service_removed.rs index 02e23c7..2740c04 100644 --- a/cdevents-sdk/src/generated/service_removed.rs +++ b/cdevents-sdk/src/generated/service_removed.rs @@ -1,9 +1,11 @@ // @generated // by cdevents/sdk-rust/generator (subject.hbs) +#[cfg(feature = "testkit")] use proptest_derive::Arbitrary; use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "environment", default, skip_serializing_if = "Option::is_none",)] @@ -11,6 +13,7 @@ pub struct Content { } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct ContentEnvironment { #[serde(rename = "id",)] @@ -18,3 +21,19 @@ pub struct ContentEnvironment { #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } + +#[cfg(test)] +mod tests { + use proptest::prelude::*; + use super::*; + + proptest! { + #[test] + #[cfg(feature = "testkit")] + fn arbitraries_are_json_valid(s in any::()) { + let json_str = serde_json::to_string(&s).unwrap(); + let actual = serde_json::from_str::(&json_str).unwrap(); + assert_eq!(s, actual); + } + } +} diff --git a/cdevents-sdk/src/generated/service_rolledback.rs b/cdevents-sdk/src/generated/service_rolledback.rs index 0f6dc2c..1499d5c 100644 --- a/cdevents-sdk/src/generated/service_rolledback.rs +++ b/cdevents-sdk/src/generated/service_rolledback.rs @@ -1,9 +1,11 @@ // @generated // by cdevents/sdk-rust/generator (subject.hbs) +#[cfg(feature = "testkit")] use proptest_derive::Arbitrary; use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "artifactId",)] @@ -13,6 +15,7 @@ pub struct Content { } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct ContentEnvironment { #[serde(rename = "id",)] @@ -20,3 +23,19 @@ pub struct ContentEnvironment { #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } + +#[cfg(test)] +mod tests { + use proptest::prelude::*; + use super::*; + + proptest! { + #[test] + #[cfg(feature = "testkit")] + fn arbitraries_are_json_valid(s in any::()) { + let json_str = serde_json::to_string(&s).unwrap(); + let actual = serde_json::from_str::(&json_str).unwrap(); + assert_eq!(s, actual); + } + } +} diff --git a/cdevents-sdk/src/generated/service_upgraded.rs b/cdevents-sdk/src/generated/service_upgraded.rs index 0f6dc2c..1499d5c 100644 --- a/cdevents-sdk/src/generated/service_upgraded.rs +++ b/cdevents-sdk/src/generated/service_upgraded.rs @@ -1,9 +1,11 @@ // @generated // by cdevents/sdk-rust/generator (subject.hbs) +#[cfg(feature = "testkit")] use proptest_derive::Arbitrary; use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "artifactId",)] @@ -13,6 +15,7 @@ pub struct Content { } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct ContentEnvironment { #[serde(rename = "id",)] @@ -20,3 +23,19 @@ pub struct ContentEnvironment { #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } + +#[cfg(test)] +mod tests { + use proptest::prelude::*; + use super::*; + + proptest! { + #[test] + #[cfg(feature = "testkit")] + fn arbitraries_are_json_valid(s in any::()) { + let json_str = serde_json::to_string(&s).unwrap(); + let actual = serde_json::from_str::(&json_str).unwrap(); + assert_eq!(s, actual); + } + } +} diff --git a/cdevents-sdk/src/generated/taskrun_finished.rs b/cdevents-sdk/src/generated/taskrun_finished.rs index 27b4338..8603566 100644 --- a/cdevents-sdk/src/generated/taskrun_finished.rs +++ b/cdevents-sdk/src/generated/taskrun_finished.rs @@ -1,9 +1,11 @@ // @generated // by cdevents/sdk-rust/generator (subject.hbs) +#[cfg(feature = "testkit")] use proptest_derive::Arbitrary; use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "errors", default, skip_serializing_if = "Option::is_none",)] @@ -19,6 +21,7 @@ pub struct Content { } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct ContentPipelineRun { #[serde(rename = "id",)] @@ -26,3 +29,19 @@ pub struct ContentPipelineRun { #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } + +#[cfg(test)] +mod tests { + use proptest::prelude::*; + use super::*; + + proptest! { + #[test] + #[cfg(feature = "testkit")] + fn arbitraries_are_json_valid(s in any::()) { + let json_str = serde_json::to_string(&s).unwrap(); + let actual = serde_json::from_str::(&json_str).unwrap(); + assert_eq!(s, actual); + } + } +} diff --git a/cdevents-sdk/src/generated/taskrun_started.rs b/cdevents-sdk/src/generated/taskrun_started.rs index 13cba66..3edb228 100644 --- a/cdevents-sdk/src/generated/taskrun_started.rs +++ b/cdevents-sdk/src/generated/taskrun_started.rs @@ -1,9 +1,11 @@ // @generated // by cdevents/sdk-rust/generator (subject.hbs) +#[cfg(feature = "testkit")] use proptest_derive::Arbitrary; use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "pipelineRun", default, skip_serializing_if = "Option::is_none",)] @@ -15,6 +17,7 @@ pub struct Content { } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct ContentPipelineRun { #[serde(rename = "id",)] @@ -22,3 +25,19 @@ pub struct ContentPipelineRun { #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } + +#[cfg(test)] +mod tests { + use proptest::prelude::*; + use super::*; + + proptest! { + #[test] + #[cfg(feature = "testkit")] + fn arbitraries_are_json_valid(s in any::()) { + let json_str = serde_json::to_string(&s).unwrap(); + let actual = serde_json::from_str::(&json_str).unwrap(); + assert_eq!(s, actual); + } + } +} diff --git a/cdevents-sdk/src/generated/testcaserun_finished.rs b/cdevents-sdk/src/generated/testcaserun_finished.rs index 46656e1..6d2051b 100644 --- a/cdevents-sdk/src/generated/testcaserun_finished.rs +++ b/cdevents-sdk/src/generated/testcaserun_finished.rs @@ -1,9 +1,11 @@ // @generated // by cdevents/sdk-rust/generator (subject.hbs) +#[cfg(feature = "testkit")] use proptest_derive::Arbitrary; use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "environment",)] @@ -21,6 +23,7 @@ pub struct Content { } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct ContentTestSuiteRun { #[serde(rename = "id",)] @@ -30,6 +33,7 @@ pub struct ContentTestSuiteRun { } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct ContentTestCase { #[serde(rename = "id",)] @@ -45,6 +49,7 @@ pub struct ContentTestCase { } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct ContentEnvironment { #[serde(rename = "id",)] @@ -54,6 +59,7 @@ pub struct ContentEnvironment { } #[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] pub enum ContentOutcome { #[serde(rename = "pass")] Pass, @@ -66,6 +72,7 @@ pub enum ContentOutcome { } #[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] pub enum ContentSeverity { #[serde(rename = "low")] Low, @@ -78,6 +85,7 @@ pub enum ContentSeverity { } #[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] pub enum ContentTestCaseType { #[serde(rename = "performance")] Performance, @@ -96,3 +104,19 @@ pub enum ContentTestCaseType { #[serde(rename = "other")] Other, } + +#[cfg(test)] +mod tests { + use proptest::prelude::*; + use super::*; + + proptest! { + #[test] + #[cfg(feature = "testkit")] + fn arbitraries_are_json_valid(s in any::()) { + let json_str = serde_json::to_string(&s).unwrap(); + let actual = serde_json::from_str::(&json_str).unwrap(); + assert_eq!(s, actual); + } + } +} diff --git a/cdevents-sdk/src/generated/testcaserun_queued.rs b/cdevents-sdk/src/generated/testcaserun_queued.rs index 1c65fdb..c42dfb2 100644 --- a/cdevents-sdk/src/generated/testcaserun_queued.rs +++ b/cdevents-sdk/src/generated/testcaserun_queued.rs @@ -1,9 +1,11 @@ // @generated // by cdevents/sdk-rust/generator (subject.hbs) +#[cfg(feature = "testkit")] use proptest_derive::Arbitrary; use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "environment",)] @@ -17,6 +19,7 @@ pub struct Content { } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct ContentTrigger { #[serde(rename = "type", default, skip_serializing_if = "Option::is_none",)] @@ -26,6 +29,7 @@ pub struct ContentTrigger { } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct ContentTestSuiteRun { #[serde(rename = "id",)] @@ -35,6 +39,7 @@ pub struct ContentTestSuiteRun { } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct ContentTestCase { #[serde(rename = "id",)] @@ -50,6 +55,7 @@ pub struct ContentTestCase { } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct ContentEnvironment { #[serde(rename = "id",)] @@ -59,6 +65,7 @@ pub struct ContentEnvironment { } #[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] pub enum ContentTestCaseType { #[serde(rename = "performance")] Performance, @@ -79,6 +86,7 @@ pub enum ContentTestCaseType { } #[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] pub enum ContentTriggerType { #[serde(rename = "manual")] Manual, @@ -91,3 +99,19 @@ pub enum ContentTriggerType { #[serde(rename = "other")] Other, } + +#[cfg(test)] +mod tests { + use proptest::prelude::*; + use super::*; + + proptest! { + #[test] + #[cfg(feature = "testkit")] + fn arbitraries_are_json_valid(s in any::()) { + let json_str = serde_json::to_string(&s).unwrap(); + let actual = serde_json::from_str::(&json_str).unwrap(); + assert_eq!(s, actual); + } + } +} diff --git a/cdevents-sdk/src/generated/testcaserun_started.rs b/cdevents-sdk/src/generated/testcaserun_started.rs index 1c65fdb..c42dfb2 100644 --- a/cdevents-sdk/src/generated/testcaserun_started.rs +++ b/cdevents-sdk/src/generated/testcaserun_started.rs @@ -1,9 +1,11 @@ // @generated // by cdevents/sdk-rust/generator (subject.hbs) +#[cfg(feature = "testkit")] use proptest_derive::Arbitrary; use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "environment",)] @@ -17,6 +19,7 @@ pub struct Content { } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct ContentTrigger { #[serde(rename = "type", default, skip_serializing_if = "Option::is_none",)] @@ -26,6 +29,7 @@ pub struct ContentTrigger { } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct ContentTestSuiteRun { #[serde(rename = "id",)] @@ -35,6 +39,7 @@ pub struct ContentTestSuiteRun { } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct ContentTestCase { #[serde(rename = "id",)] @@ -50,6 +55,7 @@ pub struct ContentTestCase { } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct ContentEnvironment { #[serde(rename = "id",)] @@ -59,6 +65,7 @@ pub struct ContentEnvironment { } #[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] pub enum ContentTestCaseType { #[serde(rename = "performance")] Performance, @@ -79,6 +86,7 @@ pub enum ContentTestCaseType { } #[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] pub enum ContentTriggerType { #[serde(rename = "manual")] Manual, @@ -91,3 +99,19 @@ pub enum ContentTriggerType { #[serde(rename = "other")] Other, } + +#[cfg(test)] +mod tests { + use proptest::prelude::*; + use super::*; + + proptest! { + #[test] + #[cfg(feature = "testkit")] + fn arbitraries_are_json_valid(s in any::()) { + let json_str = serde_json::to_string(&s).unwrap(); + let actual = serde_json::from_str::(&json_str).unwrap(); + assert_eq!(s, actual); + } + } +} diff --git a/cdevents-sdk/src/generated/testoutput_published.rs b/cdevents-sdk/src/generated/testoutput_published.rs index e673427..675acbc 100644 --- a/cdevents-sdk/src/generated/testoutput_published.rs +++ b/cdevents-sdk/src/generated/testoutput_published.rs @@ -1,9 +1,11 @@ // @generated // by cdevents/sdk-rust/generator (subject.hbs) +#[cfg(feature = "testkit")] use proptest_derive::Arbitrary; use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "format",)] @@ -17,6 +19,7 @@ pub struct Content { } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct ContentTestCaseRun { #[serde(rename = "id",)] @@ -26,6 +29,7 @@ pub struct ContentTestCaseRun { } #[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] pub enum ContentOutputType { #[serde(rename = "report")] Report, @@ -38,3 +42,19 @@ pub enum ContentOutputType { #[serde(rename = "other")] Other, } + +#[cfg(test)] +mod tests { + use proptest::prelude::*; + use super::*; + + proptest! { + #[test] + #[cfg(feature = "testkit")] + fn arbitraries_are_json_valid(s in any::()) { + let json_str = serde_json::to_string(&s).unwrap(); + let actual = serde_json::from_str::(&json_str).unwrap(); + assert_eq!(s, actual); + } + } +} diff --git a/cdevents-sdk/src/generated/testsuiterun_finished.rs b/cdevents-sdk/src/generated/testsuiterun_finished.rs index 40496ef..a59e593 100644 --- a/cdevents-sdk/src/generated/testsuiterun_finished.rs +++ b/cdevents-sdk/src/generated/testsuiterun_finished.rs @@ -1,9 +1,11 @@ // @generated // by cdevents/sdk-rust/generator (subject.hbs) +#[cfg(feature = "testkit")] use proptest_derive::Arbitrary; use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "environment",)] @@ -19,6 +21,7 @@ pub struct Content { } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct ContentTestSuite { #[serde(rename = "id",)] @@ -32,6 +35,7 @@ pub struct ContentTestSuite { } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct ContentEnvironment { #[serde(rename = "id",)] @@ -41,6 +45,7 @@ pub struct ContentEnvironment { } #[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] pub enum ContentOutcome { #[serde(rename = "pass")] Pass, @@ -53,6 +58,7 @@ pub enum ContentOutcome { } #[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] pub enum ContentSeverity { #[serde(rename = "low")] Low, @@ -63,3 +69,19 @@ pub enum ContentSeverity { #[serde(rename = "critical")] Critical, } + +#[cfg(test)] +mod tests { + use proptest::prelude::*; + use super::*; + + proptest! { + #[test] + #[cfg(feature = "testkit")] + fn arbitraries_are_json_valid(s in any::()) { + let json_str = serde_json::to_string(&s).unwrap(); + let actual = serde_json::from_str::(&json_str).unwrap(); + assert_eq!(s, actual); + } + } +} diff --git a/cdevents-sdk/src/generated/testsuiterun_queued.rs b/cdevents-sdk/src/generated/testsuiterun_queued.rs index 1b2e244..5fc5ac1 100644 --- a/cdevents-sdk/src/generated/testsuiterun_queued.rs +++ b/cdevents-sdk/src/generated/testsuiterun_queued.rs @@ -1,9 +1,11 @@ // @generated // by cdevents/sdk-rust/generator (subject.hbs) +#[cfg(feature = "testkit")] use proptest_derive::Arbitrary; use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "environment",)] @@ -15,6 +17,7 @@ pub struct Content { } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct ContentTrigger { #[serde(rename = "type", default, skip_serializing_if = "Option::is_none",)] @@ -24,6 +27,7 @@ pub struct ContentTrigger { } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct ContentTestSuite { #[serde(rename = "id",)] @@ -37,6 +41,7 @@ pub struct ContentTestSuite { } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct ContentEnvironment { #[serde(rename = "id",)] @@ -46,6 +51,7 @@ pub struct ContentEnvironment { } #[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] pub enum ContentTriggerType { #[serde(rename = "manual")] Manual, @@ -58,3 +64,19 @@ pub enum ContentTriggerType { #[serde(rename = "other")] Other, } + +#[cfg(test)] +mod tests { + use proptest::prelude::*; + use super::*; + + proptest! { + #[test] + #[cfg(feature = "testkit")] + fn arbitraries_are_json_valid(s in any::()) { + let json_str = serde_json::to_string(&s).unwrap(); + let actual = serde_json::from_str::(&json_str).unwrap(); + assert_eq!(s, actual); + } + } +} diff --git a/cdevents-sdk/src/generated/testsuiterun_started.rs b/cdevents-sdk/src/generated/testsuiterun_started.rs index 3591ca1..f735c42 100644 --- a/cdevents-sdk/src/generated/testsuiterun_started.rs +++ b/cdevents-sdk/src/generated/testsuiterun_started.rs @@ -1,9 +1,11 @@ // @generated // by cdevents/sdk-rust/generator (subject.hbs) +#[cfg(feature = "testkit")] use proptest_derive::Arbitrary; use serde::{Serialize, Deserialize}; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "environment",)] @@ -15,6 +17,7 @@ pub struct Content { } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct ContentTrigger { #[serde(rename = "type", default, skip_serializing_if = "Option::is_none",)] @@ -24,6 +27,7 @@ pub struct ContentTrigger { } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct ContentTestSuite { #[serde(rename = "id",)] @@ -37,6 +41,7 @@ pub struct ContentTestSuite { } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct ContentEnvironment { #[serde(rename = "id",)] @@ -46,6 +51,7 @@ pub struct ContentEnvironment { } #[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] pub enum ContentTriggerType { #[serde(rename = "manual")] Manual, @@ -58,3 +64,19 @@ pub enum ContentTriggerType { #[serde(rename = "other")] Other, } + +#[cfg(test)] +mod tests { + use proptest::prelude::*; + use super::*; + + proptest! { + #[test] + #[cfg(feature = "testkit")] + fn arbitraries_are_json_valid(s in any::()) { + let json_str = serde_json::to_string(&s).unwrap(); + let actual = serde_json::from_str::(&json_str).unwrap(); + assert_eq!(s, actual); + } + } +} diff --git a/cdevents-sdk/src/subject.rs b/cdevents-sdk/src/subject.rs index 887b156..c58f0f0 100644 --- a/cdevents-sdk/src/subject.rs +++ b/cdevents-sdk/src/subject.rs @@ -88,3 +88,40 @@ impl From for Subject where T: Into{ } } } + +#[cfg(feature = "testkit")] +impl<> proptest::arbitrary::Arbitrary for Subject { + type Parameters = (); + type Strategy = proptest::strategy::BoxedStrategy; + fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy { + use proptest::prelude::*; + ( + any::(), + "\\PC*", + any::>(), + ).prop_map(|(content, id, source)| { + let mut subject = Subject::from(content).with_id(id); + if let Some(source) = source { + subject = subject.with_source(source); + } + subject + }).boxed() + } +} + + +#[cfg(test)] +mod tests { + use proptest::prelude::*; + use super::*; + + proptest! { + #[test] + #[cfg(feature = "testkit")] + fn jsonify_arbitraries(s in any::()) { + // Not enough information into json of subject to deserialize into the same sut content + // so only check that it could be serialized + serde_json::to_string(&s).unwrap(); + } + } +} \ No newline at end of file diff --git a/cdevents-sdk/src/uri.rs b/cdevents-sdk/src/uri.rs index bf65638..73cad0a 100644 --- a/cdevents-sdk/src/uri.rs +++ b/cdevents-sdk/src/uri.rs @@ -8,11 +8,16 @@ use std::str::FromStr; use serde::{Serialize, Deserialize}; - +#[cfg(feature = "testkit")] use proptest_derive::Arbitrary; use crate::UriReference; #[derive(Debug, Clone, Default, Serialize, Deserialize)] -pub struct Uri(#[serde(with = "crate::serde::fluent_uri")] pub(crate) fluent_uri::Uri); +#[cfg_attr(feature = "testkit", derive(Arbitrary))] +pub struct Uri( + #[cfg_attr(feature = "testkit", proptest(value = "fluent_uri::Uri::parse_from(\"https://example.com/\".to_owned()).unwrap()"))] //TODO generate random value + #[serde(with = "crate::serde::fluent_uri")] + pub(crate) fluent_uri::Uri +); impl PartialEq for Uri { fn eq(&self, other: &Self) -> bool { @@ -72,3 +77,19 @@ impl Uri { // uri.0 // } // } + +#[cfg(test)] +mod tests { + use proptest::prelude::*; + use super::*; + + proptest! { + #[test] + #[cfg(feature = "testkit")] + fn arbitraries_are_json_valid(s in any::()) { + let json_str = serde_json::to_string(&s).unwrap(); + let actual = serde_json::from_str::(&json_str).unwrap(); + assert_eq!(s, actual); + } + } +} diff --git a/cdevents-sdk/src/uri_reference.rs b/cdevents-sdk/src/uri_reference.rs index 4e910ba..0af5fb9 100644 --- a/cdevents-sdk/src/uri_reference.rs +++ b/cdevents-sdk/src/uri_reference.rs @@ -1,11 +1,13 @@ use std::str::FromStr; use serde::{Serialize, Deserialize}; - use crate::Uri; #[derive(Debug, Clone, Default, Serialize, Deserialize)] -pub struct UriReference(#[serde(with = "crate::serde::fluent_uri")] pub(crate) fluent_uri::Uri); +pub struct UriReference( + #[serde(with = "crate::serde::fluent_uri")] + pub(crate) fluent_uri::Uri +); impl PartialEq for UriReference { fn eq(&self, other: &Self) -> bool { @@ -64,3 +66,33 @@ impl UriReference { // uri.0 // } // } + +#[cfg(feature = "testkit")] +impl<> proptest::arbitrary::Arbitrary for UriReference { + type Parameters = (); + type Strategy = proptest::strategy::BoxedStrategy; + + fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy { + use proptest::prelude::*; + (prop_oneof![ + "/[a-z_\\-/]*".prop_map(|s| UriReference::from_str(&s).unwrap()), + Just("https://example.com/").prop_map(|s| UriReference::from_str(&s).unwrap()), + ]).boxed() + } +} + +#[cfg(test)] +mod tests { + use proptest::prelude::*; + use super::*; + + proptest! { + #[test] + #[cfg(feature = "testkit")] + fn arbitraries_are_json_valid(s in any::()) { + let json_str = serde_json::to_string(&s).unwrap(); + let actual = serde_json::from_str::(&json_str).unwrap(); + assert_eq!(s, actual); + } + } +} diff --git a/generator/templates/mod.hbs b/generator/templates/mod.hbs index 5d3ef83..e8b2625 100644 --- a/generator/templates/mod.hbs +++ b/generator/templates/mod.hbs @@ -62,3 +62,18 @@ impl From<{{this.rust_module}}::Content> for Content { } } {{/each}} + +#[cfg(feature = "testkit")] +impl<> proptest::arbitrary::Arbitrary for Content { + type Parameters = (); + type Strategy = proptest::strategy::BoxedStrategy; + + fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy { + use proptest::prelude::*; + prop_oneof![ +{{#each variants }} + any::<{{this.rust_module}}::Content>().prop_map(Content::from), +{{/each}} + ].boxed() + } +} diff --git a/generator/templates/variant.hbs b/generator/templates/variant.hbs index 1cddc8b..8726957 100644 --- a/generator/templates/variant.hbs +++ b/generator/templates/variant.hbs @@ -1,10 +1,12 @@ // @generated // by cdevents/sdk-rust/generator (subject.hbs) +#[cfg(feature = "testkit")] use proptest_derive::Arbitrary; use serde::{Serialize, Deserialize}; {{#each structs }} #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] #[serde(deny_unknown_fields)] pub struct {{ this.type_info.type_declaration }} { {{#each this.fields }} @@ -19,6 +21,7 @@ pub struct {{ this.type_info.type_declaration }} { {{#each enums }} #[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)] +#[cfg_attr(feature = "testkit", derive(Arbitrary))] pub enum {{ this.type_info.type_declaration }} { {{#each this.values }} #[serde(rename = "{{this.1}}")]{{#if this.0}} @@ -27,3 +30,19 @@ pub enum {{ this.type_info.type_declaration }} { {{/each}} } {{/each}} + +#[cfg(test)] +mod tests { + use proptest::prelude::*; + use super::*; + + proptest! { + #[test] + #[cfg(feature = "testkit")] + fn arbitraries_are_json_valid(s in any::()) { + let json_str = serde_json::to_string(&s).unwrap(); + let actual = serde_json::from_str::(&json_str).unwrap(); + assert_eq!(s, actual); + } + } +} From ad8f66550de13a80f2546b8869c6ff48c2b0bb94 Mon Sep 17 00:00:00 2001 From: David Bernard Date: Sun, 28 Jan 2024 19:27:29 +0100 Subject: [PATCH 26/34] test: add test to validate against jsonschema: examples (from spec), generated samples - generate samples with arbitraries (proptest) Signed-off-by: David Bernard --- cdevents-sdk/Cargo.toml | 1 + cdevents-sdk/tests/specs.rs | 39 +++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/cdevents-sdk/Cargo.toml b/cdevents-sdk/Cargo.toml index 9cc5395..f38f150 100644 --- a/cdevents-sdk/Cargo.toml +++ b/cdevents-sdk/Cargo.toml @@ -21,6 +21,7 @@ time = { version = "0.3", features = ["serde-human-readable"] } [dev-dependencies] assert-json-diff = "2.0" +boon = "0.5" proptest = "1" rstest = "0.18" diff --git a/cdevents-sdk/tests/specs.rs b/cdevents-sdk/tests/specs.rs index 0cd1008..be3d313 100644 --- a/cdevents-sdk/tests/specs.rs +++ b/cdevents-sdk/tests/specs.rs @@ -3,6 +3,8 @@ use cdevents_sdk::CDEvent; use rstest::rstest; use std::fs; use std::path::PathBuf; +use proptest::prelude::*; +use boon::{Schemas, Compiler}; #[rstest] fn for_each_example(#[files("../cdevents-spec/examples/*.json")] path: PathBuf) { @@ -27,3 +29,40 @@ fn for_each_example(#[files("../cdevents-spec/examples/*.json")] path: PathBuf) dbg!(&cdevent_json); assert_json_eq!(example_json, cdevent_json); } + +fn check_against_schema(json: &serde_json::Value, ty: &str) { + let (subject, predicate) = cdevents_sdk::extract_subject_predicate(ty).expect("valid type: {ty}"); + let schemapath = format!("../cdevents-spec/schemas/{subject}{predicate}.json"); + //TODO optimize to not recompile a previously read schema + let mut schemas = Schemas::new(); + let mut compiler = Compiler::new(); + let sch_index = compiler.compile(&schemapath, &mut schemas); + if let Err(err) = sch_index { + assert!(false, "{err:#}"); + return; // to allow sch_index.unwrap() + } + let sch_index = sch_index.unwrap(); + let result = schemas.validate(&json, sch_index); + if let Err(err) = result { + assert!(false, "{err}"); + return; + } +} + +#[rstest] +fn validate_example_against_schema(#[files("../cdevents-spec/examples/*.json")] path: PathBuf) { + let example_txt = fs::read_to_string(path).expect("to read file as string"); + let example_json: serde_json::Value = + serde_json::from_str(&example_txt).expect("to parse as json"); + let ty = example_json["context"]["type"].as_str().expect("valid context.type in json"); + check_against_schema(&example_json, ty); +} + +proptest! { + #[test] + #[cfg(feature = "testkit")] + fn arbitraries_check_jsonschema(s in any::()) { + let json = serde_json::to_value(&s).unwrap(); + check_against_schema(&json, s.ty()); + } +} From 97b6a5100d802b6277bc6a1b966f5ad2ce9c5420 Mon Sep 17 00:00:00 2001 From: David Bernard Date: Sun, 28 Jan 2024 21:41:32 +0100 Subject: [PATCH 27/34] fix: enforce non-empty string for `id` and hardcode mapping between context.type and subject.type Signed-off-by: David Bernard --- README.md | 6 +- cdevents-sdk/examples/pipelinerun_finished.rs | 6 +- cdevents-sdk/src/cdevent.rs | 26 +- cdevents-sdk/src/cloudevents.rs | 8 +- cdevents-sdk/src/context.rs | 8 +- cdevents-sdk/src/error.rs | 4 + .../src/generated/artifact_packaged.rs | 2 +- cdevents-sdk/src/generated/branch_created.rs | 2 +- cdevents-sdk/src/generated/branch_deleted.rs | 2 +- .../src/generated/change_abandoned.rs | 2 +- cdevents-sdk/src/generated/change_created.rs | 2 +- cdevents-sdk/src/generated/change_merged.rs | 2 +- cdevents-sdk/src/generated/change_reviewed.rs | 2 +- cdevents-sdk/src/generated/change_updated.rs | 2 +- .../src/generated/incident_detected.rs | 6 +- .../src/generated/incident_reported.rs | 6 +- .../src/generated/incident_resolved.rs | 6 +- cdevents-sdk/src/generated/mod.rs | 226 +++++++++++++++++- .../src/generated/repository_created.rs | 2 +- .../src/generated/service_deployed.rs | 4 +- .../src/generated/service_published.rs | 2 +- cdevents-sdk/src/generated/service_removed.rs | 2 +- .../src/generated/service_rolledback.rs | 4 +- .../src/generated/service_upgraded.rs | 4 +- .../src/generated/taskrun_finished.rs | 2 +- cdevents-sdk/src/generated/taskrun_started.rs | 2 +- .../src/generated/testcaserun_finished.rs | 6 +- .../src/generated/testcaserun_queued.rs | 6 +- .../src/generated/testcaserun_started.rs | 6 +- .../src/generated/testoutput_published.rs | 2 +- .../src/generated/testsuiterun_finished.rs | 4 +- .../src/generated/testsuiterun_queued.rs | 4 +- .../src/generated/testsuiterun_started.rs | 4 +- cdevents-sdk/src/id.rs | 88 +++++++ cdevents-sdk/src/lib.rs | 2 + cdevents-sdk/src/subject.rs | 23 +- cdevents-sdk/src/uri_reference.rs | 2 +- cdevents-sdk/tests/specs.rs | 2 +- generator/src/main.rs | 49 ++-- generator/templates/mod.hbs | 42 +++- 40 files changed, 469 insertions(+), 111 deletions(-) create mode 100644 cdevents-sdk/src/id.rs diff --git a/README.md b/README.md index 3905ac3..99a0418 100644 --- a/README.md +++ b/README.md @@ -29,10 +29,10 @@ fn main() -> Result<(), Box> { pipeline_name: Some("testPipeline".into()), url: Some("https://dev.pipeline.run/url".into()) }) - .with_id("/dev/pipeline/run/1") + .with_id("/dev/pipeline/run/1".try_into()?) .with_source("https://dev.pipeline.run/source".try_into()?) ) - .with_id("271069a8-fc18-44f1-b38f-9d70a1695819") + .with_id("271069a8-fc18-44f1-b38f-9d70a1695819".try_into()?) .with_source("https://dev.cdevents".try_into()?) ; @@ -52,7 +52,7 @@ fn main() -> Result<(), Box> { let cloudevent_received: Event = cloudevent.clone(); let cdevent_extracted: CDEvent = cloudevent_received.try_into()?; - assert_eq!(cloudevent.id(), cdevent_extracted.id()); + assert_eq!(cloudevent.id(), cdevent_extracted.id().to_string()); assert_eq!(cdevent_expected, cdevent_extracted); Ok(()) } diff --git a/cdevents-sdk/examples/pipelinerun_finished.rs b/cdevents-sdk/examples/pipelinerun_finished.rs index 4bfdef6..12a5c07 100644 --- a/cdevents-sdk/examples/pipelinerun_finished.rs +++ b/cdevents-sdk/examples/pipelinerun_finished.rs @@ -11,10 +11,10 @@ fn main() -> Result<(), Box> { pipeline_name: Some("testPipeline".into()), url: Some("https://dev.pipeline.run/url".into()) }) - .with_id("/dev/pipeline/run/1") + .with_id("/dev/pipeline/run/1".try_into()?) .with_source("https://dev.pipeline.run/source".try_into()?) ) - .with_id("271069a8-fc18-44f1-b38f-9d70a1695819") + .with_id("271069a8-fc18-44f1-b38f-9d70a1695819".try_into()?) .with_source("https://dev.cdevents".try_into()?) ; @@ -34,7 +34,7 @@ fn main() -> Result<(), Box> { let cloudevent_received: Event = cloudevent.clone(); let cdevent_extracted: CDEvent = cloudevent_received.try_into()?; - assert_eq!(cloudevent.id(), cdevent_extracted.id()); + assert_eq!(cloudevent.id(), cdevent_extracted.id().to_string()); assert_eq!(cdevent_expected, cdevent_extracted); Ok(()) } diff --git a/cdevents-sdk/src/cdevent.rs b/cdevents-sdk/src/cdevent.rs index 885da56..ad4b53c 100644 --- a/cdevents-sdk/src/cdevent.rs +++ b/cdevents-sdk/src/cdevent.rs @@ -1,4 +1,4 @@ -use crate::{Context, Subject, UriReference}; +use crate::{Context, Id, Subject, UriReference}; use serde::{ de::{self, Deserializer, MapAccess, Visitor}, Deserialize, Serialize, @@ -22,7 +22,7 @@ pub struct CDEvent { impl From for CDEvent { fn from(subject: Subject) -> Self { let context = Context { - ty: subject.ty().into(), + ty: subject.content().ty().into(), ..Default::default() }; Self { @@ -46,12 +46,12 @@ impl CDEvent { } /// see - pub fn id(&self) -> &str { - self.context.id.as_str() + pub fn id(&self) -> &Id { + &self.context.id } - pub fn with_id(mut self, v: T) -> Self where T: Into { - self.context.id = v.into(); + pub fn with_id(mut self, v: Id) -> Self { + self.context.id = v; self } @@ -83,8 +83,8 @@ impl CDEvent { /// see /// derived from subject.content pub fn ty(&self) -> &str { - //self.context.ty() - self.subject.ty() + //self.subject.content().ty() + self.context.ty.as_str() } /// see @@ -199,14 +199,10 @@ impl<> proptest::arbitrary::Arbitrary for CDEvent { use proptest::prelude::*; ( any::(), - "\\PC*", - any::>(), + any::(), + any::(), ).prop_map(|(subject, id, source)| { - let mut cdevent = CDEvent::from(subject).with_id(id); - if let Some(source) = source { - cdevent = cdevent.with_source(source); - } - cdevent + CDEvent::from(subject).with_id(id).with_source(source) }).boxed() } } diff --git a/cdevents-sdk/src/cloudevents.rs b/cdevents-sdk/src/cloudevents.rs index f7fc72d..0c674be 100644 --- a/cdevents-sdk/src/cloudevents.rs +++ b/cdevents-sdk/src/cloudevents.rs @@ -68,10 +68,10 @@ mod tests { fn test_into_cloudevent() -> Result<(), Box> { let cdevent = CDEvent::from( Subject::from(build_queued::Content{}) - .with_id("subject123") + .with_id("subject123".try_into()?) .with_source("/event/source/123".try_into()?) ) - .with_id("271069a8-fc18-44f1-b38f-9d70a1695819") + .with_id("271069a8-fc18-44f1-b38f-9d70a1695819".try_into()?) .with_source("https://dev.cdevents".try_into()?) ; @@ -82,11 +82,11 @@ mod tests { assert_eq!(cloudevent_via_builder, cloudevent); assert_eq!(cloudevent.id(), "271069a8-fc18-44f1-b38f-9d70a1695819"); - assert_eq!(cloudevent.id(), cdevent.id()); + assert_eq!(cloudevent.id(), cdevent.id().to_string()); let (_, _, data) = cloudevent.take_data(); let cdevent_extracted: CDEvent = data.ok_or(Error::DataNotFoundInCloudEvent)?.try_into()?; - assert_eq!(cloudevent.id(), cdevent_extracted.id()); + assert_eq!(cloudevent.id(), cdevent_extracted.id().to_string()); assert_eq!(cdevent, cdevent_extracted); Ok(()) } diff --git a/cdevents-sdk/src/context.rs b/cdevents-sdk/src/context.rs index cd891f4..7845c5b 100644 --- a/cdevents-sdk/src/context.rs +++ b/cdevents-sdk/src/context.rs @@ -1,12 +1,12 @@ use serde::{Deserialize, Serialize}; -use crate::UriReference; +use crate::{Id, UriReference}; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] pub(crate) struct Context { pub(crate) version: String, - pub(crate) id: String, + pub(crate) id: Id, pub(crate) source: UriReference, #[serde(rename = "type")] pub(crate) ty: String, @@ -18,8 +18,8 @@ impl Default for Context { fn default() -> Self { Self { version: "0.3.0".into(), - id: "00000000-0000-0000-0000-000000000000".into(), - source: UriReference::default(), + id: Id::default(), + source: "/undef".try_into().expect("/undef is a valid uri-reference"), ty: "dev.cdevents.undef.undef.0.0.0".into(), timestamp: time::OffsetDateTime::now_utc(), } diff --git a/cdevents-sdk/src/error.rs b/cdevents-sdk/src/error.rs index 5d7260b..51ac340 100644 --- a/cdevents-sdk/src/error.rs +++ b/cdevents-sdk/src/error.rs @@ -1,5 +1,7 @@ use thiserror::Error; +// type Result = std::result::Result; + #[derive(Error, Debug)] pub enum Error { #[error("Empty data in cloudevent")] @@ -10,4 +12,6 @@ pub enum Error { SerdeJsonError( #[from] serde_json::Error), #[error("unknown error")] Unknown, + #[error("{0} should be non-empty")] + EmptyString(&'static str) } diff --git a/cdevents-sdk/src/generated/artifact_packaged.rs b/cdevents-sdk/src/generated/artifact_packaged.rs index 3900f77..e4472a7 100644 --- a/cdevents-sdk/src/generated/artifact_packaged.rs +++ b/cdevents-sdk/src/generated/artifact_packaged.rs @@ -17,7 +17,7 @@ pub struct Content { #[serde(deny_unknown_fields)] pub struct ContentChange { #[serde(rename = "id",)] - pub id: String, + pub id: crate::Id, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } diff --git a/cdevents-sdk/src/generated/branch_created.rs b/cdevents-sdk/src/generated/branch_created.rs index 8c479f9..99f44c3 100644 --- a/cdevents-sdk/src/generated/branch_created.rs +++ b/cdevents-sdk/src/generated/branch_created.rs @@ -17,7 +17,7 @@ pub struct Content { #[serde(deny_unknown_fields)] pub struct ContentRepository { #[serde(rename = "id",)] - pub id: String, + pub id: crate::Id, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } diff --git a/cdevents-sdk/src/generated/branch_deleted.rs b/cdevents-sdk/src/generated/branch_deleted.rs index 8c479f9..99f44c3 100644 --- a/cdevents-sdk/src/generated/branch_deleted.rs +++ b/cdevents-sdk/src/generated/branch_deleted.rs @@ -17,7 +17,7 @@ pub struct Content { #[serde(deny_unknown_fields)] pub struct ContentRepository { #[serde(rename = "id",)] - pub id: String, + pub id: crate::Id, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } diff --git a/cdevents-sdk/src/generated/change_abandoned.rs b/cdevents-sdk/src/generated/change_abandoned.rs index 8c479f9..99f44c3 100644 --- a/cdevents-sdk/src/generated/change_abandoned.rs +++ b/cdevents-sdk/src/generated/change_abandoned.rs @@ -17,7 +17,7 @@ pub struct Content { #[serde(deny_unknown_fields)] pub struct ContentRepository { #[serde(rename = "id",)] - pub id: String, + pub id: crate::Id, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } diff --git a/cdevents-sdk/src/generated/change_created.rs b/cdevents-sdk/src/generated/change_created.rs index 8c479f9..99f44c3 100644 --- a/cdevents-sdk/src/generated/change_created.rs +++ b/cdevents-sdk/src/generated/change_created.rs @@ -17,7 +17,7 @@ pub struct Content { #[serde(deny_unknown_fields)] pub struct ContentRepository { #[serde(rename = "id",)] - pub id: String, + pub id: crate::Id, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } diff --git a/cdevents-sdk/src/generated/change_merged.rs b/cdevents-sdk/src/generated/change_merged.rs index 8c479f9..99f44c3 100644 --- a/cdevents-sdk/src/generated/change_merged.rs +++ b/cdevents-sdk/src/generated/change_merged.rs @@ -17,7 +17,7 @@ pub struct Content { #[serde(deny_unknown_fields)] pub struct ContentRepository { #[serde(rename = "id",)] - pub id: String, + pub id: crate::Id, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } diff --git a/cdevents-sdk/src/generated/change_reviewed.rs b/cdevents-sdk/src/generated/change_reviewed.rs index 8c479f9..99f44c3 100644 --- a/cdevents-sdk/src/generated/change_reviewed.rs +++ b/cdevents-sdk/src/generated/change_reviewed.rs @@ -17,7 +17,7 @@ pub struct Content { #[serde(deny_unknown_fields)] pub struct ContentRepository { #[serde(rename = "id",)] - pub id: String, + pub id: crate::Id, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } diff --git a/cdevents-sdk/src/generated/change_updated.rs b/cdevents-sdk/src/generated/change_updated.rs index 8c479f9..99f44c3 100644 --- a/cdevents-sdk/src/generated/change_updated.rs +++ b/cdevents-sdk/src/generated/change_updated.rs @@ -17,7 +17,7 @@ pub struct Content { #[serde(deny_unknown_fields)] pub struct ContentRepository { #[serde(rename = "id",)] - pub id: String, + pub id: crate::Id, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } diff --git a/cdevents-sdk/src/generated/incident_detected.rs b/cdevents-sdk/src/generated/incident_detected.rs index 6d0c62a..303f33b 100644 --- a/cdevents-sdk/src/generated/incident_detected.rs +++ b/cdevents-sdk/src/generated/incident_detected.rs @@ -9,7 +9,7 @@ use serde::{Serialize, Deserialize}; #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "artifactId", default, skip_serializing_if = "Option::is_none",)] - pub artifact_id: Option, + pub artifact_id: Option, #[serde(rename = "description", default, skip_serializing_if = "Option::is_none",)] pub description: Option, #[serde(rename = "environment",)] @@ -23,7 +23,7 @@ pub struct Content { #[serde(deny_unknown_fields)] pub struct ContentService { #[serde(rename = "id",)] - pub id: String, + pub id: crate::Id, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } @@ -33,7 +33,7 @@ pub struct ContentService { #[serde(deny_unknown_fields)] pub struct ContentEnvironment { #[serde(rename = "id",)] - pub id: String, + pub id: crate::Id, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } diff --git a/cdevents-sdk/src/generated/incident_reported.rs b/cdevents-sdk/src/generated/incident_reported.rs index ee90dae..a4ac0c1 100644 --- a/cdevents-sdk/src/generated/incident_reported.rs +++ b/cdevents-sdk/src/generated/incident_reported.rs @@ -9,7 +9,7 @@ use serde::{Serialize, Deserialize}; #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "artifactId", default, skip_serializing_if = "Option::is_none",)] - pub artifact_id: Option, + pub artifact_id: Option, #[serde(rename = "description", default, skip_serializing_if = "Option::is_none",)] pub description: Option, #[serde(rename = "environment",)] @@ -25,7 +25,7 @@ pub struct Content { #[serde(deny_unknown_fields)] pub struct ContentService { #[serde(rename = "id",)] - pub id: String, + pub id: crate::Id, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } @@ -35,7 +35,7 @@ pub struct ContentService { #[serde(deny_unknown_fields)] pub struct ContentEnvironment { #[serde(rename = "id",)] - pub id: String, + pub id: crate::Id, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } diff --git a/cdevents-sdk/src/generated/incident_resolved.rs b/cdevents-sdk/src/generated/incident_resolved.rs index 6d0c62a..303f33b 100644 --- a/cdevents-sdk/src/generated/incident_resolved.rs +++ b/cdevents-sdk/src/generated/incident_resolved.rs @@ -9,7 +9,7 @@ use serde::{Serialize, Deserialize}; #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "artifactId", default, skip_serializing_if = "Option::is_none",)] - pub artifact_id: Option, + pub artifact_id: Option, #[serde(rename = "description", default, skip_serializing_if = "Option::is_none",)] pub description: Option, #[serde(rename = "environment",)] @@ -23,7 +23,7 @@ pub struct Content { #[serde(deny_unknown_fields)] pub struct ContentService { #[serde(rename = "id",)] - pub id: String, + pub id: crate::Id, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } @@ -33,7 +33,7 @@ pub struct ContentService { #[serde(deny_unknown_fields)] pub struct ContentEnvironment { #[serde(rename = "id",)] - pub id: String, + pub id: crate::Id, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } diff --git a/cdevents-sdk/src/generated/mod.rs b/cdevents-sdk/src/generated/mod.rs index c64f14e..47f92f2 100644 --- a/cdevents-sdk/src/generated/mod.rs +++ b/cdevents-sdk/src/generated/mod.rs @@ -339,14 +339,140 @@ impl Content { } } - pub fn subject_predicate(&self) -> (&'static str, &'static str){ - let mut split = self.ty().split('.'); - ( - split.nth(2).expect("fargment 2 of ty should always exists"), - split.nth(3).expect("fargment 3 of ty should always exists") - ) + pub fn subject(&self) -> &'static str { + match self { + Self::ArtifactPackaged(_) => "artifact", + Self::ArtifactPublished(_) => "artifact", + Self::ArtifactSigned(_) => "artifact", + Self::BranchCreated(_) => "branch", + Self::BranchDeleted(_) => "branch", + Self::BuildFinished(_) => "build", + Self::BuildQueued(_) => "build", + Self::BuildStarted(_) => "build", + Self::ChangeAbandoned(_) => "change", + Self::ChangeCreated(_) => "change", + Self::ChangeMerged(_) => "change", + Self::ChangeReviewed(_) => "change", + Self::ChangeUpdated(_) => "change", + Self::EnvironmentCreated(_) => "environment", + Self::EnvironmentDeleted(_) => "environment", + Self::EnvironmentModified(_) => "environment", + Self::IncidentDetected(_) => "incident", + Self::IncidentReported(_) => "incident", + Self::IncidentResolved(_) => "incident", + Self::PipelinerunFinished(_) => "pipelineRun", + Self::PipelinerunQueued(_) => "pipelineRun", + Self::PipelinerunStarted(_) => "pipelineRun", + Self::RepositoryCreated(_) => "repository", + Self::RepositoryDeleted(_) => "repository", + Self::RepositoryModified(_) => "repository", + Self::ServiceDeployed(_) => "service", + Self::ServicePublished(_) => "service", + Self::ServiceRemoved(_) => "service", + Self::ServiceRolledback(_) => "service", + Self::ServiceUpgraded(_) => "service", + Self::TaskrunFinished(_) => "taskRun", + Self::TaskrunStarted(_) => "taskRun", + Self::TestcaserunFinished(_) => "testCaseRun", + Self::TestcaserunQueued(_) => "testCaseRun", + Self::TestcaserunStarted(_) => "testCaseRun", + Self::TestoutputPublished(_) => "testOutput", + Self::TestsuiterunFinished(_) => "testSuiteRun", + Self::TestsuiterunQueued(_) => "testSuiteRun", + Self::TestsuiterunStarted(_) => "testSuiteRun", + } } + pub fn predicate(&self) -> &'static str { + match self { + Self::ArtifactPackaged(_) => "packaged", + Self::ArtifactPublished(_) => "published", + Self::ArtifactSigned(_) => "signed", + Self::BranchCreated(_) => "created", + Self::BranchDeleted(_) => "deleted", + Self::BuildFinished(_) => "finished", + Self::BuildQueued(_) => "queued", + Self::BuildStarted(_) => "started", + Self::ChangeAbandoned(_) => "abandoned", + Self::ChangeCreated(_) => "created", + Self::ChangeMerged(_) => "merged", + Self::ChangeReviewed(_) => "reviewed", + Self::ChangeUpdated(_) => "updated", + Self::EnvironmentCreated(_) => "created", + Self::EnvironmentDeleted(_) => "deleted", + Self::EnvironmentModified(_) => "modified", + Self::IncidentDetected(_) => "detected", + Self::IncidentReported(_) => "reported", + Self::IncidentResolved(_) => "resolved", + Self::PipelinerunFinished(_) => "finished", + Self::PipelinerunQueued(_) => "queued", + Self::PipelinerunStarted(_) => "started", + Self::RepositoryCreated(_) => "created", + Self::RepositoryDeleted(_) => "deleted", + Self::RepositoryModified(_) => "modified", + Self::ServiceDeployed(_) => "deployed", + Self::ServicePublished(_) => "published", + Self::ServiceRemoved(_) => "removed", + Self::ServiceRolledback(_) => "rolledback", + Self::ServiceUpgraded(_) => "upgraded", + Self::TaskrunFinished(_) => "finished", + Self::TaskrunStarted(_) => "started", + Self::TestcaserunFinished(_) => "finished", + Self::TestcaserunQueued(_) => "queued", + Self::TestcaserunStarted(_) => "started", + Self::TestoutputPublished(_) => "published", + Self::TestsuiterunFinished(_) => "finished", + Self::TestsuiterunQueued(_) => "queued", + Self::TestsuiterunStarted(_) => "started", + } + } +} + +// due to inconstency in case/format the subject could be not be extracted from the context.type (ty), jsonshema $id, spec filename (shema, examples) +pub fn extract_subject_predicate(ty: &str) -> Option<(&str, &str)>{ + // let mut split = ty.split('.'); + match ty { + ARTIFACT_PACKAGED => Some(("artifact", "packaged")), + ARTIFACT_PUBLISHED => Some(("artifact", "published")), + ARTIFACT_SIGNED => Some(("artifact", "signed")), + BRANCH_CREATED => Some(("branch", "created")), + BRANCH_DELETED => Some(("branch", "deleted")), + BUILD_FINISHED => Some(("build", "finished")), + BUILD_QUEUED => Some(("build", "queued")), + BUILD_STARTED => Some(("build", "started")), + CHANGE_ABANDONED => Some(("change", "abandoned")), + CHANGE_CREATED => Some(("change", "created")), + CHANGE_MERGED => Some(("change", "merged")), + CHANGE_REVIEWED => Some(("change", "reviewed")), + CHANGE_UPDATED => Some(("change", "updated")), + ENVIRONMENT_CREATED => Some(("environment", "created")), + ENVIRONMENT_DELETED => Some(("environment", "deleted")), + ENVIRONMENT_MODIFIED => Some(("environment", "modified")), + INCIDENT_DETECTED => Some(("incident", "detected")), + INCIDENT_REPORTED => Some(("incident", "reported")), + INCIDENT_RESOLVED => Some(("incident", "resolved")), + PIPELINERUN_FINISHED => Some(("pipelineRun", "finished")), + PIPELINERUN_QUEUED => Some(("pipelineRun", "queued")), + PIPELINERUN_STARTED => Some(("pipelineRun", "started")), + REPOSITORY_CREATED => Some(("repository", "created")), + REPOSITORY_DELETED => Some(("repository", "deleted")), + REPOSITORY_MODIFIED => Some(("repository", "modified")), + SERVICE_DEPLOYED => Some(("service", "deployed")), + SERVICE_PUBLISHED => Some(("service", "published")), + SERVICE_REMOVED => Some(("service", "removed")), + SERVICE_ROLLEDBACK => Some(("service", "rolledback")), + SERVICE_UPGRADED => Some(("service", "upgraded")), + TASKRUN_FINISHED => Some(("taskRun", "finished")), + TASKRUN_STARTED => Some(("taskRun", "started")), + TESTCASERUN_FINISHED => Some(("testCaseRun", "finished")), + TESTCASERUN_QUEUED => Some(("testCaseRun", "queued")), + TESTCASERUN_STARTED => Some(("testCaseRun", "started")), + TESTOUTPUT_PUBLISHED => Some(("testOutput", "published")), + TESTSUITERUN_FINISHED => Some(("testSuiteRun", "finished")), + TESTSUITERUN_QUEUED => Some(("testSuiteRun", "queued")), + TESTSUITERUN_STARTED => Some(("testSuiteRun", "started")), + _ => None, + } } impl From for Content { @@ -595,3 +721,91 @@ impl<> proptest::arbitrary::Arbitrary for Content { ].boxed() } } + +// #[cfg(test)] +// mod tests { +// use super::*; +// +// #[test] +// fn test_true() { +// +// assert_eq!(extract_subject_predicate(ARTIFACT_PACKAGED), Some(("artifact","packaged"))); +// +// assert_eq!(extract_subject_predicate(ARTIFACT_PUBLISHED), Some(("artifact","published"))); +// +// assert_eq!(extract_subject_predicate(ARTIFACT_SIGNED), Some(("artifact","signed"))); +// +// assert_eq!(extract_subject_predicate(BRANCH_CREATED), Some(("branch","created"))); +// +// assert_eq!(extract_subject_predicate(BRANCH_DELETED), Some(("branch","deleted"))); +// +// assert_eq!(extract_subject_predicate(BUILD_FINISHED), Some(("build","finished"))); +// +// assert_eq!(extract_subject_predicate(BUILD_QUEUED), Some(("build","queued"))); +// +// assert_eq!(extract_subject_predicate(BUILD_STARTED), Some(("build","started"))); +// +// assert_eq!(extract_subject_predicate(CHANGE_ABANDONED), Some(("change","abandoned"))); +// +// assert_eq!(extract_subject_predicate(CHANGE_CREATED), Some(("change","created"))); +// +// assert_eq!(extract_subject_predicate(CHANGE_MERGED), Some(("change","merged"))); +// +// assert_eq!(extract_subject_predicate(CHANGE_REVIEWED), Some(("change","reviewed"))); +// +// assert_eq!(extract_subject_predicate(CHANGE_UPDATED), Some(("change","updated"))); +// +// assert_eq!(extract_subject_predicate(ENVIRONMENT_CREATED), Some(("environment","created"))); +// +// assert_eq!(extract_subject_predicate(ENVIRONMENT_DELETED), Some(("environment","deleted"))); +// +// assert_eq!(extract_subject_predicate(ENVIRONMENT_MODIFIED), Some(("environment","modified"))); +// +// assert_eq!(extract_subject_predicate(INCIDENT_DETECTED), Some(("incident","detected"))); +// +// assert_eq!(extract_subject_predicate(INCIDENT_REPORTED), Some(("incident","reported"))); +// +// assert_eq!(extract_subject_predicate(INCIDENT_RESOLVED), Some(("incident","resolved"))); +// +// assert_eq!(extract_subject_predicate(PIPELINERUN_FINISHED), Some(("pipelineRun","finished"))); +// +// assert_eq!(extract_subject_predicate(PIPELINERUN_QUEUED), Some(("pipelineRun","queued"))); +// +// assert_eq!(extract_subject_predicate(PIPELINERUN_STARTED), Some(("pipelineRun","started"))); +// +// assert_eq!(extract_subject_predicate(REPOSITORY_CREATED), Some(("repository","created"))); +// +// assert_eq!(extract_subject_predicate(REPOSITORY_DELETED), Some(("repository","deleted"))); +// +// assert_eq!(extract_subject_predicate(REPOSITORY_MODIFIED), Some(("repository","modified"))); +// +// assert_eq!(extract_subject_predicate(SERVICE_DEPLOYED), Some(("service","deployed"))); +// +// assert_eq!(extract_subject_predicate(SERVICE_PUBLISHED), Some(("service","published"))); +// +// assert_eq!(extract_subject_predicate(SERVICE_REMOVED), Some(("service","removed"))); +// +// assert_eq!(extract_subject_predicate(SERVICE_ROLLEDBACK), Some(("service","rolledback"))); +// +// assert_eq!(extract_subject_predicate(SERVICE_UPGRADED), Some(("service","upgraded"))); +// +// assert_eq!(extract_subject_predicate(TASKRUN_FINISHED), Some(("taskRun","finished"))); +// +// assert_eq!(extract_subject_predicate(TASKRUN_STARTED), Some(("taskRun","started"))); +// +// assert_eq!(extract_subject_predicate(TESTCASERUN_FINISHED), Some(("testCaseRun","finished"))); +// +// assert_eq!(extract_subject_predicate(TESTCASERUN_QUEUED), Some(("testCaseRun","queued"))); +// +// assert_eq!(extract_subject_predicate(TESTCASERUN_STARTED), Some(("testCaseRun","started"))); +// +// assert_eq!(extract_subject_predicate(TESTOUTPUT_PUBLISHED), Some(("testOutput","published"))); +// +// assert_eq!(extract_subject_predicate(TESTSUITERUN_FINISHED), Some(("testSuiteRun","finished"))); +// +// assert_eq!(extract_subject_predicate(TESTSUITERUN_QUEUED), Some(("testSuiteRun","queued"))); +// +// assert_eq!(extract_subject_predicate(TESTSUITERUN_STARTED), Some(("testSuiteRun","started"))); +// +// } +// } \ No newline at end of file diff --git a/cdevents-sdk/src/generated/repository_created.rs b/cdevents-sdk/src/generated/repository_created.rs index 7f2ed30..b2d8e60 100644 --- a/cdevents-sdk/src/generated/repository_created.rs +++ b/cdevents-sdk/src/generated/repository_created.rs @@ -9,7 +9,7 @@ use serde::{Serialize, Deserialize}; #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "name",)] - pub name: String, + pub name: crate::Name, #[serde(rename = "owner", default, skip_serializing_if = "Option::is_none",)] pub owner: Option, #[serde(rename = "url",)] diff --git a/cdevents-sdk/src/generated/service_deployed.rs b/cdevents-sdk/src/generated/service_deployed.rs index 1499d5c..b9fe280 100644 --- a/cdevents-sdk/src/generated/service_deployed.rs +++ b/cdevents-sdk/src/generated/service_deployed.rs @@ -9,7 +9,7 @@ use serde::{Serialize, Deserialize}; #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "artifactId",)] - pub artifact_id: String, + pub artifact_id: crate::Id, #[serde(rename = "environment",)] pub environment: ContentEnvironment, } @@ -19,7 +19,7 @@ pub struct Content { #[serde(deny_unknown_fields)] pub struct ContentEnvironment { #[serde(rename = "id",)] - pub id: String, + pub id: crate::Id, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } diff --git a/cdevents-sdk/src/generated/service_published.rs b/cdevents-sdk/src/generated/service_published.rs index 2740c04..e458076 100644 --- a/cdevents-sdk/src/generated/service_published.rs +++ b/cdevents-sdk/src/generated/service_published.rs @@ -17,7 +17,7 @@ pub struct Content { #[serde(deny_unknown_fields)] pub struct ContentEnvironment { #[serde(rename = "id",)] - pub id: String, + pub id: crate::Id, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } diff --git a/cdevents-sdk/src/generated/service_removed.rs b/cdevents-sdk/src/generated/service_removed.rs index 2740c04..e458076 100644 --- a/cdevents-sdk/src/generated/service_removed.rs +++ b/cdevents-sdk/src/generated/service_removed.rs @@ -17,7 +17,7 @@ pub struct Content { #[serde(deny_unknown_fields)] pub struct ContentEnvironment { #[serde(rename = "id",)] - pub id: String, + pub id: crate::Id, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } diff --git a/cdevents-sdk/src/generated/service_rolledback.rs b/cdevents-sdk/src/generated/service_rolledback.rs index 1499d5c..b9fe280 100644 --- a/cdevents-sdk/src/generated/service_rolledback.rs +++ b/cdevents-sdk/src/generated/service_rolledback.rs @@ -9,7 +9,7 @@ use serde::{Serialize, Deserialize}; #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "artifactId",)] - pub artifact_id: String, + pub artifact_id: crate::Id, #[serde(rename = "environment",)] pub environment: ContentEnvironment, } @@ -19,7 +19,7 @@ pub struct Content { #[serde(deny_unknown_fields)] pub struct ContentEnvironment { #[serde(rename = "id",)] - pub id: String, + pub id: crate::Id, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } diff --git a/cdevents-sdk/src/generated/service_upgraded.rs b/cdevents-sdk/src/generated/service_upgraded.rs index 1499d5c..b9fe280 100644 --- a/cdevents-sdk/src/generated/service_upgraded.rs +++ b/cdevents-sdk/src/generated/service_upgraded.rs @@ -9,7 +9,7 @@ use serde::{Serialize, Deserialize}; #[serde(deny_unknown_fields)] pub struct Content { #[serde(rename = "artifactId",)] - pub artifact_id: String, + pub artifact_id: crate::Id, #[serde(rename = "environment",)] pub environment: ContentEnvironment, } @@ -19,7 +19,7 @@ pub struct Content { #[serde(deny_unknown_fields)] pub struct ContentEnvironment { #[serde(rename = "id",)] - pub id: String, + pub id: crate::Id, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } diff --git a/cdevents-sdk/src/generated/taskrun_finished.rs b/cdevents-sdk/src/generated/taskrun_finished.rs index 8603566..d47c3f7 100644 --- a/cdevents-sdk/src/generated/taskrun_finished.rs +++ b/cdevents-sdk/src/generated/taskrun_finished.rs @@ -25,7 +25,7 @@ pub struct Content { #[serde(deny_unknown_fields)] pub struct ContentPipelineRun { #[serde(rename = "id",)] - pub id: String, + pub id: crate::Id, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } diff --git a/cdevents-sdk/src/generated/taskrun_started.rs b/cdevents-sdk/src/generated/taskrun_started.rs index 3edb228..3f76d68 100644 --- a/cdevents-sdk/src/generated/taskrun_started.rs +++ b/cdevents-sdk/src/generated/taskrun_started.rs @@ -21,7 +21,7 @@ pub struct Content { #[serde(deny_unknown_fields)] pub struct ContentPipelineRun { #[serde(rename = "id",)] - pub id: String, + pub id: crate::Id, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } diff --git a/cdevents-sdk/src/generated/testcaserun_finished.rs b/cdevents-sdk/src/generated/testcaserun_finished.rs index 6d2051b..c6d4414 100644 --- a/cdevents-sdk/src/generated/testcaserun_finished.rs +++ b/cdevents-sdk/src/generated/testcaserun_finished.rs @@ -27,7 +27,7 @@ pub struct Content { #[serde(deny_unknown_fields)] pub struct ContentTestSuiteRun { #[serde(rename = "id",)] - pub id: String, + pub id: crate::Id, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } @@ -37,7 +37,7 @@ pub struct ContentTestSuiteRun { #[serde(deny_unknown_fields)] pub struct ContentTestCase { #[serde(rename = "id",)] - pub id: String, + pub id: crate::Id, #[serde(rename = "name", default, skip_serializing_if = "Option::is_none",)] pub name: Option, #[serde(rename = "type", default, skip_serializing_if = "Option::is_none",)] @@ -53,7 +53,7 @@ pub struct ContentTestCase { #[serde(deny_unknown_fields)] pub struct ContentEnvironment { #[serde(rename = "id",)] - pub id: String, + pub id: crate::Id, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } diff --git a/cdevents-sdk/src/generated/testcaserun_queued.rs b/cdevents-sdk/src/generated/testcaserun_queued.rs index c42dfb2..3c5c12c 100644 --- a/cdevents-sdk/src/generated/testcaserun_queued.rs +++ b/cdevents-sdk/src/generated/testcaserun_queued.rs @@ -33,7 +33,7 @@ pub struct ContentTrigger { #[serde(deny_unknown_fields)] pub struct ContentTestSuiteRun { #[serde(rename = "id",)] - pub id: String, + pub id: crate::Id, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } @@ -43,7 +43,7 @@ pub struct ContentTestSuiteRun { #[serde(deny_unknown_fields)] pub struct ContentTestCase { #[serde(rename = "id",)] - pub id: String, + pub id: crate::Id, #[serde(rename = "name", default, skip_serializing_if = "Option::is_none",)] pub name: Option, #[serde(rename = "type", default, skip_serializing_if = "Option::is_none",)] @@ -59,7 +59,7 @@ pub struct ContentTestCase { #[serde(deny_unknown_fields)] pub struct ContentEnvironment { #[serde(rename = "id",)] - pub id: String, + pub id: crate::Id, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } diff --git a/cdevents-sdk/src/generated/testcaserun_started.rs b/cdevents-sdk/src/generated/testcaserun_started.rs index c42dfb2..3c5c12c 100644 --- a/cdevents-sdk/src/generated/testcaserun_started.rs +++ b/cdevents-sdk/src/generated/testcaserun_started.rs @@ -33,7 +33,7 @@ pub struct ContentTrigger { #[serde(deny_unknown_fields)] pub struct ContentTestSuiteRun { #[serde(rename = "id",)] - pub id: String, + pub id: crate::Id, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } @@ -43,7 +43,7 @@ pub struct ContentTestSuiteRun { #[serde(deny_unknown_fields)] pub struct ContentTestCase { #[serde(rename = "id",)] - pub id: String, + pub id: crate::Id, #[serde(rename = "name", default, skip_serializing_if = "Option::is_none",)] pub name: Option, #[serde(rename = "type", default, skip_serializing_if = "Option::is_none",)] @@ -59,7 +59,7 @@ pub struct ContentTestCase { #[serde(deny_unknown_fields)] pub struct ContentEnvironment { #[serde(rename = "id",)] - pub id: String, + pub id: crate::Id, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } diff --git a/cdevents-sdk/src/generated/testoutput_published.rs b/cdevents-sdk/src/generated/testoutput_published.rs index 675acbc..b4a146a 100644 --- a/cdevents-sdk/src/generated/testoutput_published.rs +++ b/cdevents-sdk/src/generated/testoutput_published.rs @@ -23,7 +23,7 @@ pub struct Content { #[serde(deny_unknown_fields)] pub struct ContentTestCaseRun { #[serde(rename = "id",)] - pub id: String, + pub id: crate::Id, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } diff --git a/cdevents-sdk/src/generated/testsuiterun_finished.rs b/cdevents-sdk/src/generated/testsuiterun_finished.rs index a59e593..824bfb6 100644 --- a/cdevents-sdk/src/generated/testsuiterun_finished.rs +++ b/cdevents-sdk/src/generated/testsuiterun_finished.rs @@ -25,7 +25,7 @@ pub struct Content { #[serde(deny_unknown_fields)] pub struct ContentTestSuite { #[serde(rename = "id",)] - pub id: String, + pub id: crate::Id, #[serde(rename = "name", default, skip_serializing_if = "Option::is_none",)] pub name: Option, #[serde(rename = "uri", default, skip_serializing_if = "Option::is_none",)] @@ -39,7 +39,7 @@ pub struct ContentTestSuite { #[serde(deny_unknown_fields)] pub struct ContentEnvironment { #[serde(rename = "id",)] - pub id: String, + pub id: crate::Id, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } diff --git a/cdevents-sdk/src/generated/testsuiterun_queued.rs b/cdevents-sdk/src/generated/testsuiterun_queued.rs index 5fc5ac1..d5cae30 100644 --- a/cdevents-sdk/src/generated/testsuiterun_queued.rs +++ b/cdevents-sdk/src/generated/testsuiterun_queued.rs @@ -31,7 +31,7 @@ pub struct ContentTrigger { #[serde(deny_unknown_fields)] pub struct ContentTestSuite { #[serde(rename = "id",)] - pub id: String, + pub id: crate::Id, #[serde(rename = "name", default, skip_serializing_if = "Option::is_none",)] pub name: Option, #[serde(rename = "url", default, skip_serializing_if = "Option::is_none",)] @@ -45,7 +45,7 @@ pub struct ContentTestSuite { #[serde(deny_unknown_fields)] pub struct ContentEnvironment { #[serde(rename = "id",)] - pub id: String, + pub id: crate::Id, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } diff --git a/cdevents-sdk/src/generated/testsuiterun_started.rs b/cdevents-sdk/src/generated/testsuiterun_started.rs index f735c42..9c27a7d 100644 --- a/cdevents-sdk/src/generated/testsuiterun_started.rs +++ b/cdevents-sdk/src/generated/testsuiterun_started.rs @@ -31,7 +31,7 @@ pub struct ContentTrigger { #[serde(deny_unknown_fields)] pub struct ContentTestSuite { #[serde(rename = "id",)] - pub id: String, + pub id: crate::Id, #[serde(rename = "name", default, skip_serializing_if = "Option::is_none",)] pub name: Option, #[serde(rename = "uri", default, skip_serializing_if = "Option::is_none",)] @@ -45,7 +45,7 @@ pub struct ContentTestSuite { #[serde(deny_unknown_fields)] pub struct ContentEnvironment { #[serde(rename = "id",)] - pub id: String, + pub id: crate::Id, #[serde(rename = "source", default, skip_serializing_if = "Option::is_none",)] pub source: Option, } diff --git a/cdevents-sdk/src/id.rs b/cdevents-sdk/src/id.rs new file mode 100644 index 0000000..ccebdc6 --- /dev/null +++ b/cdevents-sdk/src/id.rs @@ -0,0 +1,88 @@ +use std::{fmt::{Display, Formatter}, str::FromStr}; + +use serde::{Deserialize, Serialize}; + +pub type Id = NonEmptyString; +pub type Name = NonEmptyString; + +/// A non-empty string. +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)] +pub struct NonEmptyString(String); + +impl NonEmptyString { + pub fn as_str(&self) -> &str { + &self.0.as_str() + } +} + +impl Default for NonEmptyString { + fn default() -> Self { + NonEmptyString("00000000-0000-0000-0000-000000000000".to_owned()) + } +} + +impl From for String { + fn from(id: NonEmptyString) -> Self { + id.0 + } +} +impl TryFrom for NonEmptyString { + type Error = crate::Error; + + fn try_from(value: String) -> Result { + if value.is_empty() { + return Err(crate::Error::EmptyString("id")) + } + Ok(Self(value)) + } +} + +impl TryFrom<&str> for NonEmptyString { + type Error = crate::Error; + + fn try_from(value: &str) -> Result { + if value.is_empty() { + return Err(crate::Error::EmptyString("id")) + } + Ok(Self(value.to_owned())) + } +} + +impl FromStr for NonEmptyString { + type Err = crate::Error; + + fn from_str(s: &str) -> Result { + Self::try_from(s) + } +} + +impl Display for NonEmptyString { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.0) + } +} + +impl From<&NonEmptyString> for String { + fn from(id: &NonEmptyString) -> Self { + id.0.clone() + } +} + +impl AsRef for NonEmptyString { + fn as_ref(&self) -> &str { + &self.0 + } +} + +#[cfg(feature = "testkit")] +impl<> proptest::arbitrary::Arbitrary for NonEmptyString { + type Parameters = (); + type Strategy = proptest::strategy::BoxedStrategy; + + fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy { + use proptest::prelude::*; + "\\PC+".prop_map(|id| + id.try_into().expect("generate valid id") + ).boxed() + } +} \ No newline at end of file diff --git a/cdevents-sdk/src/lib.rs b/cdevents-sdk/src/lib.rs index 819f4f8..76887c5 100644 --- a/cdevents-sdk/src/lib.rs +++ b/cdevents-sdk/src/lib.rs @@ -8,12 +8,14 @@ mod context; pub mod cloudevents; mod error; mod generated; +mod id; pub(crate) mod serde; mod subject; mod uri; mod uri_reference; pub use cdevent::*; +pub use id::*; pub(crate) use context::*; pub use error::*; pub use generated::*; diff --git a/cdevents-sdk/src/subject.rs b/cdevents-sdk/src/subject.rs index c58f0f0..f120a4f 100644 --- a/cdevents-sdk/src/subject.rs +++ b/cdevents-sdk/src/subject.rs @@ -2,7 +2,7 @@ use std::str::FromStr; use serde::{Deserialize, Serialize}; -use crate::{Content, UriReference}; +use crate::{Content, Id, UriReference}; /// see #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] @@ -11,7 +11,7 @@ pub struct Subject { #[serde(rename = "content")] content: Content, #[serde(rename = "id")] - id: String, + id: Id, #[serde( rename = "source", default, @@ -24,13 +24,12 @@ pub struct Subject { impl Subject { /// see - pub fn id(&self) -> &str { + pub fn id(&self) -> &Id { &self.id } - pub fn with_id(mut self, id: T) -> Self - where T: Into { - self.id = id.into(); + pub fn with_id(mut self, id: Id) -> Self { + self.id = id; self } @@ -60,7 +59,8 @@ impl Subject { id: json["id"] .as_str() .ok_or_else(|| serde::de::Error::missing_field("id"))? - .to_string(), + .try_into() + .map_err(serde::de::Error::custom)?, ty: json["type"] .as_str() .ok_or_else(|| serde::de::Error::missing_field("type"))? @@ -79,10 +79,13 @@ impl Subject { impl From for Subject where T: Into{ fn from(content: T) -> Self { let content = content.into(); - let ty = content.ty().to_owned(); + let ty = crate::extract_subject_predicate(content.ty()) + .map(|(s, _)| s) + .unwrap_or("unknown") + .to_owned(); Self { content, - id: String::new(), + id: Id::default(), source: None, ty, } @@ -97,7 +100,7 @@ impl<> proptest::arbitrary::Arbitrary for Subject { use proptest::prelude::*; ( any::(), - "\\PC*", + any::(), any::>(), ).prop_map(|(content, id, source)| { let mut subject = Subject::from(content).with_id(id); diff --git a/cdevents-sdk/src/uri_reference.rs b/cdevents-sdk/src/uri_reference.rs index 0af5fb9..53b48d7 100644 --- a/cdevents-sdk/src/uri_reference.rs +++ b/cdevents-sdk/src/uri_reference.rs @@ -75,7 +75,7 @@ impl<> proptest::arbitrary::Arbitrary for UriReference { fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy { use proptest::prelude::*; (prop_oneof![ - "/[a-z_\\-/]*".prop_map(|s| UriReference::from_str(&s).unwrap()), + "\\/[a-z_\\-\\/]+".prop_map(|s| UriReference::from_str(&s).unwrap()), Just("https://example.com/").prop_map(|s| UriReference::from_str(&s).unwrap()), ]).boxed() } diff --git a/cdevents-sdk/tests/specs.rs b/cdevents-sdk/tests/specs.rs index be3d313..e2b6e70 100644 --- a/cdevents-sdk/tests/specs.rs +++ b/cdevents-sdk/tests/specs.rs @@ -32,7 +32,7 @@ fn for_each_example(#[files("../cdevents-spec/examples/*.json")] path: PathBuf) fn check_against_schema(json: &serde_json::Value, ty: &str) { let (subject, predicate) = cdevents_sdk::extract_subject_predicate(ty).expect("valid type: {ty}"); - let schemapath = format!("../cdevents-spec/schemas/{subject}{predicate}.json"); + let schemapath = format!("../cdevents-spec/schemas/{subject}{predicate}.json").to_lowercase(); //TODO optimize to not recompile a previously read schema let mut schemas = Schemas::new(); let mut compiler = Compiler::new(); diff --git a/generator/src/main.rs b/generator/src/main.rs index 2cf0425..325e56a 100644 --- a/generator/src/main.rs +++ b/generator/src/main.rs @@ -46,18 +46,15 @@ fn main() -> Result<()> { if let Some(extension) = path.extension() { if extension == "json" { let json: Value = serde_json::from_str(&std::fs::read_to_string(&path)?)?; - let (rust_module, context_type, code) = generate_variant(&hbs, json) + let (variant_info, code) = generate_variant(&hbs, json) .with_context(|| format!("failed to generate variant on {:?}", &path))?; let file = settings .dest - .join(cruet::to_snake_case(&rust_module)) + .join(cruet::to_snake_case(&variant_info.rust_module)) .with_extension("rs"); //TODO use a formatter like https://crates.io/crates/prettyplease? fs::write(file, code)?; - variants.push(VariantInfo { - context_type, - rust_module, - }); + variants.push(variant_info); } } } @@ -71,7 +68,7 @@ fn main() -> Result<()> { Ok(()) } -fn generate_variant(hbs: &Handlebars, jsonschema: Value) -> Result<(String, String, String)> { +fn generate_variant(hbs: &Handlebars, jsonschema: Value) -> Result<(VariantInfo, String)> { // let id = jsonschema["$id"] // .as_str() // .ok_or(anyhow!("$id not found or not a string")) @@ -90,11 +87,23 @@ fn generate_variant(hbs: &Handlebars, jsonschema: Value) -> Result<(String, Stri .to_string(); let fragments = context_type.split('.').collect::>(); - let module_name = format!("{}_{}", fragments[2], fragments[3]).to_snake_case(); + let rust_module = format!("{}_{}", fragments[2], fragments[3]).to_snake_case(); + let predicate = fragments[3].to_owned(); + // due to inconstency in case/format the subject could be not be extracted from the context.type (ty), jsonshema $id, spec filename (shema, examples) + let subject = jsonschema["properties"]["subject"]["properties"]["type"]["default"] + .as_str() + .unwrap_or_default() + .to_string(); let data = build_data_for_variants(jsonschema); let code = hbs.render("variant", &data)?; - Ok((module_name.to_string(), context_type, code)) + let variant_info = VariantInfo { + context_type, + rust_module, + subject, + predicate, + }; + Ok((variant_info, code)) } fn generate_module(hbs: &Handlebars, variants: &[VariantInfo]) -> Result<(String, String)> { @@ -133,6 +142,8 @@ struct TypeInfo { struct VariantInfo { context_type: String, rust_module: String, + subject: String, + predicate: String, } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -183,12 +194,22 @@ fn collect_structs( // type_declaration: "http::Uri".to_string(), // serde_with: Some("crate::serde::uri".to_string()), // }, - //TODO manage enum _ => match json_definition["enum"].as_array() { - None => TypeInfo { - type_declaration: "String".to_string(), - ..Default::default() - }, + None => { + let type_declaration = + match (field_names.last(), json_definition["minLength"].as_i64()) { + (Some(&"id"), _) => "crate::Id", + (Some(&"name"), Some(1)) => "crate::Name", + (Some(x), Some(1)) if x.ends_with("Id") => "crate::Id", + (Some(x), Some(1)) if x.ends_with("Name") => "crate::Name", + _ => "String", + } + .to_string(); + TypeInfo { + type_declaration, + ..Default::default() + } + } Some(values) => { let default_value = json_definition["default"].as_str(); let values = values diff --git a/generator/templates/mod.hbs b/generator/templates/mod.hbs index e8b2625..51f4665 100644 --- a/generator/templates/mod.hbs +++ b/generator/templates/mod.hbs @@ -45,14 +45,32 @@ impl Content { } } - pub fn subject_predicate(&self) -> (&'static str, &'static str){ - let mut split = self.ty().split('.'); - ( - split.nth(2).expect("fargment 2 of ty should always exists"), - split.nth(3).expect("fargment 3 of ty should always exists") - ) + pub fn subject(&self) -> &'static str { + match self { + {{#each variants }} + Self::{{to_class_case this.rust_module}}(_) => "{{ this.subject }}", + {{/each}} + } } + pub fn predicate(&self) -> &'static str { + match self { + {{#each variants }} + Self::{{to_class_case this.rust_module}}(_) => "{{ this.predicate }}", + {{/each}} + } + } +} + +// due to inconstency in case/format the subject could be not be extracted from the context.type (ty), jsonshema $id, spec filename (shema, examples) +pub fn extract_subject_predicate(ty: &str) -> Option<(&str, &str)>{ + // let mut split = ty.split('.'); + match ty { + {{#each variants }} + {{to_screaming_snake_case this.rust_module}} => Some(("{{ this.subject }}", "{{ this.predicate }}")), + {{/each}} + _ => None, + } } {{#each variants }} @@ -77,3 +95,15 @@ impl<> proptest::arbitrary::Arbitrary for Content { ].boxed() } } + +// #[cfg(test)] +// mod tests { +// use super::*; +// +// #[test] +// fn test_true() { +// {{#each variants }} +// assert_eq!(extract_subject_predicate({{to_screaming_snake_case this.rust_module}}), Some(("{{ this.subject }}","{{ this.predicate }}"))); +// {{/each}} +// } +// } \ No newline at end of file From 799cd269cdd1ae7634637389327e76a8705190a2 Mon Sep 17 00:00:00 2001 From: David Bernard Date: Tue, 30 Jan 2024 20:19:34 +0100 Subject: [PATCH 28/34] build: change clipy configuration to support workspace and features - avoid clippy genarte wrong warning about useless stuff - apply some clippy recommandation Signed-off-by: David Bernard --- Makefile | 2 +- cdevents-sdk/src/id.rs | 2 +- cdevents-sdk/src/uri_reference.rs | 2 +- cdevents-sdk/tests/specs.rs | 8 +++----- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index a5d16a5..b0ef6b1 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,7 @@ lint_cargo_deny: --config=tools/cargo-deny/deny.toml lint_cargo_clippy: - cargo clippy --no-deps --all-targets -- -D warnings + cargo clippy --workspace --all-features --no-deps --all-targets -- --deny warnings lint_cargo_toml_fmt_files: dprint fmt --config=tools/dprint/dprint.json diff --git a/cdevents-sdk/src/id.rs b/cdevents-sdk/src/id.rs index ccebdc6..49e3d51 100644 --- a/cdevents-sdk/src/id.rs +++ b/cdevents-sdk/src/id.rs @@ -11,7 +11,7 @@ pub struct NonEmptyString(String); impl NonEmptyString { pub fn as_str(&self) -> &str { - &self.0.as_str() + self.0.as_str() } } diff --git a/cdevents-sdk/src/uri_reference.rs b/cdevents-sdk/src/uri_reference.rs index 53b48d7..11385ce 100644 --- a/cdevents-sdk/src/uri_reference.rs +++ b/cdevents-sdk/src/uri_reference.rs @@ -76,7 +76,7 @@ impl<> proptest::arbitrary::Arbitrary for UriReference { use proptest::prelude::*; (prop_oneof![ "\\/[a-z_\\-\\/]+".prop_map(|s| UriReference::from_str(&s).unwrap()), - Just("https://example.com/").prop_map(|s| UriReference::from_str(&s).unwrap()), + Just("https://example.com/").prop_map(|s| UriReference::from_str(s).unwrap()), ]).boxed() } } diff --git a/cdevents-sdk/tests/specs.rs b/cdevents-sdk/tests/specs.rs index e2b6e70..06cc5ec 100644 --- a/cdevents-sdk/tests/specs.rs +++ b/cdevents-sdk/tests/specs.rs @@ -38,14 +38,12 @@ fn check_against_schema(json: &serde_json::Value, ty: &str) { let mut compiler = Compiler::new(); let sch_index = compiler.compile(&schemapath, &mut schemas); if let Err(err) = sch_index { - assert!(false, "{err:#}"); - return; // to allow sch_index.unwrap() + panic!("{err:#}"); //like a assert(false,...) } let sch_index = sch_index.unwrap(); - let result = schemas.validate(&json, sch_index); + let result = schemas.validate(json, sch_index); if let Err(err) = result { - assert!(false, "{err}"); - return; + panic!("{err}"); } } From a7ca3cce7671219b5aceff59ecbe77789129ef02 Mon Sep 17 00:00:00 2001 From: David Bernard Date: Tue, 30 Jan 2024 21:28:51 +0100 Subject: [PATCH 29/34] build: exclude generator from crago-deny scope Signed-off-by: David Bernard --- Makefile | 4 +++- generator/Cargo.toml | 2 +- tools/cargo-deny/deny.toml | 11 ++++++----- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index b0ef6b1..94213e1 100644 --- a/Makefile +++ b/Makefile @@ -32,7 +32,9 @@ lint_cargo_fmt_check: cargo fmt --all -- --check lint_cargo_deny: - cargo deny --all-features \ + cargo deny --workspace --all-features \ + --exclude-dev \ + --exclude generator \ check licenses advisories \ --config=tools/cargo-deny/deny.toml diff --git a/generator/Cargo.toml b/generator/Cargo.toml index fdddb63..c66eb9d 100644 --- a/generator/Cargo.toml +++ b/generator/Cargo.toml @@ -5,7 +5,7 @@ version.workspace = true authors.workspace = true edition.workspace = true license.workspace = true -publish.workspace = true +publish = false repository.workspace = true description = "generate cdevents type from json schema on cdevents-spec" diff --git a/tools/cargo-deny/deny.toml b/tools/cargo-deny/deny.toml index b6ceb5b..94f7eec 100644 --- a/tools/cargo-deny/deny.toml +++ b/tools/cargo-deny/deny.toml @@ -9,13 +9,14 @@ wildcards = "deny" unlicensed = "deny" copyleft = "deny" confidence-threshold = 0.95 -allow = [ - "Apache-2.0", - "MIT", - "BSD-2-Clause", -] +allow = ["Apache-2.0", "MIT", "BSD-2-Clause", "Unicode-DFS-2016"] exceptions = [] +# The unpublished packages (generator) would be ignored now +# FIXME the generator is excluded explicitly (see Makefile), I don't know why this is not working +[licenses.private] +ignore = true + [advisories] unmaintained = "deny" vulnerability = "deny" From 41480b11479ee1b0e55d1042f001a9d8bdf2e39b Mon Sep 17 00:00:00 2001 From: David Bernard Date: Tue, 30 Jan 2024 21:49:04 +0100 Subject: [PATCH 30/34] ci: run tests and fix clippy call - clippy & tests need git submodules content Signed-off-by: David Bernard --- .github/workflows/linter.yaml | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/.github/workflows/linter.yaml b/.github/workflows/linter.yaml index 6dbd883..8799abf 100644 --- a/.github/workflows/linter.yaml +++ b/.github/workflows/linter.yaml @@ -34,19 +34,23 @@ jobs: uses: wagoid/commitlint-github-action@v5.4.5 lint_check: - name: Rust - lint_${{ matrix.lint_projects }} + name: Rust - ${{ matrix.tasks }} runs-on: ubuntu-latest strategy: fail-fast: false matrix: - lint_projects: - - cargo_fmt_check - - cargo_toml_fmt_files - - cargo_clippy - - cargo_deny + tasks: + - lint_cargo_fmt_check + - lint_cargo_toml_fmt_files + - lint_cargo_clippy + - lint_cargo_deny + - test steps: - name: Run the checkout command uses: actions/checkout@v4 + with: + fetch-depth: 0 + submodules: "true" - name: Install rust toolchain uses: actions-rust-lang/setup-rust-toolchain@v1 with: @@ -66,8 +70,8 @@ jobs: ~/.cargo/git/db/ key: ${{ runner.os }}-sdk-rust-${{ hashFiles('**/Cargo.lock') }} restore-keys: | - ${{ runner.os }}-sdk-rust- + ${{ runner.os }}-sdk-rust- - name: Check cargo version run: cargo --version - - name: Run lint ${{ matrix.lint_projects }} - run: make -f Makefile lint_${{ matrix.lint_projects }} + - name: Run lint ${{ matrix.tasks }} + run: make -f Makefile ${{ matrix.tasks }} From 25e2dcc4eecfb12cc5e2952f2a0328af92eea5f1 Mon Sep 17 00:00:00 2001 From: David Bernard Date: Tue, 30 Jan 2024 21:52:58 +0100 Subject: [PATCH 31/34] ci: disable test (until fix) Signed-off-by: David Bernard --- .github/workflows/linter.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/linter.yaml b/.github/workflows/linter.yaml index 8799abf..ce1ebd3 100644 --- a/.github/workflows/linter.yaml +++ b/.github/workflows/linter.yaml @@ -44,7 +44,7 @@ jobs: - lint_cargo_toml_fmt_files - lint_cargo_clippy - lint_cargo_deny - - test + # - test # disable test until setup of nextest steps: - name: Run the checkout command uses: actions/checkout@v4 @@ -73,5 +73,5 @@ jobs: ${{ runner.os }}-sdk-rust- - name: Check cargo version run: cargo --version - - name: Run lint ${{ matrix.tasks }} + - name: Run ${{ matrix.tasks }} run: make -f Makefile ${{ matrix.tasks }} From 9bc4e33574a62fdd6dd701f1ba9389258acc0276 Mon Sep 17 00:00:00 2001 From: David Bernard Date: Thu, 1 Feb 2024 15:15:45 +0100 Subject: [PATCH 32/34] ci(revert): restore `lint_check` to lint actions only Signed-off-by: David Bernard --- .github/workflows/linter.yaml | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/.github/workflows/linter.yaml b/.github/workflows/linter.yaml index ce1ebd3..61a153b 100644 --- a/.github/workflows/linter.yaml +++ b/.github/workflows/linter.yaml @@ -34,17 +34,16 @@ jobs: uses: wagoid/commitlint-github-action@v5.4.5 lint_check: - name: Rust - ${{ matrix.tasks }} + name: Rust - lint_${{ matrix.lint_projects }} runs-on: ubuntu-latest strategy: fail-fast: false matrix: - tasks: - - lint_cargo_fmt_check - - lint_cargo_toml_fmt_files - - lint_cargo_clippy - - lint_cargo_deny - # - test # disable test until setup of nextest + lint_projects: + - cargo_fmt_check + - cargo_toml_fmt_files + - cargo_clippy + - cargo_deny steps: - name: Run the checkout command uses: actions/checkout@v4 @@ -73,5 +72,5 @@ jobs: ${{ runner.os }}-sdk-rust- - name: Check cargo version run: cargo --version - - name: Run ${{ matrix.tasks }} - run: make -f Makefile ${{ matrix.tasks }} + - name: Run ${{ matrix.lint_projects }} + run: make -f Makefile lint_${{ matrix.lint_projects }} From 7ead28c63dd1a6410d31cc0d0a07af453b868765 Mon Sep 17 00:00:00 2001 From: David Bernard Date: Thu, 1 Feb 2024 17:55:36 +0100 Subject: [PATCH 33/34] refactor: remove & clean Signed-off-by: David Bernard --- .mega-linter.yml | 40 ---------------------------------------- README.md | 6 +----- generator/src/main.rs | 4 ---- 3 files changed, 1 insertion(+), 49 deletions(-) delete mode 100644 .mega-linter.yml diff --git a/.mega-linter.yml b/.mega-linter.yml deleted file mode 100644 index bbfe908..0000000 --- a/.mega-linter.yml +++ /dev/null @@ -1,40 +0,0 @@ -# Configuration file for MegaLinter -# See all available variables at https://megalinter.github.io/configuration/ and in linters documentation - -APPLY_FIXES: none # all, none, or list of linter keys -# ENABLE: # If you use ENABLE variable, all other languages/formats/tooling-formats will be disabled by default -# ENABLE_LINTERS: # If you use ENABLE_LINTERS variable, all other linters will be disabled by default -DISABLE: - - COPYPASTE # Comment to enable checks of excessive copy-pastes - - SPELL # Comment to enable checks of spelling mistakes -DISABLE_LINTERS: - - DOCKERFILE_DOCKERFILELINT - - MARKDOWN_MARKDOWN_LINK_CHECK - - REPOSITORY_CHECKOV # unstable randomly failed (false negative) on generated k8s manifest - - REPOSITORY_DEVSKIM # issue with "git config --global --add safe.directory ..." - - REPOSITORY_GIT_DIFF - - REPOSITORY_GRYPE - - REPOSITORY_KICS - - REPOSITORY_SYFT - - REPOSITORY_TRUFFLEHOG # too long to search for secret - - RUST_CLIPPY # run via an other way, and current version doesn't support `--deny ... --allow ...` - - SQL_TSQLLINT # "You must install or update .NET to run this application." -SHOW_ELAPSED_TIME: true -FILEIO_REPORTER: false -# DISABLE_ERRORS: true # Uncomment if you want MegaLinter to detect errors but not block CI to pass -FILTER_REGEX_EXCLUDE: "(generated)|(megalinter-reports)|(cdevents-spec.*)|(.gitmodules)|(.sqlx)|(\\.lock)|(\\.ndjson)|(\\.pdf)|(\\.csv)|(\\.zip)|(\\.tar)|(\\.ipynb)|(license.*)|(LICENSE.*)" -SPELL_FILTER_REGEX_INCLUDE: '\\.md$' -PRINT_ALPACA: false -REPOSITORY_SECRETLINT_ARGUMENTS: - - --secretlintignore - - .gitignore -REPOSITORY_TRIVY_ARGUMENTS: - - --skip-dirs - - "cdevents-spec" -RUST_CLIPPY_ARGUMENTS: - - --workspace - - --all-features - - --all-targets - # - --deny warnings - # - --allow deprecated - # - --allow unknown-lints diff --git a/README.md b/README.md index 99a0418..fe53265 100644 --- a/README.md +++ b/README.md @@ -58,11 +58,7 @@ fn main() -> Result<(), Box> { } ``` -See the [CloudEvents](https://github.com/cloudevents/sdk-go#send-your-first-cloudevent) docs as well. - -## Contributing - -If you would like to contribute, see our [development](DEVELOPMENT.md) guide. +See the [CloudEvents](https://github.com/cloudevents/sdk-rust) docs as well. ## References diff --git a/generator/src/main.rs b/generator/src/main.rs index 325e56a..85e50fb 100644 --- a/generator/src/main.rs +++ b/generator/src/main.rs @@ -190,10 +190,6 @@ fn collect_structs( type_declaration: "crate::Uri".to_string(), serde_with: None, }, - // Some("uri") => TypeInfo { - // type_declaration: "http::Uri".to_string(), - // serde_with: Some("crate::serde::uri".to_string()), - // }, _ => match json_definition["enum"].as_array() { None => { let type_declaration = From 6c72ab9b89810612b1110e583a5b14ad1378d685 Mon Sep 17 00:00:00 2001 From: David Bernard Date: Thu, 1 Feb 2024 17:58:24 +0100 Subject: [PATCH 34/34] build: add check that generated code is committed Signed-off-by: David Bernard --- Makefile | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 94213e1..ca42967 100644 --- a/Makefile +++ b/Makefile @@ -13,12 +13,14 @@ build_%: check: cargo hack check --each-feature + check_no_std: cargo --version cargo check --target thumbv7em-none-eabihf -p ockam --no-default-features --features 'no_std alloc software_vault' # no_std example project cd examples/rust/example_projects/no_std cargo check --example hello + check_cargo_update: cargo --version # TODO: uncomment when tauri version is updated @@ -26,6 +28,10 @@ check_cargo_update: # cargo update # cargo check +# no uncommitted changes on sdk (generated code) +check_no_uncommitted_changes_on_sdk: + git diff --exit-code cdevents-sdk + lint: lint_cargo_fmt_check lint_cargo_deny lint_cargo_clippy lint_cargo_fmt_check: @@ -59,6 +65,7 @@ test: .PHONY: generate \ - check test \ + check check_no_uncommitted_changes_on_sdk \ + test \ lint lint_cargo_fmt_check lint_cargo_deny lint_cargo_clippy lint_cargo_toml_files lint_cargo_readme lint_cargo_readme_% lint_cargo_toml_files \ clean clean_% very_clean format