Skip to content

Commit 79861ad

Browse files
committed
Implement Multipart handling for generic parameters
1 parent b047e29 commit 79861ad

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

generate.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ rm src/apis src/models docs -rf
99
--git-user-id=vrchatapi \
1010
--git-repo-id=vrchatapi-rust \
1111
-o . \
12-
-i https://raw.githubusercontent.com/vrchatapi/specification/gh-pages/openapi.yaml \
12+
-i https://raw.githubusercontent.com/vrchatapi/specification/0ec000c2208fcea379372074f42cc6fc97c506d1/openapi.yaml \
1313
--http-user-agent="vrchatapi-rust"
1414
#--global-property debugOperations=true
1515

16+
#https://raw.githubusercontent.com/vrchatapi/specification/gh-pages/openapi.yaml \
17+
18+
1619
# Update entire description (replace entire line, match the random data there) line in Cargo.toml
1720
sed -i 's/^description = ".*"/description = "VRChat API Client for Rust"/' Cargo.toml
1821

@@ -39,7 +42,10 @@ sed -i 's/Result<models::CurrentUser, Error<GetCurrentUserError>>/Result<models:
3942
sed -i "s/local_var_req_builder = local_var_req_builder.json(&\(.*\));/if let Some(\1) = \1 { \0 }/g" src/apis/files_api.rs
4043

4144
#https://github.com/vrchatapi/vrchatapi-rust/pull/30
42-
perl -0pi -e 's|(fn\s+[^(]*\([^)]*)file:\s+:?:?std::path::PathBuf,?([^)]*)((?:(?!\/\/ TODO: support file upload for '\''file'\'' parameter)[\s\S])*)\/\/ TODO: support file upload for '\''file'\'' parameter|\1file: impl Into<::std::borrow::Cow<'\''static, [u8]>>,\n\tfilename: impl Into<::std::borrow::Cow<'\''static, str>>,\n\tmime_type: &str,\2\3let part = reqwest::multipart::Part::bytes(p_form_file).file_name(filename).mime_str(mime_type)?;\n\tmultipart_form = multipart_form.part("file", part);|g' src/apis/files_api.rs
45+
#perl -0pi -e 's|(fn\s+[^(]*\([^)]*)file:\s+:?:?std::path::PathBuf,?([^)]*)((?:(?!\/\/ TODO: support file upload for '\''file'\'' parameter)[\s\S])*)\/\/ TODO: support file upload for '\''file'\'' parameter|\1file: impl Into<::std::borrow::Cow<'\''static, [u8]>>,\n\tfilename: impl Into<::std::borrow::Cow<'\''static, str>>,\n\tmime_type: &str,\2\3let part = reqwest::multipart::Part::bytes(p_form_file).file_name(filename).mime_str(mime_type)?;\n\tmultipart_form = multipart_form.part("file", part);|g' src/apis/files_api.rs
46+
#perl -0pi -e 's|(fn\s+[^(]*\([^)]*)image:\s+:?:?std::path::PathBuf,?([^)]*)((?:(?!\/\/ TODO: support file upload for '\''image'\'' parameter)[\s\S])*)\/\/ TODO: support file upload for '\''image'\'' parameter|\1image: impl Into<::std::borrow::Cow<'\''static, [u8]>>,\n\tfilename: impl Into<::std::borrow::Cow<'\''static, str>>,\n\tmime_type: &str,\2\3let part = reqwest::multipart::Part::bytes(p_form_image).file_name(filename).mime_str(mime_type)?;\n\tmultipart_form = multipart_form.part("image", part);|g' src/apis/invite_api.rs
47+
#This is basically the multipart handling from above, except put in one regex replace
48+
perl -0pi -e 's|(fn\s+[^(]*\([^)]*)([,\s])([\w]+):\s+(?:::)?std::path::PathBuf,?([^)]*)((?:(?!\/\/ TODO: support file upload for '\''\3'\'' parameter)[\s\S])*)\/\/ TODO: support file upload for '\''\3'\'' parameter|\1\2\3: impl Into<::std::borrow::Cow<'\''static, [u8]>>,\n\tfilename: impl Into<::std::borrow::Cow<'\''static, str>>,\n\tmime_type: &str,\4\5let part = reqwest::multipart::Part::bytes(p_form_\3).file_name(filename).mime_str(mime_type)?;\n\tmultipart_form = multipart_form.part("\3", part);|g' src/apis/files_api.rs src/apis/invite_api.rs
4349

