Skip to content

Commit 2fd36dd

Browse files
author
lif
committed
Per ahl PR feedback: Forego supporting the erroneous OpenAPI format
(and manually update sample OpenAPI JSON for Nexus and Propolis accordingly)
1 parent 8583d9a commit 2fd36dd

12 files changed

Lines changed: 165 additions & 28 deletions

progenitor-impl/src/method.rs

Lines changed: 2 additions & 9 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 (mut status_code, response) = v?;
446+
let (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,14 +472,7 @@ impl Generator {
472472
};
473473

474474
OperationResponseKind::Type(typ)
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-
475+
} else if status_code == OperationResponseStatus::Code(101) {
483476
OperationResponseKind::Upgrade
484477
} else if response.content.first().is_some() {
485478
OperationResponseKind::Raw

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35228,7 +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(self) -> Result<ResponseValue<reqwest::Upgraded>, Error<()>> {
35231+
pub async fn send(self) -> Result<ResponseValue<reqwest::Upgraded>, Error<types::Error>> {
3523235232
let Self {
3523335233
client,
3523435234
organization_name,
@@ -35275,6 +35275,12 @@ pub mod builder {
3527535275
let response = result?;
3527635276
match response.status().as_u16() {
3527735277
101u16 => ResponseValue::upgrade(response).await,
35278+
400u16..=499u16 => Err(Error::ErrorResponse(
35279+
ResponseValue::from_response(response).await?,
35280+
)),
35281+
500u16..=599u16 => Err(Error::ErrorResponse(
35282+
ResponseValue::from_response(response).await?,
35283+
)),
3527835284
_ => Err(Error::UnexpectedResponse(response)),
3527935285
}
3528035286
}
@@ -47941,7 +47947,7 @@ pub mod builder {
4794147947

4794247948
///Sends a `GET` request to
4794347949
/// `/v1/instances/{instance}/serial-console/stream`
47944-
pub async fn send(self) -> Result<ResponseValue<reqwest::Upgraded>, Error<()>> {
47950+
pub async fn send(self) -> Result<ResponseValue<reqwest::Upgraded>, Error<types::Error>> {
4794547951
let Self {
4794647952
client,
4794747953
instance,
@@ -47991,6 +47997,12 @@ pub mod builder {
4799147997
let response = result?;
4799247998
match response.status().as_u16() {
4799347999
101u16 => ResponseValue::upgrade(response).await,
48000+
400u16..=499u16 => Err(Error::ErrorResponse(
48001+
ResponseValue::from_response(response).await?,
48002+
)),
48003+
500u16..=599u16 => Err(Error::ErrorResponse(
48004+
ResponseValue::from_response(response).await?,
48005+
)),
4799448006
_ => Err(Error::UnexpectedResponse(response)),
4799548007
}
4799648008
}

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35080,7 +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(self) -> Result<ResponseValue<reqwest::Upgraded>, Error<()>> {
35083+
pub async fn send(self) -> Result<ResponseValue<reqwest::Upgraded>, Error<types::Error>> {
3508435084
let Self {
3508535085
client,
3508635086
organization_name,
@@ -35127,6 +35127,12 @@ pub mod builder {
3512735127
let response = result?;
3512835128
match response.status().as_u16() {
3512935129
101u16 => ResponseValue::upgrade(response).await,
35130+
400u16..=499u16 => Err(Error::ErrorResponse(
35131+
ResponseValue::from_response(response).await?,
35132+
)),
35133+
500u16..=599u16 => Err(Error::ErrorResponse(
35134+
ResponseValue::from_response(response).await?,
35135+
)),
3513035136
_ => Err(Error::UnexpectedResponse(response)),
3513135137
}
3513235138
}
@@ -47793,7 +47799,7 @@ pub mod builder {
4779347799

4779447800
///Sends a `GET` request to
4779547801
/// `/v1/instances/{instance}/serial-console/stream`
47796-
pub async fn send(self) -> Result<ResponseValue<reqwest::Upgraded>, Error<()>> {
47802+
pub async fn send(self) -> Result<ResponseValue<reqwest::Upgraded>, Error<types::Error>> {
4779747803
let Self {
4779847804
client,
4779947805
instance,
@@ -47843,6 +47849,12 @@ pub mod builder {
4784347849
let response = result?;
4784447850
match response.status().as_u16() {
4784547851
101u16 => ResponseValue::upgrade(response).await,
47852+
400u16..=499u16 => Err(Error::ErrorResponse(
47853+
ResponseValue::from_response(response).await?,
47854+
)),
47855+
500u16..=599u16 => Err(Error::ErrorResponse(
47856+
ResponseValue::from_response(response).await?,
47857+
)),
4784647858
_ => Err(Error::UnexpectedResponse(response)),
4784747859
}
4784847860
}

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4405,6 +4405,26 @@ pub mod operations {
44054405
pub fn switching_protocols(self) -> Self {
44064406
Self(self.0.status(101u16))
44074407
}
4408+
4409+
pub fn client_error(self, status: u16, value: &types::Error) -> Self {
4410+
assert_eq!(status / 100u16, 4u16);
4411+
Self(
4412+
self.0
4413+
.status(status)
4414+
.header("content-type", "application/json")
4415+
.json_body_obj(value),
4416+
)
4417+
}
4418+
4419+
pub fn server_error(self, status: u16, value: &types::Error) -> Self {
4420+
assert_eq!(status / 100u16, 5u16);
4421+
Self(
4422+
self.0
4423+
.status(status)
4424+
.header("content-type", "application/json")
4425+
.json_body_obj(value),
4426+
)
4427+
}
44084428
}
44094429

44104430
pub struct InstanceStartWhen(::httpmock::When);
@@ -12924,6 +12944,26 @@ pub mod operations {
1292412944
pub fn switching_protocols(self) -> Self {
1292512945
Self(self.0.status(101u16))
1292612946
}
12947+
12948+
pub fn client_error(self, status: u16, value: &types::Error) -> Self {
12949+
assert_eq!(status / 100u16, 4u16);
12950+
Self(
12951+
self.0
12952+
.status(status)
12953+
.header("content-type", "application/json")
12954+
.json_body_obj(value),
12955+
)
12956+
}
12957+
12958+
pub fn server_error(self, status: u16, value: &types::Error) -> Self {
12959+
assert_eq!(status / 100u16, 5u16);
12960+
Self(
12961+
self.0
12962+
.status(status)
12963+
.header("content-type", "application/json")
12964+
.json_body_obj(value),
12965+
)
12966+
}
1292712967
}
1292812968

1292912969
pub struct InstanceStartV1When(::httpmock::When);

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

Lines changed: 14 additions & 2 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<()>> {
16469+
) -> Result<ResponseValue<reqwest::Upgraded>, Error<types::Error>> {
1647016470
let url = format!(
1647116471
"{}/organizations/{}/projects/{}/instances/{}/serial-console/stream",
1647216472
self.baseurl,
@@ -16504,6 +16504,12 @@ impl Client {
1650416504
let response = result?;
1650516505
match response.status().as_u16() {
1650616506
101u16 => ResponseValue::upgrade(response).await,
16507+
400u16..=499u16 => Err(Error::ErrorResponse(
16508+
ResponseValue::from_response(response).await?,
16509+
)),
16510+
500u16..=599u16 => Err(Error::ErrorResponse(
16511+
ResponseValue::from_response(response).await?,
16512+
)),
1650716513
_ => Err(Error::UnexpectedResponse(response)),
1650816514
}
1650916515
}
@@ -23537,7 +23543,7 @@ impl Client {
2353723543
instance: &'a types::NameOrId,
2353823544
organization: Option<&'a types::NameOrId>,
2353923545
project: Option<&'a types::NameOrId>,
23540-
) -> Result<ResponseValue<reqwest::Upgraded>, Error<()>> {
23546+
) -> Result<ResponseValue<reqwest::Upgraded>, Error<types::Error>> {
2354123547
let url = format!(
2354223548
"{}/v1/instances/{}/serial-console/stream",
2354323549
self.baseurl,
@@ -23578,6 +23584,12 @@ impl Client {
2357823584
let response = result?;
2357923585
match response.status().as_u16() {
2358023586
101u16 => ResponseValue::upgrade(response).await,
23587+
400u16..=499u16 => Err(Error::ErrorResponse(
23588+
ResponseValue::from_response(response).await?,
23589+
)),
23590+
500u16..=599u16 => Err(Error::ErrorResponse(
23591+
ResponseValue::from_response(response).await?,
23592+
)),
2358123593
_ => Err(Error::UnexpectedResponse(response)),
2358223594
}
2358323595
}

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

Lines changed: 14 additions & 2 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<()>> {
16469+
) -> Result<ResponseValue<reqwest::Upgraded>, Error<types::Error>> {
1647016470
let url = format!(
1647116471
"{}/organizations/{}/projects/{}/instances/{}/serial-console/stream",
1647216472
self.baseurl,
@@ -16504,6 +16504,12 @@ impl Client {
1650416504
let response = result?;
1650516505
match response.status().as_u16() {
1650616506
101u16 => ResponseValue::upgrade(response).await,
16507+
400u16..=499u16 => Err(Error::ErrorResponse(
16508+
ResponseValue::from_response(response).await?,
16509+
)),
16510+
500u16..=599u16 => Err(Error::ErrorResponse(
16511+
ResponseValue::from_response(response).await?,
16512+
)),
1650716513
_ => Err(Error::UnexpectedResponse(response)),
1650816514
}
1650916515
}
@@ -23537,7 +23543,7 @@ impl Client {
2353723543
instance: &'a types::NameOrId,
2353823544
organization: Option<&'a types::NameOrId>,
2353923545
project: Option<&'a types::NameOrId>,
23540-
) -> Result<ResponseValue<reqwest::Upgraded>, Error<()>> {
23546+
) -> Result<ResponseValue<reqwest::Upgraded>, Error<types::Error>> {
2354123547
let url = format!(
2354223548
"{}/v1/instances/{}/serial-console/stream",
2354323549
self.baseurl,
@@ -23578,6 +23584,12 @@ impl Client {
2357823584
let response = result?;
2357923585
match response.status().as_u16() {
2358023586
101u16 => ResponseValue::upgrade(response).await,
23587+
400u16..=499u16 => Err(Error::ErrorResponse(
23588+
ResponseValue::from_response(response).await?,
23589+
)),
23590+
500u16..=599u16 => Err(Error::ErrorResponse(
23591+
ResponseValue::from_response(response).await?,
23592+
)),
2358123593
_ => Err(Error::UnexpectedResponse(response)),
2358223594
}
2358323595
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3321,7 +3321,7 @@ pub mod builder {
33213321
}
33223322

33233323
///Sends a `GET` request to `/instance/serial`
3324-
pub async fn send(self) -> Result<ResponseValue<reqwest::Upgraded>, Error<()>> {
3324+
pub async fn send(self) -> Result<ResponseValue<reqwest::Upgraded>, Error<types::Error>> {
33253325
let Self { client } = self;
33263326
let url = format!("{}/instance/serial", client.baseurl,);
33273327
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
@@ -3354,6 +3354,12 @@ pub mod builder {
33543354
let response = result?;
33553355
match response.status().as_u16() {
33563356
101u16 => ResponseValue::upgrade(response).await,
3357+
400u16..=499u16 => Err(Error::ErrorResponse(
3358+
ResponseValue::from_response(response).await?,
3359+
)),
3360+
500u16..=599u16 => Err(Error::ErrorResponse(
3361+
ResponseValue::from_response(response).await?,
3362+
)),
33573363
_ => Err(Error::UnexpectedResponse(response)),
33583364
}
33593365
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3276,7 +3276,7 @@ pub mod builder {
32763276
}
32773277

32783278
///Sends a `GET` request to `/instance/serial`
3279-
pub async fn send(self) -> Result<ResponseValue<reqwest::Upgraded>, Error<()>> {
3279+
pub async fn send(self) -> Result<ResponseValue<reqwest::Upgraded>, Error<types::Error>> {
32803280
let Self { client } = self;
32813281
let url = format!("{}/instance/serial", client.baseurl,);
32823282
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
@@ -3309,6 +3309,12 @@ pub mod builder {
33093309
let response = result?;
33103310
match response.status().as_u16() {
33113311
101u16 => ResponseValue::upgrade(response).await,
3312+
400u16..=499u16 => Err(Error::ErrorResponse(
3313+
ResponseValue::from_response(response).await?,
3314+
)),
3315+
500u16..=599u16 => Err(Error::ErrorResponse(
3316+
ResponseValue::from_response(response).await?,
3317+
)),
33123318
_ => Err(Error::UnexpectedResponse(response)),
33133319
}
33143320
}

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,26 @@ pub mod operations {
278278
pub fn switching_protocols(self) -> Self {
279279
Self(self.0.status(101u16))
280280
}
281+
282+
pub fn client_error(self, status: u16, value: &types::Error) -> Self {
283+
assert_eq!(status / 100u16, 4u16);
284+
Self(
285+
self.0
286+
.status(status)
287+
.header("content-type", "application/json")
288+
.json_body_obj(value),
289+
)
290+
}
291+
292+
pub fn server_error(self, status: u16, value: &types::Error) -> Self {
293+
assert_eq!(status / 100u16, 5u16);
294+
Self(
295+
self.0
296+
.status(status)
297+
.header("content-type", "application/json")
298+
.json_body_obj(value),
299+
)
300+
}
281301
}
282302

283303
pub struct InstanceStatePutWhen(::httpmock::When);

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1586,7 +1586,7 @@ impl Client {
15861586
///Sends a `GET` request to `/instance/serial`
15871587
pub async fn instance_serial<'a>(
15881588
&'a self,
1589-
) -> Result<ResponseValue<reqwest::Upgraded>, Error<()>> {
1589+
) -> Result<ResponseValue<reqwest::Upgraded>, Error<types::Error>> {
15901590
let url = format!("{}/instance/serial", self.baseurl,);
15911591
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
15921592
header_map.append(
@@ -1618,6 +1618,12 @@ impl Client {
16181618
let response = result?;
16191619
match response.status().as_u16() {
16201620
101u16 => ResponseValue::upgrade(response).await,
1621+
400u16..=499u16 => Err(Error::ErrorResponse(
1622+
ResponseValue::from_response(response).await?,
1623+
)),
1624+
500u16..=599u16 => Err(Error::ErrorResponse(
1625+
ResponseValue::from_response(response).await?,
1626+
)),
16211627
_ => Err(Error::UnexpectedResponse(response)),
16221628
}
16231629
}

0 commit comments

Comments
 (0)