From e11c74ce6a72a6dff1a5d92652bdd5a9afac179e Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 3 Jul 2026 15:55:27 +0200 Subject: [PATCH 1/2] Remove unnecessary &mut --- src/api/mod.rs | 4 ++-- src/api/types.rs | 2 +- src/cli_v1.rs | 2 +- src/codesamples.rs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/api/mod.rs b/src/api/mod.rs index 979cf97..f8f529d 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -27,7 +27,7 @@ pub struct Api { impl Api { pub fn new( paths: openapi::Paths, - components: &mut openapi::Components, + components: openapi::Components, webhooks: &[String], include_mode: IncludeMode, excluded_operations: &BTreeSet, @@ -41,7 +41,7 @@ impl Api { )?; let types = types::from_referenced_components( &resources, - &mut components.schemas, + components.schemas, webhooks, include_mode, ); diff --git a/src/api/types.rs b/src/api/types.rs index 4daebec..de70181 100644 --- a/src/api/types.rs +++ b/src/api/types.rs @@ -23,7 +23,7 @@ pub type Types = BTreeMap; pub(crate) fn from_referenced_components( res: &Resources, - schemas: &mut IndexMap, + mut schemas: IndexMap, webhooks: &[String], include_mode: IncludeMode, ) -> Types { diff --git a/src/cli_v1.rs b/src/cli_v1.rs index b594232..671f226 100644 --- a/src/cli_v1.rs +++ b/src/cli_v1.rs @@ -120,7 +120,7 @@ pub fn run_cli_v1_main() -> anyhow::Result<()> { let webhooks = get_webhooks(&spec); Api::new( spec.paths.context("found no endpoints in input spec")?, - &mut spec.components.unwrap_or_default(), + spec.components.unwrap_or_default(), &webhooks, args.include_mode, &excluded_operations, diff --git a/src/codesamples.rs b/src/codesamples.rs index f2ca0ca..b5786be 100644 --- a/src/codesamples.rs +++ b/src/codesamples.rs @@ -213,7 +213,7 @@ pub async fn generate_codesamples( .paths .clone() .context("found no endpoints in input spec")?, - &mut openapi_spec.components.clone().unwrap_or_default(), + openapi_spec.components.clone().unwrap_or_default(), &[], IncludeMode::Public, &excluded_operation_ids, From 69307c20a49ce4c76e6ae8a54483777b1176e917 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Fri, 3 Jul 2026 15:57:20 +0200 Subject: [PATCH 2/2] Make webhook inclusion independent of (operation) include-mode --- src/api/mod.rs | 7 +------ src/api/types.rs | 18 +++++------------- src/cli_v1.rs | 15 +++++++++++---- 3 files changed, 17 insertions(+), 23 deletions(-) diff --git a/src/api/mod.rs b/src/api/mod.rs index f8f529d..8790e85 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -39,12 +39,7 @@ impl Api { excluded_operations, specified_operations, )?; - let types = types::from_referenced_components( - &resources, - components.schemas, - webhooks, - include_mode, - ); + let types = types::from_referenced_components(&resources, components.schemas, webhooks); Ok(Self { resources, types }) } diff --git a/src/api/types.rs b/src/api/types.rs index de70181..f708943 100644 --- a/src/api/types.rs +++ b/src/api/types.rs @@ -9,7 +9,7 @@ use anyhow::{Context as _, bail, ensure}; use indexmap::IndexMap; use serde::{Deserialize, Serialize}; -use crate::{JsonValue, cli_v1::IncludeMode, utils::get_properties}; +use crate::{JsonValue, utils::get_properties}; use super::{ get_schema_name, @@ -25,15 +25,10 @@ pub(crate) fn from_referenced_components( res: &Resources, mut schemas: IndexMap, webhooks: &[String], - include_mode: IncludeMode, ) -> Types { - let mut referenced_components: Vec<&str> = match include_mode { - IncludeMode::Public | IncludeMode::PublicAndInternal | IncludeMode::Internal => { - webhooks.iter().map(|s| &**s).collect() - } - IncludeMode::OnlySpecified => vec![], - }; - referenced_components.extend(resources::referenced_components(res)); + let components: Vec<&str> = resources::referenced_components(res) + .chain(webhooks.iter().map(String::as_str)) + .collect(); let mut types = BTreeMap::new(); let mut add_type = |schema_name: &str, extra_components: &mut BTreeSet<_>| { @@ -58,10 +53,7 @@ pub(crate) fn from_referenced_components( } }; - let mut extra_components: BTreeSet<_> = referenced_components - .into_iter() - .map(ToOwned::to_owned) - .collect(); + let mut extra_components: BTreeSet<_> = components.into_iter().map(ToOwned::to_owned).collect(); while let Some(c) = extra_components.pop_first() { add_type(&c, &mut extra_components); } diff --git a/src/cli_v1.rs b/src/cli_v1.rs index 671f226..5f11fa9 100644 --- a/src/cli_v1.rs +++ b/src/cli_v1.rs @@ -28,14 +28,17 @@ struct CliArgs { #[arg(global = true, long, value_enum, default_value_t = IncludeMode::Public)] include_mode: IncludeMode, - /// Ignore a specified operation id + /// Include webhooks in component models. + #[arg(global = true, long)] + include_webhooks: bool, + + /// Ignore a specified operation id. #[arg(global = true, short, long = "exclude-op-id")] excluded_operations: Vec, - /// Include specified operations + /// Include specified operations. /// /// Use this option, to run the codegen with a limited set of operations. - /// Op webhook models will be excluded from the generation #[arg(global = true, long = "include-op-id")] specified_operations: Vec, @@ -117,7 +120,11 @@ pub fn run_cli_v1_main() -> anyhow::Result<()> { let spec: OpenApi = serde_json::from_str(&input_file_contents) .context("failed to parse OpenAPI spec")?; - let webhooks = get_webhooks(&spec); + let webhooks = if args.include_webhooks { + get_webhooks(&spec) + } else { + vec![] + }; Api::new( spec.paths.context("found no endpoints in input spec")?, spec.components.unwrap_or_default(),