Skip to content

Commit 96e977a

Browse files
authored
improve docs and error output for Generator::httpmock (#992)
1 parent 96bdb54 commit 96e977a

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

progenitor-impl/src/httpmock.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,14 @@ struct MockOp {
2626

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

@@ -81,7 +85,9 @@ impl Generator {
8185

8286
let crate_path = syn::TypePath {
8387
qself: None,
84-
path: syn::parse_str(crate_name).unwrap(),
88+
path: syn::parse_str(crate_path).unwrap_or_else(|_| {
89+
panic!("{} is not a valid identifier", crate_path)
90+
}),
8591
};
8692

8793
let code = quote! {

progenitor-impl/src/method.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,10 +1293,7 @@ impl Generator {
12931293
parameters: &[OperationParameter],
12941294
responses: &[OperationResponse],
12951295
) -> Option<DropshotPagination> {
1296-
let Some(value) = operation.extensions.get("x-dropshot-pagination")
1297-
else {
1298-
return None;
1299-
};
1296+
let value = operation.extensions.get("x-dropshot-pagination")?;
13001297

13011298
// We expect to see at least "page_token" and "limit" parameters.
13021299
if parameters

0 commit comments

Comments
 (0)