4450
find src/ -type f -name "*.rs" -exec sed -i 's/models::models/models/g' {} +
4551

src/apis/invite_api.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,9 @@ pub async fn invite_user(
323323
pub async fn invite_user_with_photo(
324324
configuration: &configuration::Configuration,
325325
user_id: &str,
326-
image: std::path::PathBuf,
326+
image: impl Into<::std::borrow::Cow<'static, [u8]>>,
327+
filename: impl Into<::std::borrow::Cow<'static, str>>,
328+
mime_type: &str,
327329
data: models::InviteRequest,
328330
) -> Result<models::SentNotification, Error<InviteUserWithPhotoError>> {
329331
// add a prefix to parameters to efficiently prevent name collisions
@@ -344,7 +346,10 @@ pub async fn invite_user_with_photo(
344346
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
345347
}
346348
let mut multipart_form = reqwest::multipart::Form::new();
347-
// TODO: support file upload for 'image' parameter
349+
let part = reqwest::multipart::Part::bytes(p_form_image)
350+
.file_name(filename)
351+
.mime_str(mime_type)?;
352+
multipart_form = multipart_form.part("image", part);
348353
multipart_form = multipart_form.text("data", serde_json::to_string_pretty(&p_form_data)?);
349354
req_builder = req_builder.multipart(multipart_form);
350355

@@ -434,7 +439,9 @@ pub async fn request_invite(
434439
pub async fn request_invite_with_photo(
435440
configuration: &configuration::Configuration,
436441
user_id: &str,
437-
image: std::path::PathBuf,
442+
image: impl Into<::std::borrow::Cow<'static, [u8]>>,
443+
filename: impl Into<::std::borrow::Cow<'static, str>>,
444+
mime_type: &str,
438445
data: models::RequestInviteRequest,
439446
) -> Result<models::Notification, Error<RequestInviteWithPhotoError>> {
440447
// add a prefix to parameters to efficiently prevent name collisions
@@ -455,7 +462,10 @@ pub async fn request_invite_with_photo(
455462
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
456463
}
457464
let mut multipart_form = reqwest::multipart::Form::new();
458-
// TODO: support file upload for 'image' parameter
465+
let part = reqwest::multipart::Part::bytes(p_form_image)
466+
.file_name(filename)
467+
.mime_str(mime_type)?;
468+
multipart_form = multipart_form.part("image", part);
459469
multipart_form = multipart_form.text("data", serde_json::to_string_pretty(&p_form_data)?);
460470
req_builder = req_builder.multipart(multipart_form);
461471

@@ -601,7 +611,9 @@ pub async fn respond_invite(
601611
pub async fn respond_invite_with_photo(
602612
configuration: &configuration::Configuration,
603613
notification_id: &str,
604-
image: std::path::PathBuf,
614+
image: impl Into<::std::borrow::Cow<'static, [u8]>>,
615+
filename: impl Into<::std::borrow::Cow<'static, str>>,
616+
mime_type: &str,
605617
data: models::InviteResponse,
606618
) -> Result<models::Notification, Error<RespondInviteWithPhotoError>> {
607619
// add a prefix to parameters to efficiently prevent name collisions
@@ -622,7 +634,10 @@ pub async fn respond_invite_with_photo(
622634
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
623635
}
624636
let mut multipart_form = reqwest::multipart::Form::new();
625-
// TODO: support file upload for 'image' parameter
637+
let part = reqwest::multipart::Part::bytes(p_form_image)
638+
.file_name(filename)
639+
.mime_str(mime_type)?;
640+
multipart_form = multipart_form.part("image", part);
626641
multipart_form = multipart_form.text("data", serde_json::to_string_pretty(&p_form_data)?);
627642
req_builder = req_builder.multipart(multipart_form);
628643

0 commit comments

Comments
 (0)