enable streaming with multiple file types#1278
Closed
drahnr wants to merge 25 commits into
Closed
Conversation
Contributor
Author
|
Could someone take a quick look and allow the workflow? Thanks! |
There was a problem hiding this comment.
Pull request overview
This PR adds initial multipart/form-data request body support to the Progenitor generator and client runtime, along with new fixtures and golden outputs to validate generated code for multipart request bodies.
Changes:
- Add
multipart/form-dataas a recognized body content type and generate request-building code that uses a multipart form builder. - Introduce
FormPart/BinaryFormPart/TextFormPart(plusFilenameandContentTypenewtypes) inprogenitor-clientand aRequestBuilderExt::form_from_parts()helper. - Add a sample OpenAPI spec and extensive generator tests/golden outputs covering mixed multipart field types and encodings.
Reviewed changes
Copilot reviewed 17 out of 18 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| sample_openapi/example_multipart.json | Adds a minimal multipart OpenAPI fixture used by output verification. |
| progenitor-impl/tests/test_specific.rs | Adds multipart-focused generator tests (including edge cases). |
| progenitor-impl/tests/test_output.rs | Adds output verification for the new multipart fixture. |
| progenitor-impl/tests/output/src/example_multipart_positional.rs | New golden output for positional client generation for multipart example. |
| progenitor-impl/tests/output/src/example_multipart_httpmock.rs | New golden output for httpmock helpers for multipart example. |
| progenitor-impl/tests/output/src/example_multipart_cli.rs | New golden output for CLI generation for multipart example. |
| progenitor-impl/tests/output/src/example_multipart_builder.rs | New golden output for builder-style client generation for multipart example. |
| progenitor-impl/tests/output/src/example_multipart_builder_tagged.rs | New golden output for tagged builder-style generation for multipart example. |
| progenitor-impl/src/method.rs | Adds FormData body type + a Form(TypeId) parameter type and emits .form_from_parts(...) for multipart bodies. |
| progenitor-impl/src/lib.rs | Adds generator state for form metadata and generates as_form() impls for multipart form structs. |
| progenitor-impl/src/httpmock.rs | Updates httpmock wrapper generation to account for form parameters. |
| progenitor-impl/src/cli.rs | Updates CLI generation to handle OperationParameterType::Form for body type lookup. |
| progenitor-client/tests/client_test.rs | Adds unit tests for new multipart form part APIs and newtypes. |
| progenitor-client/src/progenitor_client.rs | Implements multipart form part types/newtypes and RequestBuilderExt::form_from_parts(). |
| progenitor-client/Cargo.toml | Adds assert_matches as a dev-dependency for new tests. |
| Cargo.toml | Enables reqwest multipart feature; adds assert_matches; enables tokio macros feature. |
| Cargo.lock | Updates lockfile for new dependencies/features. |
| cargo-progenitor/src/main.rs | Updates generated dependency snippet to include reqwest multipart feature. |
Comments suppressed due to low confidence (1)
progenitor-impl/src/httpmock.rs:235
- httpmock wrapper generation treats multipart/form-data bodies the same as JSON bodies (
json_body_obj). This will not match actual multipart requests and makes the generated httpmock helpers misleading for operations whose body ismultipart/form-data.
For multipart bodies, consider not generating a body matcher by default (or matching only on headers), and let callers add custom matching behavior if they need it.
OperationParameterKind::Body(body_content_type) => match typ {
OperationParameterType::Type(_) | OperationParameterType::Form(_) => (
true,
quote! {
Self(self.0.json_body_obj(value))
},
),
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+425
to
+433
| if meta.is_binary { | ||
| // Binary fields: Option<bytes::Bytes> -> FormPart::Binary | ||
| // Use .into() to support custom binary types via with_conversion | ||
| Some(quote! { | ||
| if let Some(ref val) = self.#ident { | ||
| parts.push((#api_name, progenitor_client::FormPart::Binary( | ||
| progenitor_client::BinaryFormPart { | ||
| data: val.clone().into(), | ||
| filename: None, |
Comment on lines
+447
to
+452
| if let Some(ref val) = self.#ident { | ||
| parts.push((#api_name, progenitor_client::FormPart::Text( | ||
| progenitor_client::TextFormPart { | ||
| value: serde_json::to_string(val) | ||
| .expect("multipart form field serialization should not fail"), | ||
| content_type: #json_content_type, |
Comment on lines
+2178
to
+2179
| let mut fields = IndexMap::new(); | ||
| for (name, property) in properties { |
Comment on lines
+187
to
+196
| /// Binary form part data with optional filename and content-type. | ||
| #[derive(Debug, Clone)] | ||
| pub struct BinaryFormPart { | ||
| /// The binary data | ||
| pub data: Bytes, | ||
| /// Optional filename for the part | ||
| pub filename: Option<Filename>, | ||
| /// Optional content-type override | ||
| pub content_type: Option<ContentType>, | ||
| } |
Comment on lines
+806
to
+812
| #[test] | ||
| #[should_panic(expected = "unreachable")] | ||
| fn test_multipart_empty_properties_panics() { | ||
| let spec = make_multipart_spec("upload_empty", serde_json::json!({})); | ||
| let mut generator = make_builder_generator(); | ||
| let _ = generator.generate_tokens(&spec); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Obsoletes #418 #609
Closes #518
CC @JMendyk