Skip to content

Commit

Permalink
fix: invalid text 'null' in request when no args given (#29)
Browse files Browse the repository at this point in the history
* fix: invalid text 'null' in request when no args given

in these requests, if the optional args are None, instead of passing a empty request body, a text 'null' will be added, which results in 400 response saying
```
{
    "error": {
        "message": "JSON failed to parse.",
        "status_code": 400
    }
}
```

* Revert "fix: invalid text 'null' in request when no args given"

This reverts commit da82cf9.

* fix: invalid text 'null' in request when no args given

In these requests, if the optional args are None, instead of passing a empty request body, a text 'null' will be added, which results in 400 response saying
```
{
    "error": {
        "message": "JSON failed to parse.",
        "status_code": 400
    }
}
```

This fix checks for the optional args, and only write to the request body if they have values.

It is mainly for `finish_file_data_upload` as it allows an emty body, but the other two will still fail anyway.

* regenerate from 1.18.5 spec

Signed-off-by: C0D3 M4513R <[email protected]>

---------

Signed-off-by: C0D3 M4513R <[email protected]>
Co-authored-by: C0D3 M4513R <[email protected]>
  • Loading branch information
paradox8599 and C0D3-M4513R authored Oct 17, 2024
1 parent dac3382 commit 7d12428
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
3 changes: 3 additions & 0 deletions generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ cat patches/2FA_Current_User.rs >> src/models/current_user.rs
sed -i 's/pub use self::current_user::CurrentUser;/pub use self::current_user::{EitherUserOrTwoFactor, CurrentUser};/g' src/models/mod.rs
sed -i 's/Result<models::CurrentUser, Error<GetCurrentUserError>>/Result<models::EitherUserOrTwoFactor, Error<GetCurrentUserError>>/g' src/apis/authentication_api.rs

# https://github.com/vrchatapi/vrchatapi-rust/pull/29
sed -i "s/local_var_req_builder = local_var_req_builder.json(&\(.*\));/if let Some(\1) = \1 { \0 }/g" src/apis/files_api.rs

cargo fmt
cargo build
cargo test
12 changes: 9 additions & 3 deletions src/apis/files_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ pub async fn create_file(
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
local_var_req_builder = local_var_req_builder.json(&create_file_request);
if let Some(create_file_request) = create_file_request {
local_var_req_builder = local_var_req_builder.json(&create_file_request);
}

let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
Expand Down Expand Up @@ -148,7 +150,9 @@ pub async fn create_file_version(
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
local_var_req_builder = local_var_req_builder.json(&create_file_version_request);
if let Some(create_file_version_request) = create_file_version_request {
local_var_req_builder = local_var_req_builder.json(&create_file_version_request);
}

let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
Expand Down Expand Up @@ -326,7 +330,9 @@ pub async fn finish_file_data_upload(
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
local_var_req_builder = local_var_req_builder.json(&finish_file_data_upload_request);
if let Some(finish_file_data_upload_request) = finish_file_data_upload_request {
local_var_req_builder = local_var_req_builder.json(&finish_file_data_upload_request);
}

let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
Expand Down

0 comments on commit 7d12428

Please sign in to comment.