Skip to content

Commit

Permalink
add accept header (#436)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahl authored Apr 25, 2023
1 parent 819ebb2 commit a9e7660
Show file tree
Hide file tree
Showing 14 changed files with 5,376 additions and 633 deletions.
28 changes: 25 additions & 3 deletions progenitor-impl/src/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -999,17 +999,38 @@ impl Generator {
}
}
OperationResponseType::Upgrade => {
if response.status_code == OperationResponseStatus::Default {
return quote! { } // catch-all handled below
if response.status_code
== OperationResponseStatus::Default
{
return quote! {}; // catch-all handled below
} else {
todo!("non-default error response handling for upgrade requests is not yet implemented");
todo!(
"non-default error response handling for \
upgrade requests is not yet implemented"
);
}
}
};

quote! { #pat => { #decode } }
});

let accept_header = matches!(
(&response_type, &error_type),
(OperationResponseType::Type(_), _)
| (OperationResponseType::None, OperationResponseType::Type(_))
)
.then(|| {
quote! {
.header(
reqwest::header::ACCEPT,
reqwest::header::HeaderValue::from_static(
"application/json",
),
)
}
});

// Generate the catch-all case for other statuses. If the operation
// specifies a default response, we've already generated a default
// match as part of error response code handling. (And we've handled
Expand Down Expand Up @@ -1042,6 +1063,7 @@ impl Generator {

let request = #client.client
. #method_func (url)
#accept_header
#(#body_func)*
#query_use
#headers_use
Expand Down
107 changes: 96 additions & 11 deletions progenitor-impl/tests/output/buildomat-builder-tagged.out
Original file line number Diff line number Diff line change
Expand Up @@ -1872,7 +1872,14 @@ pub mod builder {
pub async fn send(self) -> Result<ResponseValue<()>, Error<()>> {
let Self { client } = self;
let url = format!("{}/v1/control/hold", client.baseurl,);
let request = client.client.post(url).build()?;
let request = client
.client
.post(url)
.header(
reqwest::header::ACCEPT,
reqwest::header::HeaderValue::from_static("application/json"),
)
.build()?;
let result = client.client.execute(request).await;
let response = result?;
match response.status().as_u16() {
Expand Down Expand Up @@ -1945,7 +1952,14 @@ pub mod builder {
client.baseurl,
encode_path(&task.to_string()),
);
let request = client.client.get(url).build()?;
let request = client
.client
.get(url)
.header(
reqwest::header::ACCEPT,
reqwest::header::HeaderValue::from_static("application/json"),
)
.build()?;
let result = client.client.execute(request).await;
let response = result?;
match response.status().as_u16() {
Expand All @@ -1972,7 +1986,14 @@ pub mod builder {
pub async fn send(self) -> Result<ResponseValue<Vec<types::Task>>, Error<()>> {
let Self { client } = self;
let url = format!("{}/v1/tasks", client.baseurl,);
let request = client.client.get(url).build()?;
let request = client
.client
.get(url)
.header(
reqwest::header::ACCEPT,
reqwest::header::HeaderValue::from_static("application/json"),
)
.build()?;
let result = client.client.execute(request).await;
let response = result?;
match response.status().as_u16() {
Expand Down Expand Up @@ -2025,7 +2046,15 @@ pub mod builder {
.and_then(std::convert::TryInto::<types::TaskSubmit>::try_into)
.map_err(Error::InvalidRequest)?;
let url = format!("{}/v1/tasks", client.baseurl,);
let request = client.client.post(url).json(&body).build()?;
let request = client
.client
.post(url)
.header(
reqwest::header::ACCEPT,
reqwest::header::HeaderValue::from_static("application/json"),
)
.json(&body)
.build()?;
let result = client.client.execute(request).await;
let response = result?;
match response.status().as_u16() {
Expand Down Expand Up @@ -2093,7 +2122,15 @@ pub mod builder {
if let Some(v) = &minseq {
query.push(("minseq", v.to_string()));
}
let request = client.client.get(url).query(&query).build()?;
let request = client
.client
.get(url)
.header(
reqwest::header::ACCEPT,
reqwest::header::HeaderValue::from_static("application/json"),
)
.query(&query)
.build()?;
let result = client.client.execute(request).await;
let response = result?;
match response.status().as_u16() {
Expand Down Expand Up @@ -2139,7 +2176,14 @@ pub mod builder {
client.baseurl,
encode_path(&task.to_string()),
);
let request = client.client.get(url).build()?;
let request = client
.client
.get(url)
.header(
reqwest::header::ACCEPT,
reqwest::header::HeaderValue::from_static("application/json"),
)
.build()?;
let result = client.client.execute(request).await;
let response = result?;
match response.status().as_u16() {
Expand Down Expand Up @@ -2256,7 +2300,15 @@ pub mod builder {
.and_then(std::convert::TryInto::<types::UserCreate>::try_into)
.map_err(Error::InvalidRequest)?;
let url = format!("{}/v1/users", client.baseurl,);
let request = client.client.post(url).json(&body).build()?;
let request = client
.client
.post(url)
.header(
reqwest::header::ACCEPT,
reqwest::header::HeaderValue::from_static("application/json"),
)
.json(&body)
.build()?;
let result = client.client.execute(request).await;
let response = result?;
match response.status().as_u16() {
Expand All @@ -2283,7 +2335,14 @@ pub mod builder {
pub async fn send(self) -> Result<ResponseValue<types::WhoamiResult>, Error<()>> {
let Self { client } = self;
let url = format!("{}/v1/whoami", client.baseurl,);
let request = client.client.get(url).build()?;
let request = client
.client
.get(url)
.header(
reqwest::header::ACCEPT,
reqwest::header::HeaderValue::from_static("application/json"),
)
.build()?;
let result = client.client.execute(request).await;
let response = result?;
match response.status().as_u16() {
Expand Down Expand Up @@ -2336,7 +2395,15 @@ pub mod builder {
.and_then(std::convert::TryInto::<types::WorkerBootstrap>::try_into)
.map_err(Error::InvalidRequest)?;
let url = format!("{}/v1/worker/bootstrap", client.baseurl,);
let request = client.client.post(url).json(&body).build()?;
let request = client
.client
.post(url)
.header(
reqwest::header::ACCEPT,
reqwest::header::HeaderValue::from_static("application/json"),
)
.json(&body)
.build()?;
let result = client.client.execute(request).await;
let response = result?;
match response.status().as_u16() {
Expand All @@ -2363,7 +2430,14 @@ pub mod builder {
pub async fn send(self) -> Result<ResponseValue<types::WorkerPingResult>, Error<()>> {
let Self { client } = self;
let url = format!("{}/v1/worker/ping", client.baseurl,);
let request = client.client.get(url).build()?;
let request = client
.client
.get(url)
.header(
reqwest::header::ACCEPT,
reqwest::header::HeaderValue::from_static("application/json"),
)
.build()?;
let result = client.client.execute(request).await;
let response = result?;
match response.status().as_u16() {
Expand Down Expand Up @@ -2497,6 +2571,10 @@ pub mod builder {
let request = client
.client
.post(url)
.header(
reqwest::header::ACCEPT,
reqwest::header::HeaderValue::from_static("application/json"),
)
.header(
reqwest::header::CONTENT_TYPE,
reqwest::header::HeaderValue::from_static("application/octet-stream"),
Expand Down Expand Up @@ -2671,7 +2749,14 @@ pub mod builder {
pub async fn send(self) -> Result<ResponseValue<types::WorkersResult>, Error<()>> {
let Self { client } = self;
let url = format!("{}/v1/workers", client.baseurl,);
let request = client.client.get(url).build()?;
let request = client
.client
.get(url)
.header(
reqwest::header::ACCEPT,
reqwest::header::HeaderValue::from_static("application/json"),
)
.build()?;
let result = client.client.execute(request).await;
let response = result?;
match response.status().as_u16() {
Expand Down
Loading

0 comments on commit a9e7660

Please sign in to comment.