Skip to content

Commit

Permalink
improve docs and error output for Generator::httpmock (#992)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahl authored Dec 4, 2024
1 parent 96bdb54 commit 96e977a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
10 changes: 8 additions & 2 deletions progenitor-impl/src/httpmock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@ struct MockOp {

impl Generator {
/// Generate a strongly-typed mocking extension to the `httpmock` crate.
///
/// The `crate_path` parameter should be a valid Rust path corresponding to
/// the SDK. This can include `::` and instances of `-` in the crate name
/// should be converted to `_`.
pub fn httpmock(
&mut self,
spec: &OpenAPI,
crate_name: &str,
crate_path: &str,
) -> Result<TokenStream> {
validate_openapi(spec)?;

Expand Down Expand Up @@ -81,7 +85,9 @@ impl Generator {

let crate_path = syn::TypePath {
qself: None,
path: syn::parse_str(crate_name).unwrap(),
path: syn::parse_str(crate_path).unwrap_or_else(|_| {
panic!("{} is not a valid identifier", crate_path)
}),
};

let code = quote! {
Expand Down
5 changes: 1 addition & 4 deletions progenitor-impl/src/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1293,10 +1293,7 @@ impl Generator {
parameters: &[OperationParameter],
responses: &[OperationResponse],
) -> Option<DropshotPagination> {
let Some(value) = operation.extensions.get("x-dropshot-pagination")
else {
return None;
};
let value = operation.extensions.get("x-dropshot-pagination")?;

// We expect to see at least "page_token" and "limit" parameters.
if parameters
Expand Down

0 comments on commit 96e977a

Please sign in to comment.