From c7d9599ca2dfb4d15289107836df8bb196e39558 Mon Sep 17 00:00:00 2001 From: Laura Trotta <153528055+l-trotta@users.noreply.github.com> Date: Tue, 1 Jul 2025 11:01:32 +0200 Subject: [PATCH] add branch option to cli (#4722) (cherry picked from commit fd09485e02fa05766590abdace71bc5e23d485f6) --- compiler-rs/clients_schema/src/lib.rs | 1 - compiler-rs/clients_schema_to_openapi/src/cli.rs | 7 +++++++ compiler-rs/clients_schema_to_openapi/src/lib.rs | 1 + compiler-rs/clients_schema_to_openapi/src/schemas.rs | 9 ++------- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/compiler-rs/clients_schema/src/lib.rs b/compiler-rs/clients_schema/src/lib.rs index d5b01dce78..5590669bf7 100644 --- a/compiler-rs/clients_schema/src/lib.rs +++ b/compiler-rs/clients_schema/src/lib.rs @@ -1003,7 +1003,6 @@ pub struct UrlTemplate { pub struct ModelInfo { pub title: String, pub license: License, - pub version: Option, } #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/compiler-rs/clients_schema_to_openapi/src/cli.rs b/compiler-rs/clients_schema_to_openapi/src/cli.rs index fe6abf927f..f981db38b8 100644 --- a/compiler-rs/clients_schema_to_openapi/src/cli.rs +++ b/compiler-rs/clients_schema_to_openapi/src/cli.rs @@ -24,6 +24,10 @@ pub struct Cli { #[argh(option)] pub namespace: Vec, + /// the branch to generate [9.0, 8.19, current, etc... - default = current] + #[argh(option)] + pub branch: Option, + /// add enum descriptions to property descriptions [default = true] #[argh(switch)] pub lift_enum_descriptions: bool, @@ -72,9 +76,12 @@ impl From for Configuration { SchemaFlavor::Serverless => Some(Flavor::Serverless), SchemaFlavor::Stack => Some(Flavor::Stack), }; + + let branch = cli.branch; Configuration { flavor, + branch, lift_enum_descriptions: cli.lift_enum_descriptions, merge_multipath_endpoints: cli.merge_multipath_endpoints, multipath_redirects: cli.multipath_redirects, diff --git a/compiler-rs/clients_schema_to_openapi/src/lib.rs b/compiler-rs/clients_schema_to_openapi/src/lib.rs index b311cfce0d..b982e2674b 100644 --- a/compiler-rs/clients_schema_to_openapi/src/lib.rs +++ b/compiler-rs/clients_schema_to_openapi/src/lib.rs @@ -32,6 +32,7 @@ use crate::components::TypesAndComponents; pub struct Configuration { pub flavor: Option, pub namespaces: Option>, + pub branch: Option, /// If a property value is an enumeration, the description of possible values will be copied in the /// property's description (also works for arrays of enums). diff --git a/compiler-rs/clients_schema_to_openapi/src/schemas.rs b/compiler-rs/clients_schema_to_openapi/src/schemas.rs index 0a1ff021fd..02f6674217 100644 --- a/compiler-rs/clients_schema_to_openapi/src/schemas.rs +++ b/compiler-rs/clients_schema_to_openapi/src/schemas.rs @@ -209,19 +209,14 @@ impl<'a> TypesAndComponents<'a> { pub fn convert_external_docs(&self, obj: &impl clients_schema::ExternalDocument) -> Option { // FIXME: does the model contain resolved doc_id? obj.ext_doc_url().map(|url| { - let branch: &str = self - .model - .info - .as_ref() - .and_then(|i| i.version.as_deref()) - .unwrap_or("current"); + let branch = self.config.branch.clone(); let mut extensions: IndexMap = Default::default(); if let Some(previous_version_doc_url) = obj.ext_previous_version_doc_url() { extensions.insert("x-previousVersionUrl".to_string(), serde_json::json!(previous_version_doc_url)); } ExternalDocumentation { description: None, - url: url.trim().replace("{branch}", branch), + url: url.trim().replace("{branch}", &branch.unwrap_or("current".to_string())), extensions, } })