Skip to content

Commit a60f6a0

Browse files
committed
[github] Use Option<&str> instead of Option<DateTime> for list_workflow_runs's created parameter.
The issue is described in more details in github/rest-api-description#2088 For now, this change will treat the created parameter as an optional str, which it would probably do if the parameter had a custom format defined. Alternatively, one oculd try to implement a proper datetime rnage that follows the [Query for dates](https://docs.github.com/en/search-github/getting-started-with-searching-on-github/understanding-the-search-syntax#query-for-dates) format, but this is maybe more work than one would benefit by implementing the search formating on the user side.
1 parent 6e7b398 commit a60f6a0

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

generator/src/functions.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ pub fn generate_files(
138138
content
139139
};
140140

141-
let docs = get_fn_docs(o, m, p, parameters, ts)?;
141+
let docs = get_fn_docs(proper_name, o, m, p, parameters, ts)?;
142142

143143
let mut bounds: Vec<String> = Vec::new();
144144

@@ -727,7 +727,7 @@ fn get_fn_params(
727727
let nam = &to_snake_case(&parameter_data.name);
728728

729729
if !fn_params.contains(nam) && !fn_params.contains(&format!("{}_", nam)) {
730-
let typ = parameter_data.render_type(&param_name, ts)?;
730+
let typ = parameter_data.render_type(proper_name, &param_name, ts)?;
731731
if nam == "ref"
732732
|| nam == "type"
733733
|| nam == "foo"
@@ -1143,6 +1143,7 @@ fn get_fn_inner(
11431143
}
11441144

11451145
fn get_fn_docs(
1146+
proper_name: &str,
11461147
o: &openapiv3::Operation,
11471148
m: &str,
11481149
p: &str,
@@ -1215,7 +1216,7 @@ fn get_fn_docs(
12151216
}
12161217

12171218
let nam = &to_snake_case(&clean_name(&parameter_data.name));
1218-
let typ = parameter_data.render_type(&param_name, ts)?;
1219+
let typ = parameter_data.render_type(proper_name, &param_name, ts)?;
12191220

12201221
if nam == "ref"
12211222
|| nam == "type"

generator/src/main.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,11 @@ where
169169
}
170170

171171
trait ParameterDataExt {
172-
fn render_type(&self, name: &str, ts: &mut TypeSpace) -> Result<String>;
172+
fn render_type(&self, proper_name: &str, name: &str, ts: &mut TypeSpace) -> Result<String>;
173173
}
174174

175175
impl ParameterDataExt for openapiv3::ParameterData {
176-
fn render_type(&self, name: &str, ts: &mut TypeSpace) -> Result<String> {
176+
fn render_type(&self, proper_name: &str, name: &str, ts: &mut TypeSpace) -> Result<String> {
177177
use openapiv3::{SchemaKind, Type};
178178

179179
// Cleanup the name.
@@ -250,9 +250,20 @@ impl ParameterDataExt for openapiv3::ParameterData {
250250

251251
//println!("XXX min/max length");
252252
//}
253-
254253
match &st.format {
255-
Item(DateTime) => "chrono::DateTime<chrono::Utc>".to_string(),
254+
// FIXME: In [list_workflow_runs](https://docs.rs/octorust/latest/octorust/actions/struct.Actions.html#method.list_workflow_runs), the created
255+
// parameter is an optional DateTime as specified in github spec, but in practice, it is some date-time range of sort as specificed by the
256+
// [search syntax](https://docs.github.com/en/search-github/getting-started-with-searching-on-github/understanding-the-search-syntax#query-for-dates).
257+
// Convert this to an Option<&str> so the interface do not change for people not
258+
// using the parameter currently, if they were, it was not working as they expected unless they looked for a specified date-time.
259+
// https://github.com/github/rest-api-description/issues/2088
260+
Item(DateTime) => {
261+
if proper_name == "GitHub" && self.name == "created" {
262+
"Option<&str>".to_string()
263+
} else {
264+
"chrono::DateTime<chrono::Utc>".to_string()
265+
}
266+
}
256267
Item(Date) => "chrono::NaiveDate".to_string(),
257268
Item(Password) => "&str".to_string(),
258269
// TODO: as per the spec this is base64 encoded chars.
@@ -1419,7 +1430,6 @@ impl TypeSpace {
14191430
} else {
14201431
"".to_string()
14211432
};
1422-
14231433
let mut s = sc.clone();
14241434

14251435
// If we have an additional description and it is better than our original,

generator/src/template.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ impl Template {
6262
r#"if {} {{ query_args.push(("{}".to_string(), {}.to_string())); }}"#,
6363
nam, prop, nam
6464
));
65+
} else if value == "Option<&str>" {
66+
a(&format!(
67+
r#"if let Some(s) = {} {{ if !s.is_empty() {{ query_args.push(("{}".to_string(), s.to_string())); }} }}"#,
68+
nam, prop
69+
));
6570
} else if value == "&str" {
6671
a(&format!(
6772
r#"if !{}.is_empty() {{ query_args.push(("{}".to_string(), {}.to_string())); }}"#,

0 commit comments

Comments
 (0)