Skip to content

Commit e0c9453

Browse files
author
lif
committed
Treat connection upgrade (HTTP 101) as normal success.
This fixes a bug wherein client code would be generated for a 2XX-range response on WebSocket endpoints, which in turn would unnecessarily trip an `assert!(response_types.len() <= 1)` in `extract_responses` when explicit status codes are provided in the OpenAPI document. (This also fixes a bug in such a scenario wherein *all* responses, including HTTP errors, would be set to Upgrade type) (As in dropshot#1548)
1 parent b36be7b commit e0c9453

12 files changed

Lines changed: 27 additions & 60 deletions

progenitor-impl/src/method.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ impl Generator {
443443
},
444444
))
445445
.map(|v: Result<(OperationResponseStatus, &Response)>| {
446-
let (status_code, response) = v?;
446+
let (mut status_code, response) = v?;
447447

448448
// We categorize responses as "typed" based on the
449449
// "application/json" content type, "upgrade" if it's a
@@ -472,7 +472,14 @@ impl Generator {
472472
};
473473

474474
OperationResponseKind::Type(typ)
475-
} else if dropshot_websocket {
475+
} else if status_code == OperationResponseStatus::Code(101)
476+
// TODO: remove when no longer supporting older dropshot
477+
// w/o explicit response codes for WebSocket endpoints:
478+
|| (dropshot_websocket && status_code == OperationResponseStatus::Default)
479+
{
480+
// TODO (as above)
481+
status_code = OperationResponseStatus::Code(101);
482+
476483
OperationResponseKind::Upgrade
477484
} else if response.content.first().is_some() {
478485
OperationResponseKind::Raw
@@ -484,6 +491,7 @@ impl Generator {
484491
if matches!(
485492
status_code,
486493
OperationResponseStatus::Default
494+
| OperationResponseStatus::Code(101)
487495
| OperationResponseStatus::Code(200..=299)
488496
| OperationResponseStatus::Range(2)
489497
) {
@@ -516,15 +524,6 @@ impl Generator {
516524
});
517525
}
518526

519-
// Must accept HTTP 101 Switching Protocols
520-
if dropshot_websocket {
521-
responses.push(OperationResponse {
522-
status_code: OperationResponseStatus::Code(101),
523-
typ: OperationResponseKind::Upgrade,
524-
description: None,
525-
})
526-
}
527-
528527
let dropshot_paginated = self.dropshot_pagination_data(operation, &params, &responses);
529528

530529
if dropshot_websocket && dropshot_paginated.is_some() {

progenitor-impl/tests/output/src/nexus_builder.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35228,9 +35228,7 @@ pub mod builder {
3522835228
///Sends a `GET` request to
3522935229
/// `/organizations/{organization_name}/projects/{project_name}/
3523035230
/// instances/{instance_name}/serial-console/stream`
35231-
pub async fn send(
35232-
self,
35233-
) -> Result<ResponseValue<reqwest::Upgraded>, Error<reqwest::Upgraded>> {
35231+
pub async fn send(self) -> Result<ResponseValue<reqwest::Upgraded>, Error<()>> {
3523435232
let Self {
3523535233
client,
3523635234
organization_name,
@@ -35277,7 +35275,6 @@ pub mod builder {
3527735275
let response = result?;
3527835276
match response.status().as_u16() {
3527935277
101u16 => ResponseValue::upgrade(response).await,
35280-
200..=299 => ResponseValue::upgrade(response).await,
3528135278
_ => Err(Error::UnexpectedResponse(response)),
3528235279
}
3528335280
}
@@ -47944,9 +47941,7 @@ pub mod builder {
4794447941

4794547942
///Sends a `GET` request to
4794647943
/// `/v1/instances/{instance}/serial-console/stream`
47947-
pub async fn send(
47948-
self,
47949-
) -> Result<ResponseValue<reqwest::Upgraded>, Error<reqwest::Upgraded>> {
47944+
pub async fn send(self) -> Result<ResponseValue<reqwest::Upgraded>, Error<()>> {
4795047945
let Self {
4795147946
client,
4795247947
instance,
@@ -47996,7 +47991,6 @@ pub mod builder {
4799647991
let response = result?;
4799747992
match response.status().as_u16() {
4799847993
101u16 => ResponseValue::upgrade(response).await,
47999-
200..=299 => ResponseValue::upgrade(response).await,
4800047994
_ => Err(Error::UnexpectedResponse(response)),
4800147995
}
4800247996
}

progenitor-impl/tests/output/src/nexus_builder_tagged.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35080,9 +35080,7 @@ pub mod builder {
3508035080
///Sends a `GET` request to
3508135081
/// `/organizations/{organization_name}/projects/{project_name}/
3508235082
/// instances/{instance_name}/serial-console/stream`
35083-
pub async fn send(
35084-
self,
35085-
) -> Result<ResponseValue<reqwest::Upgraded>, Error<reqwest::Upgraded>> {
35083+
pub async fn send(self) -> Result<ResponseValue<reqwest::Upgraded>, Error<()>> {
3508635084
let Self {
3508735085
client,
3508835086
organization_name,
@@ -35129,7 +35127,6 @@ pub mod builder {
3512935127
let response = result?;
3513035128
match response.status().as_u16() {
3513135129
101u16 => ResponseValue::upgrade(response).await,
35132-
200..=299 => ResponseValue::upgrade(response).await,
3513335130
_ => Err(Error::UnexpectedResponse(response)),
3513435131
}
3513535132
}
@@ -47796,9 +47793,7 @@ pub mod builder {
4779647793

4779747794
///Sends a `GET` request to
4779847795
/// `/v1/instances/{instance}/serial-console/stream`
47799-
pub async fn send(
47800-
self,
47801-
) -> Result<ResponseValue<reqwest::Upgraded>, Error<reqwest::Upgraded>> {
47796+
pub async fn send(self) -> Result<ResponseValue<reqwest::Upgraded>, Error<()>> {
4780247797
let Self {
4780347798
client,
4780447799
instance,
@@ -47848,7 +47843,6 @@ pub mod builder {
4784847843
let response = result?;
4784947844
match response.status().as_u16() {
4785047845
101u16 => ResponseValue::upgrade(response).await,
47851-
200..=299 => ResponseValue::upgrade(response).await,
4785247846
_ => Err(Error::UnexpectedResponse(response)),
4785347847
}
4785447848
}

progenitor-impl/tests/output/src/nexus_cli.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7854,7 +7854,8 @@ impl<T: CliConfig> Cli<T> {
78547854
todo!()
78557855
}
78567856
Err(r) => {
7857-
todo!()
7857+
self.config.error(&r);
7858+
Err(anyhow::Error::new(r))
78587859
}
78597860
}
78607861
}
@@ -11660,7 +11661,8 @@ impl<T: CliConfig> Cli<T> {
1166011661
todo!()
1166111662
}
1166211663
Err(r) => {
11663-
todo!()
11664+
self.config.error(&r);
11665+
Err(anyhow::Error::new(r))
1166411666
}
1166511667
}
1166611668
}

progenitor-impl/tests/output/src/nexus_httpmock.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4402,10 +4402,6 @@ pub mod operations {
44024402
self.0
44034403
}
44044404

4405-
pub fn default_response(self, status: u16) -> Self {
4406-
Self(self.0.status(status))
4407-
}
4408-
44094405
pub fn switching_protocols(self) -> Self {
44104406
Self(self.0.status(101u16))
44114407
}
@@ -12925,10 +12921,6 @@ pub mod operations {
1292512921
self.0
1292612922
}
1292712923

12928-
pub fn default_response(self, status: u16) -> Self {
12929-
Self(self.0.status(status))
12930-
}
12931-
1293212924
pub fn switching_protocols(self) -> Self {
1293312925
Self(self.0.status(101u16))
1293412926
}

progenitor-impl/tests/output/src/nexus_positional.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16466,7 +16466,7 @@ impl Client {
1646616466
organization_name: &'a types::Name,
1646716467
project_name: &'a types::Name,
1646816468
instance_name: &'a types::Name,
16469-
) -> Result<ResponseValue<reqwest::Upgraded>, Error<reqwest::Upgraded>> {
16469+
) -> Result<ResponseValue<reqwest::Upgraded>, Error<()>> {
1647016470
let url = format!(
1647116471
"{}/organizations/{}/projects/{}/instances/{}/serial-console/stream",
1647216472
self.baseurl,
@@ -16504,7 +16504,6 @@ impl Client {
1650416504
let response = result?;
1650516505
match response.status().as_u16() {
1650616506
101u16 => ResponseValue::upgrade(response).await,
16507-
200..=299 => ResponseValue::upgrade(response).await,
1650816507
_ => Err(Error::UnexpectedResponse(response)),
1650916508
}
1651016509
}
@@ -23538,7 +23537,7 @@ impl Client {
2353823537
instance: &'a types::NameOrId,
2353923538
organization: Option<&'a types::NameOrId>,
2354023539
project: Option<&'a types::NameOrId>,
23541-
) -> Result<ResponseValue<reqwest::Upgraded>, Error<reqwest::Upgraded>> {
23540+
) -> Result<ResponseValue<reqwest::Upgraded>, Error<()>> {
2354223541
let url = format!(
2354323542
"{}/v1/instances/{}/serial-console/stream",
2354423543
self.baseurl,
@@ -23579,7 +23578,6 @@ impl Client {
2357923578
let response = result?;
2358023579
match response.status().as_u16() {
2358123580
101u16 => ResponseValue::upgrade(response).await,
23582-
200..=299 => ResponseValue::upgrade(response).await,
2358323581
_ => Err(Error::UnexpectedResponse(response)),
2358423582
}
2358523583
}

progenitor-impl/tests/output/src/nexus_with_timeout.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16466,7 +16466,7 @@ impl Client {
1646616466
organization_name: &'a types::Name,
1646716467
project_name: &'a types::Name,
1646816468
instance_name: &'a types::Name,
16469-
) -> Result<ResponseValue<reqwest::Upgraded>, Error<reqwest::Upgraded>> {
16469+
) -> Result<ResponseValue<reqwest::Upgraded>, Error<()>> {
1647016470
let url = format!(
1647116471
"{}/organizations/{}/projects/{}/instances/{}/serial-console/stream",
1647216472
self.baseurl,
@@ -16504,7 +16504,6 @@ impl Client {
1650416504
let response = result?;
1650516505
match response.status().as_u16() {
1650616506
101u16 => ResponseValue::upgrade(response).await,
16507-
200..=299 => ResponseValue::upgrade(response).await,
1650816507
_ => Err(Error::UnexpectedResponse(response)),
1650916508
}
1651016509
}
@@ -23538,7 +23537,7 @@ impl Client {
2353823537
instance: &'a types::NameOrId,
2353923538
organization: Option<&'a types::NameOrId>,
2354023539
project: Option<&'a types::NameOrId>,
23541-
) -> Result<ResponseValue<reqwest::Upgraded>, Error<reqwest::Upgraded>> {
23540+
) -> Result<ResponseValue<reqwest::Upgraded>, Error<()>> {
2354223541
let url = format!(
2354323542
"{}/v1/instances/{}/serial-console/stream",
2354423543
self.baseurl,
@@ -23579,7 +23578,6 @@ impl Client {
2357923578
let response = result?;
2358023579
match response.status().as_u16() {
2358123580
101u16 => ResponseValue::upgrade(response).await,
23582-
200..=299 => ResponseValue::upgrade(response).await,
2358323581
_ => Err(Error::UnexpectedResponse(response)),
2358423582
}
2358523583
}

progenitor-impl/tests/output/src/propolis_server_builder.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3321,9 +3321,7 @@ pub mod builder {
33213321
}
33223322

33233323
///Sends a `GET` request to `/instance/serial`
3324-
pub async fn send(
3325-
self,
3326-
) -> Result<ResponseValue<reqwest::Upgraded>, Error<reqwest::Upgraded>> {
3324+
pub async fn send(self) -> Result<ResponseValue<reqwest::Upgraded>, Error<()>> {
33273325
let Self { client } = self;
33283326
let url = format!("{}/instance/serial", client.baseurl,);
33293327
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
@@ -3356,7 +3354,6 @@ pub mod builder {
33563354
let response = result?;
33573355
match response.status().as_u16() {
33583356
101u16 => ResponseValue::upgrade(response).await,
3359-
200..=299 => ResponseValue::upgrade(response).await,
33603357
_ => Err(Error::UnexpectedResponse(response)),
33613358
}
33623359
}

progenitor-impl/tests/output/src/propolis_server_builder_tagged.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3276,9 +3276,7 @@ pub mod builder {
32763276
}
32773277

32783278
///Sends a `GET` request to `/instance/serial`
3279-
pub async fn send(
3280-
self,
3281-
) -> Result<ResponseValue<reqwest::Upgraded>, Error<reqwest::Upgraded>> {
3279+
pub async fn send(self) -> Result<ResponseValue<reqwest::Upgraded>, Error<()>> {
32823280
let Self { client } = self;
32833281
let url = format!("{}/instance/serial", client.baseurl,);
32843282
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
@@ -3311,7 +3309,6 @@ pub mod builder {
33113309
let response = result?;
33123310
match response.status().as_u16() {
33133311
101u16 => ResponseValue::upgrade(response).await,
3314-
200..=299 => ResponseValue::upgrade(response).await,
33153312
_ => Err(Error::UnexpectedResponse(response)),
33163313
}
33173314
}

progenitor-impl/tests/output/src/propolis_server_cli.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,8 @@ impl<T: CliConfig> Cli<T> {
279279
todo!()
280280
}
281281
Err(r) => {
282-
todo!()
282+
self.config.error(&r);
283+
Err(anyhow::Error::new(r))
283284
}
284285
}
285286
}

0 commit comments

Comments
 (0)