Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect fields using base64 URL encoding #507

Merged
merged 1 commit into from
Jun 12, 2024

Conversation

paolobarbolini
Copy link
Contributor

Some fields are encoded as base64 URL instead of Base64 Standard. This tries to catch fields requiring URL encoding by searching the description for specific words.

I'm not happy with the current implementation but I'm not too familiar with Python. Any suggestions on how to avoid the description parameter on serde_as?

This resulted into the following diff:

diff --git a/gen/drive2/src/api.rs b/gen/drive2/src/api.rs
index 7f30911f30..cb2689d1ff 100644
--- a/gen/drive2/src/api.rs
+++ b/gen/drive2/src/api.rs
@@ -3019,7 +3019,7 @@ impl client::Part for FileShortcutDetails {}
 pub struct FileThumbnail {
     /// The URL-safe Base64 encoded bytes of the thumbnail image. It should conform to RFC 4648 section 5.
     
-    #[serde_as(as = "Option<::client::serde::standard_base64::Wrapper>")]
+    #[serde_as(as = "Option<::client::serde::urlsafe_base64::Wrapper>")]
     pub image: Option<Vec<u8>>,
     /// The MIME type of the thumbnail.
     #[serde(rename="mimeType")]
diff --git a/gen/drive3/src/api.rs b/gen/drive3/src/api.rs
index 0ec40ea3d6..33887e2bc2 100644
--- a/gen/drive3/src/api.rs
+++ b/gen/drive3/src/api.rs
@@ -2231,7 +2231,7 @@ impl client::Part for FileContentHints {}
 pub struct FileContentHintsThumbnail {
     /// The thumbnail data encoded with URL-safe Base64 (RFC 4648 section 5).
     
-    #[serde_as(as = "Option<::client::serde::standard_base64::Wrapper>")]
+    #[serde_as(as = "Option<::client::serde::urlsafe_base64::Wrapper>")]
     pub image: Option<Vec<u8>>,
     /// The MIME type of the thumbnail.
     #[serde(rename="mimeType")]
diff --git a/gen/firebaseappcheck1_beta/src/api.rs b/gen/firebaseappcheck1_beta/src/api.rs
index 93ba4c06c6..9d43f7c238 100644
--- a/gen/firebaseappcheck1_beta/src/api.rs
+++ b/gen/firebaseappcheck1_beta/src/api.rs
@@ -590,7 +590,7 @@ pub struct GoogleFirebaseAppcheckV1betaExchangeAppAttestAttestationRequest {
     /// Required. The App Attest statement returned by the client-side App Attest API. This is a base64url encoded CBOR object in the JSON response.
     #[serde(rename="attestationStatement")]
     
-    #[serde_as(as = "Option<::client::serde::standard_base64::Wrapper>")]
+    #[serde_as(as = "Option<::client::serde::urlsafe_base64::Wrapper>")]
     pub attestation_statement: Option<Vec<u8>>,
     /// Required. A one-time challenge returned by an immediately prior call to GenerateAppAttestChallenge.
     
diff --git a/gen/gmail1/src/api.rs b/gen/gmail1/src/api.rs
index f8ed7e083f..ffb6b3a33f 100644
--- a/gen/gmail1/src/api.rs
+++ b/gen/gmail1/src/api.rs
@@ -1181,7 +1181,7 @@ pub struct Message {
     pub payload: Option<MessagePart>,
     /// The entire email message in an RFC 2822 formatted and base64url encoded string. Returned in `messages.get` and `drafts.get` responses when the `format=RAW` parameter is supplied.
     
-    #[serde_as(as = "Option<::client::serde::standard_base64::Wrapper>")]
+    #[serde_as(as = "Option<::client::serde::urlsafe_base64::Wrapper>")]
     pub raw: Option<Vec<u8>>,
     /// Estimated size in bytes of the message.
     #[serde(rename="sizeEstimate")]
@@ -1249,7 +1249,7 @@ pub struct MessagePartBody {
     pub attachment_id: Option<String>,
     /// The body data of a MIME message part as a base64url encoded string. May be empty for MIME container types that have no message body or when the body data is sent as a separate attachment. An attachment ID is present if the body data is contained in a separate attachment.
     
-    #[serde_as(as = "Option<::client::serde::standard_base64::Wrapper>")]
+    #[serde_as(as = "Option<::client::serde::urlsafe_base64::Wrapper>")]
     pub data: Option<Vec<u8>>,
     /// Number of bytes for the message part data (encoding notwithstanding).
     

Fixes #496

Copy link
Owner

@Byron Byron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks incredibly neat and simple, too!
As I also don't know python, I have no opinion on how to make it more idiomatic.

Future updates might include changing the search terms, or maybe allowing overrides to force one or another.

@Byron Byron merged commit 46490ae into Byron:main Jun 12, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JsonDecodeError when decoding response for gmail messages.get method
2 participants