Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions generator/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ pub fn generate_files(
content
};

let docs = get_fn_docs(o, m, p, parameters, ts)?;
let docs = get_fn_docs(proper_name, o, m, p, parameters, ts)?;

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

Expand Down Expand Up @@ -727,7 +727,7 @@ fn get_fn_params(
let nam = &to_snake_case(&parameter_data.name);

if !fn_params.contains(nam) && !fn_params.contains(&format!("{}_", nam)) {
let typ = parameter_data.render_type(&param_name, ts)?;
let typ = parameter_data.render_type(proper_name, &param_name, ts)?;
if nam == "ref"
|| nam == "type"
|| nam == "foo"
Expand Down Expand Up @@ -1143,6 +1143,7 @@ fn get_fn_inner(
}

fn get_fn_docs(
proper_name: &str,
o: &openapiv3::Operation,
m: &str,
p: &str,
Expand Down Expand Up @@ -1215,7 +1216,7 @@ fn get_fn_docs(
}

let nam = &to_snake_case(&clean_name(&parameter_data.name));
let typ = parameter_data.render_type(&param_name, ts)?;
let typ = parameter_data.render_type(proper_name, &param_name, ts)?;

if nam == "ref"
|| nam == "type"
Expand Down
20 changes: 15 additions & 5 deletions generator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,11 @@ where
}

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

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

// Cleanup the name.
Expand Down Expand Up @@ -250,9 +250,20 @@ impl ParameterDataExt for openapiv3::ParameterData {

//println!("XXX min/max length");
//}

match &st.format {
Item(DateTime) => "chrono::DateTime<chrono::Utc>".to_string(),
// FIXME: In [list_workflow_runs](https://docs.rs/octorust/latest/octorust/actions/struct.Actions.html#method.list_workflow_runs), the created
// 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
// [search syntax](https://docs.github.com/en/search-github/getting-started-with-searching-on-github/understanding-the-search-syntax#query-for-dates).
// Convert this to an Option<&str> so the interface do not change for people not
// using the parameter currently, if they were, it was not working as they expected unless they looked for a specified date-time.
// https://github.com/github/rest-api-description/issues/2088
Item(DateTime) => {
if proper_name == "GitHub" && self.name == "created" {
"Option<&str>".to_string()
} else {
"chrono::DateTime<chrono::Utc>".to_string()
}
}
Item(Date) => "chrono::NaiveDate".to_string(),
Item(Password) => "&str".to_string(),
// TODO: as per the spec this is base64 encoded chars.
Expand Down Expand Up @@ -1419,7 +1430,6 @@ impl TypeSpace {
} else {
"".to_string()
};

let mut s = sc.clone();

// If we have an additional description and it is better than our original,
Expand Down
5 changes: 5 additions & 0 deletions generator/src/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ impl Template {
r#"if {} {{ query_args.push(("{}".to_string(), {}.to_string())); }}"#,
nam, prop, nam
));
} else if value == "Option<&str>" {
a(&format!(
r#"if let Some(s) = {} {{ if !s.is_empty() {{ query_args.push(("{}".to_string(), s.to_string())); }} }}"#,
nam, prop
));
} else if value == "&str" {
a(&format!(
r#"if !{}.is_empty() {{ query_args.push(("{}".to_string(), {}.to_string())); }}"#,
Expand Down