Skip to content

Commit eec8526

Browse files
authored
cleanup and documentation (#67)
1 parent 3cd1eae commit eec8526

File tree

3 files changed

+143
-65
lines changed

3 files changed

+143
-65
lines changed

progenitor-client/src/progenitor_client.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ use bytes::Bytes;
1111
use futures_core::Stream;
1212
use serde::de::DeserializeOwned;
1313

14-
/// Represents a streaming, untyped byte stream for both success and error
15-
/// responses.
14+
/// Represents an untyped byte stream for both success and error responses.
1615
pub type ByteStream =
1716
Pin<Box<dyn Stream<Item = reqwest::Result<Bytes>> + Send>>;
1817

@@ -136,6 +135,9 @@ impl<T: std::fmt::Debug> std::fmt::Debug for ResponseValue<T> {
136135
/// or an enum if there are multiple valid error types. It can be the unit type
137136
/// if there are no structured returns expected.
138137
pub enum Error<E = ()> {
138+
/// The request did not conform to API requirements.
139+
InvalidRequest(String),
140+
139141
/// A server error either with the data, or with the connection.
140142
CommunicationError(reqwest::Error),
141143

@@ -155,6 +157,7 @@ impl<E> Error<E> {
155157
/// Returns the status code, if the error was generated from a response.
156158
pub fn status(&self) -> Option<reqwest::StatusCode> {
157159
match self {
160+
Error::InvalidRequest(_) => None,
158161
Error::CommunicationError(e) => e.status(),
159162
Error::ErrorResponse(rv) => Some(rv.status()),
160163
Error::InvalidResponsePayload(e) => e.status(),
@@ -166,6 +169,7 @@ impl<E> Error<E> {
166169
/// handling with APIs that distinguish various error response bodies.
167170
pub fn into_untyped(self) -> Error {
168171
match self {
172+
Error::InvalidRequest(s) => Error::InvalidRequest(s),
169173
Error::CommunicationError(e) => Error::CommunicationError(e),
170174
Error::ErrorResponse(ResponseValue {
171175
inner: _,
@@ -193,17 +197,20 @@ impl<E> From<reqwest::Error> for Error<E> {
193197
impl<E> std::fmt::Display for Error<E> {
194198
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
195199
match self {
200+
Error::InvalidRequest(s) => {
201+
write!(f, "Invalid Request: {}", s)
202+
}
196203
Error::CommunicationError(e) => {
197-
write!(f, "Communication Error {}", e)
204+
write!(f, "Communication Error: {}", e)
198205
}
199206
Error::ErrorResponse(_) => {
200207
write!(f, "Error Response")
201208
}
202209
Error::InvalidResponsePayload(e) => {
203-
write!(f, "Invalid Response Payload {}", e)
210+
write!(f, "Invalid Response Payload: {}", e)
204211
}
205212
Error::UnexpectedResponse(r) => {
206-
write!(f, "Unexpected Response {:?}", r)
213+
write!(f, "Unexpected Response: {:?}", r)
207214
}
208215
}
209216
}

progenitor-impl/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ pub enum Error {
1919
BadValue(String, serde_json::Value),
2020
#[error("type error")]
2121
TypeError(#[from] typify::Error),
22-
#[error("XXX")]
23-
BadConversion(String),
22+
#[error("unexpected or unhandled format in the OpenAPI document")]
23+
UnexpectedFormat(String),
2424
#[error("invalid operation path")]
2525
InvalidPath(String),
26-
//#[error("unknown")]
27-
//Unknown,
26+
#[error("invalid operation path")]
27+
InternalError(String),
2828
}
2929

3030
pub type Result<T> = std::result::Result<T, Error>;
@@ -84,7 +84,7 @@ impl Generator {
8484
.flat_map(|(path, ref_or_item)| {
8585
// Exclude externally defined path items.
8686
let item = ref_or_item.as_item().unwrap();
87-
// TODO punt on paramters that apply to all path items for now.
87+
// TODO punt on parameters that apply to all path items for now.
8888
assert!(item.parameters.is_empty());
8989
item.iter().map(move |(method, operation)| {
9090
(path.as_str(), method, operation)
@@ -102,7 +102,7 @@ impl Generator {
102102

103103
let methods = raw_methods
104104
.iter()
105-
.map(|method| self.process_method(method))
105+
.map(|method| self.positional_method(method))
106106
.collect::<Result<Vec<_>>>()?;
107107

108108
let mut types = self

0 commit comments

Comments
 (0)