changeset 123:907bfb45511b

Update generated drive code
author Lewin Bormann <lbo@spheniscida.de>
date Sun, 25 Oct 2020 18:25:38 +0100
parents 779081e4efe2
children a8e83db9b310
files async-google-apis-common/src/multipart.rs drive_example/src/drive_v3_types.rs generate/generate.py
diffstat 3 files changed, 118 insertions(+), 58 deletions(-) [+]
line wrap: on
line diff
--- a/async-google-apis-common/src/multipart.rs	Sun Oct 25 18:22:02 2020 +0100
+++ b/async-google-apis-common/src/multipart.rs	Sun Oct 25 18:25:38 2020 +0100
@@ -9,7 +9,10 @@
 
 pub const MIME_BOUNDARY: &'static str = "PB0BHe6XN3O6Q4bpnWQgS1pKfMfglTZdifFvh8YIc2APj4Cz3C";
 
-pub fn format_multipart<Req: Serialize + std::fmt::Debug>(req: &Req, data: Bytes) -> anyhow::Result<Bytes> {
+pub fn format_multipart<Req: Serialize + std::fmt::Debug>(
+    req: &Req,
+    data: Bytes,
+) -> anyhow::Result<Bytes> {
     let meta = serde_json::to_string(req).context(format!("{:?}", req))?;
     let mut buf = Vec::with_capacity(meta.len() + (1.5 * (data.len() as f64)) as usize);
 
--- a/drive_example/src/drive_v3_types.rs	Sun Oct 25 18:22:02 2020 +0100
+++ b/drive_example/src/drive_v3_types.rs	Sun Oct 25 18:25:38 2020 +0100
@@ -4159,7 +4159,10 @@
         params: &CommentsCreateParams,
         req: &Comment,
     ) -> Result<Comment> {
-        let rel_path = format!("files/{fileId}/comments", fileId = params.file_id);
+        let rel_path = format!(
+            "files/{fileId}/comments",
+            fileId = percent_encode(params.file_id.as_bytes(), NON_ALPHANUMERIC)
+        );
         let path = "https://www.googleapis.com/drive/v3/".to_string() + &rel_path;
         let tok;
         if self.scopes.is_empty() {
@@ -4194,8 +4197,8 @@
     pub async fn delete(&mut self, params: &CommentsDeleteParams) -> Result<()> {
         let rel_path = format!(
             "files/{fileId}/comments/{commentId}",
-            fileId = params.file_id,
-            commentId = params.comment_id
+            fileId = percent_encode(params.file_id.as_bytes(), NON_ALPHANUMERIC),
+            commentId = percent_encode(params.comment_id.as_bytes(), NON_ALPHANUMERIC)
         );
         let path = "https://www.googleapis.com/drive/v3/".to_string() + &rel_path;
         let tok;
@@ -4230,8 +4233,8 @@
     pub async fn get(&mut self, params: &CommentsGetParams) -> Result<Comment> {
         let rel_path = format!(
             "files/{fileId}/comments/{commentId}",
-            fileId = params.file_id,
-            commentId = params.comment_id
+            fileId = percent_encode(params.file_id.as_bytes(), NON_ALPHANUMERIC),
+            commentId = percent_encode(params.comment_id.as_bytes(), NON_ALPHANUMERIC)
         );
         let path = "https://www.googleapis.com/drive/v3/".to_string() + &rel_path;
         let tok;
@@ -4264,7 +4267,10 @@
 
     /// Lists a file's comments.
     pub async fn list(&mut self, params: &CommentsListParams) -> Result<CommentList> {
-        let rel_path = format!("files/{fileId}/comments", fileId = params.file_id);
+        let rel_path = format!(
+            "files/{fileId}/comments",
+            fileId = percent_encode(params.file_id.as_bytes(), NON_ALPHANUMERIC)
+        );
         let path = "https://www.googleapis.com/drive/v3/".to_string() + &rel_path;
         let tok;
         if self.scopes.is_empty() {
@@ -4302,8 +4308,8 @@
     ) -> Result<Comment> {
         let rel_path = format!(
             "files/{fileId}/comments/{commentId}",
-            fileId = params.file_id,
-            commentId = params.comment_id
+            fileId = percent_encode(params.file_id.as_bytes(), NON_ALPHANUMERIC),
+            commentId = percent_encode(params.comment_id.as_bytes(), NON_ALPHANUMERIC)
         );
         let path = "https://www.googleapis.com/drive/v3/".to_string() + &rel_path;
         let tok;
@@ -4405,7 +4411,10 @@
 
     /// Permanently deletes a shared drive for which the user is an organizer. The shared drive cannot contain any untrashed items.
     pub async fn delete(&mut self, params: &DrivesDeleteParams) -> Result<()> {
-        let rel_path = format!("drives/{driveId}", driveId = params.drive_id);
+        let rel_path = format!(
+            "drives/{driveId}",
+            driveId = percent_encode(params.drive_id.as_bytes(), NON_ALPHANUMERIC)
+        );
         let path = "https://www.googleapis.com/drive/v3/".to_string() + &rel_path;
         let tok;
         if self.scopes.is_empty() {
@@ -4437,7 +4446,10 @@
 
     /// Gets a shared drive's metadata by ID.
     pub async fn get(&mut self, params: &DrivesGetParams) -> Result<Drive> {
-        let rel_path = format!("drives/{driveId}", driveId = params.drive_id);
+        let rel_path = format!(
+            "drives/{driveId}",
+            driveId = percent_encode(params.drive_id.as_bytes(), NON_ALPHANUMERIC)
+        );
         let path = "https://www.googleapis.com/drive/v3/".to_string() + &rel_path;
         let tok;
         if self.scopes.is_empty() {
@@ -4469,7 +4481,10 @@
 
     /// Hides a shared drive from the default view.
     pub async fn hide(&mut self, params: &DrivesHideParams) -> Result<Drive> {
-        let rel_path = format!("drives/{driveId}/hide", driveId = params.drive_id);
+        let rel_path = format!(
+            "drives/{driveId}/hide",
+            driveId = percent_encode(params.drive_id.as_bytes(), NON_ALPHANUMERIC)
+        );
         let path = "https://www.googleapis.com/drive/v3/".to_string() + &rel_path;
         let tok;
         if self.scopes.is_empty() {
@@ -4533,7 +4548,10 @@
 
     /// Restores a shared drive to the default view.
     pub async fn unhide(&mut self, params: &DrivesUnhideParams) -> Result<Drive> {
-        let rel_path = format!("drives/{driveId}/unhide", driveId = params.drive_id);
+        let rel_path = format!(
+            "drives/{driveId}/unhide",
+            driveId = percent_encode(params.drive_id.as_bytes(), NON_ALPHANUMERIC)
+        );
         let path = "https://www.googleapis.com/drive/v3/".to_string() + &rel_path;
         let tok;
         if self.scopes.is_empty() {
@@ -4565,7 +4583,10 @@
 
     /// Updates the metadate for a shared drive.
     pub async fn update(&mut self, params: &DrivesUpdateParams, req: &Drive) -> Result<Drive> {
-        let rel_path = format!("drives/{driveId}", driveId = params.drive_id);
+        let rel_path = format!(
+            "drives/{driveId}",
+            driveId = percent_encode(params.drive_id.as_bytes(), NON_ALPHANUMERIC)
+        );
         let path = "https://www.googleapis.com/drive/v3/".to_string() + &rel_path;
         let tok;
         if self.scopes.is_empty() {
@@ -4633,7 +4654,10 @@
 
     /// Creates a copy of a file and applies any requested updates with patch semantics. Folders cannot be copied.
     pub async fn copy(&mut self, params: &FilesCopyParams, req: &File) -> Result<File> {
-        let rel_path = format!("files/{fileId}/copy", fileId = params.file_id);
+        let rel_path = format!(
+            "files/{fileId}/copy",
+            fileId = percent_encode(params.file_id.as_bytes(), NON_ALPHANUMERIC)
+        );
         let path = "https://www.googleapis.com/drive/v3/".to_string() + &rel_path;
         let tok;
         if self.scopes.is_empty() {
@@ -4798,7 +4822,10 @@
 
     /// Permanently deletes a file owned by the user without moving it to the trash. If the file belongs to a shared drive the user must be an organizer on the parent. If the target is a folder, all descendants owned by the user are also deleted.
     pub async fn delete(&mut self, params: &FilesDeleteParams) -> Result<()> {
-        let rel_path = format!("files/{fileId}", fileId = params.file_id);
+        let rel_path = format!(
+            "files/{fileId}",
+            fileId = percent_encode(params.file_id.as_bytes(), NON_ALPHANUMERIC)
+        );
         let path = "https://www.googleapis.com/drive/v3/".to_string() + &rel_path;
         let tok;
         if self.scopes.is_empty() {
@@ -4869,9 +4896,12 @@
     pub async fn export(
         &mut self,
         params: &FilesExportParams,
-        dst: Option<&mut dyn std::io::Write>,
+        dst: Option<&mut (dyn tokio::io::AsyncWrite + std::marker::Unpin)>,
     ) -> Result<DownloadResponse<()>> {
-        let rel_path = format!("files/{fileId}/export", fileId = params.file_id);
+        let rel_path = format!(
+            "files/{fileId}/export",
+            fileId = percent_encode(params.file_id.as_bytes(), NON_ALPHANUMERIC)
+        );
         let path = "https://www.googleapis.com/drive/v3/".to_string() + &rel_path;
 
         let tok;
@@ -4944,9 +4974,12 @@
     pub async fn get(
         &mut self,
         params: &FilesGetParams,
-        dst: Option<&mut dyn std::io::Write>,
+        dst: Option<&mut (dyn tokio::io::AsyncWrite + std::marker::Unpin)>,
     ) -> Result<DownloadResponse<File>> {
-        let rel_path = format!("files/{fileId}", fileId = params.file_id);
+        let rel_path = format!(
+            "files/{fileId}",
+            fileId = percent_encode(params.file_id.as_bytes(), NON_ALPHANUMERIC)
+        );
         let path = "https://www.googleapis.com/drive/v3/".to_string() + &rel_path;
 
         let tok;
@@ -5012,7 +5045,10 @@
 
     /// Updates a file's metadata and/or content. This method supports patch semantics.
     pub async fn update(&mut self, params: &FilesUpdateParams, req: &File) -> Result<File> {
-        let rel_path = format!("files/{fileId}", fileId = params.file_id);
+        let rel_path = format!(
+            "files/{fileId}",
+            fileId = percent_encode(params.file_id.as_bytes(), NON_ALPHANUMERIC)
+        );
         let path = "https://www.googleapis.com/drive/v3/".to_string() + &rel_path;
         let tok;
         if self.scopes.is_empty() {
@@ -5052,7 +5088,10 @@
         req: &File,
         data: hyper::body::Bytes,
     ) -> Result<File> {
-        let rel_path = format!("/upload/drive/v3/files/{fileId}", fileId = params.file_id);
+        let rel_path = format!(
+            "/upload/drive/v3/files/{fileId}",
+            fileId = percent_encode(params.file_id.as_bytes(), NON_ALPHANUMERIC)
+        );
         let path = "https://www.googleapis.com/".to_string() + &rel_path;
 
         let tok;
@@ -5099,7 +5138,7 @@
     ) -> Result<ResumableUpload<'client, File>> {
         let rel_path = format!(
             "/resumable/upload/drive/v3/files/{fileId}",
-            fileId = params.file_id
+            fileId = percent_encode(params.file_id.as_bytes(), NON_ALPHANUMERIC)
         );
         let path = "https://www.googleapis.com/".to_string() + &rel_path;
         let tok;
@@ -5155,9 +5194,12 @@
         &mut self,
         params: &FilesWatchParams,
         req: &Channel,
-        dst: Option<&mut dyn std::io::Write>,
+        dst: Option<&mut (dyn tokio::io::AsyncWrite + std::marker::Unpin)>,
     ) -> Result<DownloadResponse<Channel>> {
-        let rel_path = format!("files/{fileId}/watch", fileId = params.file_id);
+        let rel_path = format!(
+            "files/{fileId}/watch",
+            fileId = percent_encode(params.file_id.as_bytes(), NON_ALPHANUMERIC)
+        );
         let path = "https://www.googleapis.com/drive/v3/".to_string() + &rel_path;
 
         let tok;
@@ -5231,7 +5273,10 @@
         params: &PermissionsCreateParams,
         req: &Permission,
     ) -> Result<Permission> {
-        let rel_path = format!("files/{fileId}/permissions", fileId = params.file_id);
+        let rel_path = format!(
+            "files/{fileId}/permissions",
+            fileId = percent_encode(params.file_id.as_bytes(), NON_ALPHANUMERIC)
+        );
         let path = "https://www.googleapis.com/drive/v3/".to_string() + &rel_path;
         let tok;
         if self.scopes.is_empty() {
@@ -5266,8 +5311,8 @@
     pub async fn delete(&mut self, params: &PermissionsDeleteParams) -> Result<()> {
         let rel_path = format!(
             "files/{fileId}/permissions/{permissionId}",
-            fileId = params.file_id,
-            permissionId = params.permission_id
+            fileId = percent_encode(params.file_id.as_bytes(), NON_ALPHANUMERIC),
+            permissionId = percent_encode(params.permission_id.as_bytes(), NON_ALPHANUMERIC)
         );
         let path = "https://www.googleapis.com/drive/v3/".to_string() + &rel_path;
         let tok;
@@ -5302,8 +5347,8 @@
     pub async fn get(&mut self, params: &PermissionsGetParams) -> Result<Permission> {
         let rel_path = format!(
             "files/{fileId}/permissions/{permissionId}",
-            fileId = params.file_id,
-            permissionId = params.permission_id
+            fileId = percent_encode(params.file_id.as_bytes(), NON_ALPHANUMERIC),
+            permissionId = percent_encode(params.permission_id.as_bytes(), NON_ALPHANUMERIC)
         );
         let path = "https://www.googleapis.com/drive/v3/".to_string() + &rel_path;
         let tok;
@@ -5336,7 +5381,10 @@
 
     /// Lists a file's or shared drive's permissions.
     pub async fn list(&mut self, params: &PermissionsListParams) -> Result<PermissionList> {
-        let rel_path = format!("files/{fileId}/permissions", fileId = params.file_id);
+        let rel_path = format!(
+            "files/{fileId}/permissions",
+            fileId = percent_encode(params.file_id.as_bytes(), NON_ALPHANUMERIC)
+        );
         let path = "https://www.googleapis.com/drive/v3/".to_string() + &rel_path;
         let tok;
         if self.scopes.is_empty() {
@@ -5374,8 +5422,8 @@
     ) -> Result<Permission> {
         let rel_path = format!(
             "files/{fileId}/permissions/{permissionId}",
-            fileId = params.file_id,
-            permissionId = params.permission_id
+            fileId = percent_encode(params.file_id.as_bytes(), NON_ALPHANUMERIC),
+            permissionId = percent_encode(params.permission_id.as_bytes(), NON_ALPHANUMERIC)
         );
         let path = "https://www.googleapis.com/drive/v3/".to_string() + &rel_path;
         let tok;
@@ -5446,8 +5494,8 @@
     pub async fn create(&mut self, params: &RepliesCreateParams, req: &Reply) -> Result<Reply> {
         let rel_path = format!(
             "files/{fileId}/comments/{commentId}/replies",
-            fileId = params.file_id,
-            commentId = params.comment_id
+            fileId = percent_encode(params.file_id.as_bytes(), NON_ALPHANUMERIC),
+            commentId = percent_encode(params.comment_id.as_bytes(), NON_ALPHANUMERIC)
         );
         let path = "https://www.googleapis.com/drive/v3/".to_string() + &rel_path;
         let tok;
@@ -5483,9 +5531,9 @@
     pub async fn delete(&mut self, params: &RepliesDeleteParams) -> Result<()> {
         let rel_path = format!(
             "files/{fileId}/comments/{commentId}/replies/{replyId}",
-            fileId = params.file_id,
-            commentId = params.comment_id,
-            replyId = params.reply_id
+            fileId = percent_encode(params.file_id.as_bytes(), NON_ALPHANUMERIC),
+            commentId = percent_encode(params.comment_id.as_bytes(), NON_ALPHANUMERIC),
+            replyId = percent_encode(params.reply_id.as_bytes(), NON_ALPHANUMERIC)
         );
         let path = "https://www.googleapis.com/drive/v3/".to_string() + &rel_path;
         let tok;
@@ -5520,9 +5568,9 @@
     pub async fn get(&mut self, params: &RepliesGetParams) -> Result<Reply> {
         let rel_path = format!(
             "files/{fileId}/comments/{commentId}/replies/{replyId}",
-            fileId = params.file_id,
-            commentId = params.comment_id,
-            replyId = params.reply_id
+            fileId = percent_encode(params.file_id.as_bytes(), NON_ALPHANUMERIC),
+            commentId = percent_encode(params.comment_id.as_bytes(), NON_ALPHANUMERIC),
+            replyId = percent_encode(params.reply_id.as_bytes(), NON_ALPHANUMERIC)
         );
         let path = "https://www.googleapis.com/drive/v3/".to_string() + &rel_path;
         let tok;
@@ -5557,8 +5605,8 @@
     pub async fn list(&mut self, params: &RepliesListParams) -> Result<ReplyList> {
         let rel_path = format!(
             "files/{fileId}/comments/{commentId}/replies",
-            fileId = params.file_id,
-            commentId = params.comment_id
+            fileId = percent_encode(params.file_id.as_bytes(), NON_ALPHANUMERIC),
+            commentId = percent_encode(params.comment_id.as_bytes(), NON_ALPHANUMERIC)
         );
         let path = "https://www.googleapis.com/drive/v3/".to_string() + &rel_path;
         let tok;
@@ -5593,9 +5641,9 @@
     pub async fn update(&mut self, params: &RepliesUpdateParams, req: &Reply) -> Result<Reply> {
         let rel_path = format!(
             "files/{fileId}/comments/{commentId}/replies/{replyId}",
-            fileId = params.file_id,
-            commentId = params.comment_id,
-            replyId = params.reply_id
+            fileId = percent_encode(params.file_id.as_bytes(), NON_ALPHANUMERIC),
+            commentId = percent_encode(params.comment_id.as_bytes(), NON_ALPHANUMERIC),
+            replyId = percent_encode(params.reply_id.as_bytes(), NON_ALPHANUMERIC)
         );
         let path = "https://www.googleapis.com/drive/v3/".to_string() + &rel_path;
         let tok;
@@ -5666,8 +5714,8 @@
     pub async fn delete(&mut self, params: &RevisionsDeleteParams) -> Result<()> {
         let rel_path = format!(
             "files/{fileId}/revisions/{revisionId}",
-            fileId = params.file_id,
-            revisionId = params.revision_id
+            fileId = percent_encode(params.file_id.as_bytes(), NON_ALPHANUMERIC),
+            revisionId = percent_encode(params.revision_id.as_bytes(), NON_ALPHANUMERIC)
         );
         let path = "https://www.googleapis.com/drive/v3/".to_string() + &rel_path;
         let tok;
@@ -5707,12 +5755,12 @@
     pub async fn get(
         &mut self,
         params: &RevisionsGetParams,
-        dst: Option<&mut dyn std::io::Write>,
+        dst: Option<&mut (dyn tokio::io::AsyncWrite + std::marker::Unpin)>,
     ) -> Result<DownloadResponse<Revision>> {
         let rel_path = format!(
             "files/{fileId}/revisions/{revisionId}",
-            fileId = params.file_id,
-            revisionId = params.revision_id
+            fileId = percent_encode(params.file_id.as_bytes(), NON_ALPHANUMERIC),
+            revisionId = percent_encode(params.revision_id.as_bytes(), NON_ALPHANUMERIC)
         );
         let path = "https://www.googleapis.com/drive/v3/".to_string() + &rel_path;
 
@@ -5747,7 +5795,10 @@
 
     /// Lists a file's revisions.
     pub async fn list(&mut self, params: &RevisionsListParams) -> Result<RevisionList> {
-        let rel_path = format!("files/{fileId}/revisions", fileId = params.file_id);
+        let rel_path = format!(
+            "files/{fileId}/revisions",
+            fileId = percent_encode(params.file_id.as_bytes(), NON_ALPHANUMERIC)
+        );
         let path = "https://www.googleapis.com/drive/v3/".to_string() + &rel_path;
         let tok;
         if self.scopes.is_empty() {
@@ -5785,8 +5836,8 @@
     ) -> Result<Revision> {
         let rel_path = format!(
             "files/{fileId}/revisions/{revisionId}",
-            fileId = params.file_id,
-            revisionId = params.revision_id
+            fileId = percent_encode(params.file_id.as_bytes(), NON_ALPHANUMERIC),
+            revisionId = percent_encode(params.revision_id.as_bytes(), NON_ALPHANUMERIC)
         );
         let path = "https://www.googleapis.com/drive/v3/".to_string() + &rel_path;
         let tok;
@@ -5894,7 +5945,7 @@
     pub async fn delete(&mut self, params: &TeamdrivesDeleteParams) -> Result<()> {
         let rel_path = format!(
             "teamdrives/{teamDriveId}",
-            teamDriveId = params.team_drive_id
+            teamDriveId = percent_encode(params.team_drive_id.as_bytes(), NON_ALPHANUMERIC)
         );
         let path = "https://www.googleapis.com/drive/v3/".to_string() + &rel_path;
         let tok;
@@ -5929,7 +5980,7 @@
     pub async fn get(&mut self, params: &TeamdrivesGetParams) -> Result<TeamDrive> {
         let rel_path = format!(
             "teamdrives/{teamDriveId}",
-            teamDriveId = params.team_drive_id
+            teamDriveId = percent_encode(params.team_drive_id.as_bytes(), NON_ALPHANUMERIC)
         );
         let path = "https://www.googleapis.com/drive/v3/".to_string() + &rel_path;
         let tok;
@@ -6000,7 +6051,7 @@
     ) -> Result<TeamDrive> {
         let rel_path = format!(
             "teamdrives/{teamDriveId}",
-            teamDriveId = params.team_drive_id
+            teamDriveId = percent_encode(params.team_drive_id.as_bytes(), NON_ALPHANUMERIC)
         );
         let path = "https://www.googleapis.com/drive/v3/".to_string() + &rel_path;
         let tok;
--- a/generate/generate.py	Sun Oct 25 18:22:02 2020 +0100
+++ b/generate/generate.py	Sun Oct 25 18:25:38 2020 +0100
@@ -234,7 +234,10 @@
 
 def resolve_parameters(string, paramsname='params'):
     """Returns a Rust syntax for formatting the given string with API
-    parameters, and a list of (snake-case) API parameters that are used. """
+    parameters, and a list of (snake-case) API parameters that are used. This
+    is typically used to format URL paths containing required parameters for an
+    API call.
+    """
     pat = re.compile('\{\+?(\w+)\}')
     params = re.findall(pat, string)
     snakeparams = [rust_identifier(p) for p in params]
@@ -296,6 +299,9 @@
 
         http_method = method['httpMethod']
         has_global_params = 'parameters' in discdoc
+        # This relies on URL path parameters being required parameters (not
+        # optional). If this invariant is not fulfilled, the Rust code may not
+        # compile.
         formatted_path, required_params = resolve_parameters(method['path'])
         formatted_simple_upload_path, required_params = resolve_parameters(simple_upload_path)
         formatted_resumable_upload_path, required_params = resolve_parameters(resumable_upload_path)