Skip to content

Commit a482034

Browse files
add branch option to cli (#4722) (#4735)
(cherry picked from commit fd09485) Co-authored-by: Laura Trotta <[email protected]>
1 parent a1fcb39 commit a482034

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

compiler-rs/clients_schema/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,6 @@ pub struct UrlTemplate {
10031003
pub struct ModelInfo {
10041004
pub title: String,
10051005
pub license: License,
1006-
pub version: Option<String>,
10071006
}
10081007

10091008
#[derive(Debug, Clone, Serialize, Deserialize)]

compiler-rs/clients_schema_to_openapi/src/cli.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ pub struct Cli {
2424
#[argh(option)]
2525
pub namespace: Vec<String>,
2626

27+
/// the branch to generate [9.0, 8.19, current, etc... - default = current]
28+
#[argh(option)]
29+
pub branch: Option<String>,
30+
2731
/// add enum descriptions to property descriptions [default = true]
2832
#[argh(switch)]
2933
pub lift_enum_descriptions: bool,
@@ -72,9 +76,12 @@ impl From<Cli> for Configuration {
7276
SchemaFlavor::Serverless => Some(Flavor::Serverless),
7377
SchemaFlavor::Stack => Some(Flavor::Stack),
7478
};
79+
80+
let branch = cli.branch;
7581

7682
Configuration {
7783
flavor,
84+
branch,
7885
lift_enum_descriptions: cli.lift_enum_descriptions,
7986
merge_multipath_endpoints: cli.merge_multipath_endpoints,
8087
multipath_redirects: cli.multipath_redirects,

compiler-rs/clients_schema_to_openapi/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use crate::components::TypesAndComponents;
3232
pub struct Configuration {
3333
pub flavor: Option<Flavor>,
3434
pub namespaces: Option<Vec<String>>,
35+
pub branch: Option<String>,
3536

3637
/// If a property value is an enumeration, the description of possible values will be copied in the
3738
/// property's description (also works for arrays of enums).

compiler-rs/clients_schema_to_openapi/src/schemas.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,19 +209,14 @@ impl<'a> TypesAndComponents<'a> {
209209
pub fn convert_external_docs(&self, obj: &impl clients_schema::ExternalDocument) -> Option<ExternalDocumentation> {
210210
// FIXME: does the model contain resolved doc_id?
211211
obj.ext_doc_url().map(|url| {
212-
let branch: &str = self
213-
.model
214-
.info
215-
.as_ref()
216-
.and_then(|i| i.version.as_deref())
217-
.unwrap_or("current");
212+
let branch = self.config.branch.clone();
218213
let mut extensions: IndexMap<String,serde_json::Value> = Default::default();
219214
if let Some(previous_version_doc_url) = obj.ext_previous_version_doc_url() {
220215
extensions.insert("x-previousVersionUrl".to_string(), serde_json::json!(previous_version_doc_url));
221216
}
222217
ExternalDocumentation {
223218
description: None,
224-
url: url.trim().replace("{branch}", branch),
219+
url: url.trim().replace("{branch}", &branch.unwrap_or("current".to_string())),
225220
extensions,
226221
}
227222
})

0 commit comments

Comments
 (0)