Skip to content

Commit 4faa1e0

Browse files
committed
fix(codegen): resolve module path in multipart impls
Fix two critical compilation issues in multipart/related code generation: - Use `crate::progenitor_client::` instead of `progenitor_client::` in generated MultipartRelatedBody impls and MultipartPart constructions, since the code is generated inside the types module where progenitor_client is not in scope - Add blanket impl for references to allow calling `.multipart_related(&body)` by implementing the trait for `&T` Without these fixes, generated code failed to compile with unresolved module errors and unsatisfied trait bound errors. This makes multipart/related code generation functional with --include-client=true.
1 parent 0aaea4b commit 4faa1e0

File tree

5 files changed

+43
-36
lines changed

5 files changed

+43
-36
lines changed

progenitor-client/src/progenitor_client.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,13 @@ pub trait MultipartRelatedBody {
571571
fn as_multipart_parts(&self) -> Vec<MultipartPart<'_>>;
572572
}
573573

574+
// Blanket impl for references - allows .multipart_related(&body) to work
575+
impl<T: MultipartRelatedBody + ?Sized> MultipartRelatedBody for &T {
576+
fn as_multipart_parts(&self) -> Vec<MultipartPart<'_>> {
577+
(*self).as_multipart_parts()
578+
}
579+
}
580+
574581
#[doc(hidden)]
575582
#[allow(clippy::result_large_err)]
576583
pub trait RequestBuilderExt<E> {

progenitor-impl/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ impl Generator {
456456
Some(quote! {
457457
if let Some(ref content_type) = self.#content_type_field {
458458
if !self.#field_ident.is_empty() {
459-
Some(progenitor_client::MultipartPart {
459+
Some(crate::progenitor_client::MultipartPart {
460460
content_type: content_type.as_str(),
461461
content_id: #prop_name,
462462
bytes: ::std::borrow::Cow::Borrowed(&self.#field_ident),
@@ -471,7 +471,7 @@ impl Generator {
471471
} else {
472472
// Required binary field: use Cow::Borrowed to avoid cloning
473473
Some(quote! {
474-
Some(progenitor_client::MultipartPart {
474+
Some(crate::progenitor_client::MultipartPart {
475475
content_type: &self.#content_type_field,
476476
content_id: #prop_name,
477477
bytes: ::std::borrow::Cow::Borrowed(&self.#field_ident),
@@ -482,7 +482,7 @@ impl Generator {
482482
// Optional structured field: JSON serialization creates owned data
483483
Some(quote! {
484484
self.#field_ident.as_ref().map(|value| {
485-
progenitor_client::MultipartPart {
485+
crate::progenitor_client::MultipartPart {
486486
content_type: "application/json",
487487
content_id: #prop_name,
488488
bytes: ::std::borrow::Cow::Owned(
@@ -495,7 +495,7 @@ impl Generator {
495495
} else {
496496
// Required structured field: JSON serialization creates owned data
497497
Some(quote! {
498-
Some(progenitor_client::MultipartPart {
498+
Some(crate::progenitor_client::MultipartPart {
499499
content_type: "application/json",
500500
content_id: #prop_name,
501501
bytes: ::std::borrow::Cow::Owned(
@@ -517,8 +517,8 @@ impl Generator {
517517
let bare_type_name = quote::format_ident!("{}", bare_type_name);
518518

519519
quote! {
520-
impl progenitor_client::MultipartRelatedBody for #bare_type_name {
521-
fn as_multipart_parts(&self) -> Vec<progenitor_client::MultipartPart> {
520+
impl crate::progenitor_client::MultipartRelatedBody for #bare_type_name {
521+
fn as_multipart_parts(&self) -> Vec<crate::progenitor_client::MultipartPart> {
522522
vec![
523523
#(#parts_extraction),*
524524
]

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -669,17 +669,17 @@ pub mod types {
669669
}
670670
}
671671

672-
impl progenitor_client::MultipartRelatedBody for UploadFileMultipartParts {
673-
fn as_multipart_parts(&self) -> Vec<progenitor_client::MultipartPart> {
672+
impl crate::progenitor_client::MultipartRelatedBody for UploadFileMultipartParts {
673+
fn as_multipart_parts(&self) -> Vec<crate::progenitor_client::MultipartPart> {
674674
vec![
675-
Some(progenitor_client::MultipartPart {
675+
Some(crate::progenitor_client::MultipartPart {
676676
content_type: "application/json",
677677
content_id: "metadata",
678678
bytes: ::std::borrow::Cow::Owned(
679679
::serde_json::to_vec(&self.metadata).expect("failed to serialize field"),
680680
),
681681
}),
682-
Some(progenitor_client::MultipartPart {
682+
Some(crate::progenitor_client::MultipartPart {
683683
content_type: &self.file_content_type,
684684
content_id: "file",
685685
bytes: ::std::borrow::Cow::Borrowed(&self.file),
@@ -691,29 +691,29 @@ pub mod types {
691691
}
692692
}
693693

694-
impl progenitor_client::MultipartRelatedBody for UploadMultipleFilesMultipartParts {
695-
fn as_multipart_parts(&self) -> Vec<progenitor_client::MultipartPart> {
694+
impl crate::progenitor_client::MultipartRelatedBody for UploadMultipleFilesMultipartParts {
695+
fn as_multipart_parts(&self) -> Vec<crate::progenitor_client::MultipartPart> {
696696
vec![
697-
Some(progenitor_client::MultipartPart {
697+
Some(crate::progenitor_client::MultipartPart {
698698
content_type: "application/json",
699699
content_id: "metadata",
700700
bytes: ::std::borrow::Cow::Owned(
701701
::serde_json::to_vec(&self.metadata).expect("failed to serialize field"),
702702
),
703703
}),
704-
Some(progenitor_client::MultipartPart {
704+
Some(crate::progenitor_client::MultipartPart {
705705
content_type: &self.document_content_type,
706706
content_id: "document",
707707
bytes: ::std::borrow::Cow::Borrowed(&self.document),
708708
}),
709-
Some(progenitor_client::MultipartPart {
709+
Some(crate::progenitor_client::MultipartPart {
710710
content_type: &self.thumbnail_content_type,
711711
content_id: "thumbnail",
712712
bytes: ::std::borrow::Cow::Borrowed(&self.thumbnail),
713713
}),
714714
if let Some(ref content_type) = self.attachment_content_type {
715715
if !self.attachment.is_empty() {
716-
Some(progenitor_client::MultipartPart {
716+
Some(crate::progenitor_client::MultipartPart {
717717
content_type: content_type.as_str(),
718718
content_id: "attachment",
719719
bytes: ::std::borrow::Cow::Borrowed(&self.attachment),

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -661,17 +661,17 @@ pub mod types {
661661
}
662662
}
663663

664-
impl progenitor_client::MultipartRelatedBody for UploadFileMultipartParts {
665-
fn as_multipart_parts(&self) -> Vec<progenitor_client::MultipartPart> {
664+
impl crate::progenitor_client::MultipartRelatedBody for UploadFileMultipartParts {
665+
fn as_multipart_parts(&self) -> Vec<crate::progenitor_client::MultipartPart> {
666666
vec![
667-
Some(progenitor_client::MultipartPart {
667+
Some(crate::progenitor_client::MultipartPart {
668668
content_type: "application/json",
669669
content_id: "metadata",
670670
bytes: ::std::borrow::Cow::Owned(
671671
::serde_json::to_vec(&self.metadata).expect("failed to serialize field"),
672672
),
673673
}),
674-
Some(progenitor_client::MultipartPart {
674+
Some(crate::progenitor_client::MultipartPart {
675675
content_type: &self.file_content_type,
676676
content_id: "file",
677677
bytes: ::std::borrow::Cow::Borrowed(&self.file),
@@ -683,29 +683,29 @@ pub mod types {
683683
}
684684
}
685685

686-
impl progenitor_client::MultipartRelatedBody for UploadMultipleFilesMultipartParts {
687-
fn as_multipart_parts(&self) -> Vec<progenitor_client::MultipartPart> {
686+
impl crate::progenitor_client::MultipartRelatedBody for UploadMultipleFilesMultipartParts {
687+
fn as_multipart_parts(&self) -> Vec<crate::progenitor_client::MultipartPart> {
688688
vec![
689-
Some(progenitor_client::MultipartPart {
689+
Some(crate::progenitor_client::MultipartPart {
690690
content_type: "application/json",
691691
content_id: "metadata",
692692
bytes: ::std::borrow::Cow::Owned(
693693
::serde_json::to_vec(&self.metadata).expect("failed to serialize field"),
694694
),
695695
}),
696-
Some(progenitor_client::MultipartPart {
696+
Some(crate::progenitor_client::MultipartPart {
697697
content_type: &self.document_content_type,
698698
content_id: "document",
699699
bytes: ::std::borrow::Cow::Borrowed(&self.document),
700700
}),
701-
Some(progenitor_client::MultipartPart {
701+
Some(crate::progenitor_client::MultipartPart {
702702
content_type: &self.thumbnail_content_type,
703703
content_id: "thumbnail",
704704
bytes: ::std::borrow::Cow::Borrowed(&self.thumbnail),
705705
}),
706706
if let Some(ref content_type) = self.attachment_content_type {
707707
if !self.attachment.is_empty() {
708-
Some(progenitor_client::MultipartPart {
708+
Some(crate::progenitor_client::MultipartPart {
709709
content_type: content_type.as_str(),
710710
content_id: "attachment",
711711
bytes: ::std::borrow::Cow::Borrowed(&self.attachment),

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -258,17 +258,17 @@ pub mod types {
258258
}
259259
}
260260

261-
impl progenitor_client::MultipartRelatedBody for UploadFileMultipartParts {
262-
fn as_multipart_parts(&self) -> Vec<progenitor_client::MultipartPart> {
261+
impl crate::progenitor_client::MultipartRelatedBody for UploadFileMultipartParts {
262+
fn as_multipart_parts(&self) -> Vec<crate::progenitor_client::MultipartPart> {
263263
vec![
264-
Some(progenitor_client::MultipartPart {
264+
Some(crate::progenitor_client::MultipartPart {
265265
content_type: "application/json",
266266
content_id: "metadata",
267267
bytes: ::std::borrow::Cow::Owned(
268268
::serde_json::to_vec(&self.metadata).expect("failed to serialize field"),
269269
),
270270
}),
271-
Some(progenitor_client::MultipartPart {
271+
Some(crate::progenitor_client::MultipartPart {
272272
content_type: &self.file_content_type,
273273
content_id: "file",
274274
bytes: ::std::borrow::Cow::Borrowed(&self.file),
@@ -280,29 +280,29 @@ pub mod types {
280280
}
281281
}
282282

283-
impl progenitor_client::MultipartRelatedBody for UploadMultipleFilesMultipartParts {
284-
fn as_multipart_parts(&self) -> Vec<progenitor_client::MultipartPart> {
283+
impl crate::progenitor_client::MultipartRelatedBody for UploadMultipleFilesMultipartParts {
284+
fn as_multipart_parts(&self) -> Vec<crate::progenitor_client::MultipartPart> {
285285
vec![
286-
Some(progenitor_client::MultipartPart {
286+
Some(crate::progenitor_client::MultipartPart {
287287
content_type: "application/json",
288288
content_id: "metadata",
289289
bytes: ::std::borrow::Cow::Owned(
290290
::serde_json::to_vec(&self.metadata).expect("failed to serialize field"),
291291
),
292292
}),
293-
Some(progenitor_client::MultipartPart {
293+
Some(crate::progenitor_client::MultipartPart {
294294
content_type: &self.document_content_type,
295295
content_id: "document",
296296
bytes: ::std::borrow::Cow::Borrowed(&self.document),
297297
}),
298-
Some(progenitor_client::MultipartPart {
298+
Some(crate::progenitor_client::MultipartPart {
299299
content_type: &self.thumbnail_content_type,
300300
content_id: "thumbnail",
301301
bytes: ::std::borrow::Cow::Borrowed(&self.thumbnail),
302302
}),
303303
if let Some(ref content_type) = self.attachment_content_type {
304304
if !self.attachment.is_empty() {
305-
Some(progenitor_client::MultipartPart {
305+
Some(crate::progenitor_client::MultipartPart {
306306
content_type: content_type.as_str(),
307307
content_id: "attachment",
308308
bytes: ::std::borrow::Cow::Borrowed(&self.attachment),

0 commit comments

Comments
 (0)