diff --git a/qbittorrent-web-api-gen/api-4_1.md b/qbittorrent-web-api-gen/api-4_1.md index 0b4cfea..db5c267 100644 --- a/qbittorrent-web-api-gen/api-4_1.md +++ b/qbittorrent-web-api-gen/api-4_1.md @@ -1287,7 +1287,7 @@ Name: `banPeers` Parameter | Type | Description ----------------------------------|---------|------------ -`peers` | string | The peer to ban, or multiple peers separated by a pipe `\|`. Each peer is a colon-separated `host:port` +`peers` | string | The peer to ban, or multiple peers separated by a pipe. Each peer is a colon-separated `host:port` **Returns:** @@ -1310,11 +1310,11 @@ Parameter | Type | Description `filter` _optional_ | string | Filter torrent list by state. Allowed state filters: `all`, `downloading`, `seeding`, `completed`, `paused`, `active`, `inactive`, `resumed`, `stalled`, `stalled_uploading`, `stalled_downloading`, `errored` `category` _optional_ | string | Get torrents with the given category (empty string means "without category"; no "category" parameter means "any category" <- broken until [#11748](https://github.com/qbittorrent/qBittorrent/issues/11748) is resolved). Remember to URL-encode the category name. For example, `My category` becomes `My%20category` `tag` _optional_ | string | Get torrents with the given tag (empty string means "without tag"; no "tag" parameter means "any tag". Remember to URL-encode the category name. For example, `My tag` becomes `My%20tag` -`sort` _optional_ | string | Sort torrents by given key. They can be sorted using any field of the response's JSON array (which are documented below) as the sort key. +`sort` _optional_ | string | Sort torrents by given key. They can be sorted using any field of the response (which are documented below) as the sort key. `reverse` _optional_ | bool | Enable reverse sorting. Defaults to `false` `limit` _optional_ | integer | Limit the number of torrents returned `offset` _optional_ | integer | Set offset (if less than 0, offset from end) -`hashes` _optional_ | string | Filter by hashes. Can contain multiple hashes separated by `\|` +`hashes` _optional_ | string | Filter by hashes. Can contain multiple hashes separated by a pipe Example: @@ -1640,7 +1640,7 @@ Name: `files` Parameter | Type | Description ----------|--------|------------ `hash` | string | The hash of the torrent you want to get the contents of -`indexes` _optional_ | string | The indexes of the files you want to retrieve. `indexes` can contain multiple values separated by `\|`. +`indexes` _optional_ | string | The indexes of the files you want to retrieve. `indexes` can contain multiple values separated by a pipe. **Returns:** @@ -1761,7 +1761,7 @@ Name: `pause` Parameter | Type | Description ------------|----------|------------ -`hashes` | string | The hashes of the torrents you want to pause. `hashes` can contain multiple hashes separated by `\|`, to pause multiple torrents, or set to `all`, to pause all torrents. +`hashes` | string | The hashes of the torrents you want to pause. `hashes` can contain multiple hashes separated by a pipe, to pause multiple torrents, or set to `all`, to pause all torrents. Example: @@ -1785,7 +1785,7 @@ Name: `resume` Parameter | Type | Description ------------|----------|------------ -`hashes` | string | The hashes of the torrents you want to resume. `hashes` can contain multiple hashes separated by `\|`, to resume multiple torrents, or set to `all`, to resume all torrents. +`hashes` | string | The hashes of the torrents you want to resume. `hashes` can contain multiple hashes separated by a pipe, to resume multiple torrents, or set to `all`, to resume all torrents. Example: @@ -1809,7 +1809,7 @@ Name: `delete` Parameter | Type | Description ------------|----------|------------ -`hashes` | string | The hashes of the torrents you want to delete. `hashes` can contain multiple hashes separated by `\|`, to delete multiple torrents, or set to `all`, to delete all torrents. +`hashes` | string | The hashes of the torrents you want to delete. `hashes` can contain multiple hashes separated by a pipe, to delete multiple torrents, or set to `all`, to delete all torrents. `deleteFiles` | bool | If set to `true`, the downloaded data will also be deleted, otherwise has no effect. Example: @@ -1834,7 +1834,7 @@ Name: `recheck` Parameter | Type | Description ------------|----------|------------ -`hashes` | string | The hashes of the torrents you want to recheck. `hashes` can contain multiple hashes separated by `\|`, to recheck multiple torrents, or set to `all`, to recheck all torrents. +`hashes` | string | The hashes of the torrents you want to recheck. `hashes` can contain multiple hashes separated by a pipe, to recheck multiple torrents, or set to `all`, to recheck all torrents. Example: @@ -1858,7 +1858,7 @@ Name: `reannounce` Parameter | Type | Description ------------|----------|------------ -`hashes` | string | The hashes of the torrents you want to reannounce. `hashes` can contain multiple hashes separated by `\|`, to reannounce multiple torrents, or set to `all`, to reannounce all torrents. +`hashes` | string | The hashes of the torrents you want to reannounce. `hashes` can contain multiple hashes separated by a pipe, to reannounce multiple torrents, or set to `all`, to reannounce all torrents. Example: @@ -2032,7 +2032,7 @@ Name: `removeTrackers` Parameter | Type | Description ----------------------------------|---------|------------ `hash` | string | The hash of the torrent -`urls` | string | URLs to remove, separated by `\|` +`urls` | string | URLs to remove, separated by a pipe **Returns:** @@ -2050,8 +2050,8 @@ Name: `addPeers` Parameter | Type | Description ----------------------------------|---------|------------ -`hashes` | string | The hash of the torrent, or multiple hashes separated by a pipe `\|` -`peers` | string | The peer to add, or multiple peers separated by a pipe `\|`. Each peer is a colon-separated `host:port` +`hashes` | string | The hash of the torrent, or multiple hashes separated by a pipe +`peers` | string | The peer to add, or multiple peers separated by a pipe. Each peer is a colon-separated `host:port` **Returns:** @@ -2070,7 +2070,7 @@ Name: `increasePrio` Parameter | Type | Description ------------|----------|------------ -`hashes` | string | The hashes of the torrents you want to increase the priority of. `hashes` can contain multiple hashes separated by `\|`, to increase the priority of multiple torrents, or set to `all`, to increase the priority of all torrents. +`hashes` | string | The hashes of the torrents you want to increase the priority of. `hashes` can contain multiple hashes separated by a pipe, to increase the priority of multiple torrents, or set to `all`, to increase the priority of all torrents. Example: @@ -2095,7 +2095,7 @@ Name: `decreasePrio` Parameter | Type | Description ------------|----------|------------ -`hashes` | string | The hashes of the torrents you want to decrease the priority of. `hashes` can contain multiple hashes separated by `\|`, to decrease the priority of multiple torrents, or set to `all`, to decrease the priority of all torrents. +`hashes` | string | The hashes of the torrents you want to decrease the priority of. `hashes` can contain multiple hashes separated by a pipe, to decrease the priority of multiple torrents, or set to `all`, to decrease the priority of all torrents. Example: @@ -2120,7 +2120,7 @@ Name: `topPrio` Parameter | Type | Description ------------|----------|------------ -`hashes` | string | The hashes of the torrents you want to set to the maximum priority. `hashes` can contain multiple hashes separated by `\|`, to set multiple torrents to the maximum priority, or set to `all`, to set all torrents to the maximum priority. +`hashes` | string | The hashes of the torrents you want to set to the maximum priority. `hashes` can contain multiple hashes separated by a pipe, to set multiple torrents to the maximum priority, or set to `all`, to set all torrents to the maximum priority. Example: @@ -2145,7 +2145,7 @@ Name: `bottomPrio` Parameter | Type | Description ------------|----------|------------ -`hashes` | string | The hashes of the torrents you want to set to the minimum priority. `hashes` can contain multiple hashes separated by `\|`, to set multiple torrents to the minimum priority, or set to `all`, to set all torrents to the minimum priority. +`hashes` | string | The hashes of the torrents you want to set to the minimum priority. `hashes` can contain multiple hashes separated by a pipe, to set multiple torrents to the minimum priority, or set to `all`, to set all torrents to the minimum priority. Example: @@ -2169,7 +2169,7 @@ Name: `filePrio` Parameter | Type | Description ----------------------------------|---------|------------ `hash` | string | The hash of the torrent -`id` | string | File ids, separated by `\|` +`id` | string | File ids, separated by a pipe `priority` | object | priority object see table below. File priority to set (consult [torrent contents API](#get-torrent-contents) for possible values) `id` values correspond to file position inside the array returned by [torrent contents API](#get-torrent-contents), e.g. `id=0` for first file, `id=1` for second file, etc. @@ -2676,7 +2676,7 @@ Name: `toggleSequentialDownload` Parameter | Type | Description ------------|----------|------------ -`hashes` | string | The hashes of the torrents you want to toggle sequential download for. `hashes` can contain multiple hashes separated by `\|`, to toggle sequential download for multiple torrents, or set to `all`, to toggle sequential download for all torrents. +`hashes` | string | The hashes of the torrents you want to toggle sequential download for. `hashes` can contain multiple hashes separated by a pipe, to toggle sequential download for multiple torrents, or set to `all`, to toggle sequential download for all torrents. Example: @@ -2700,7 +2700,7 @@ Name: `toggleFirstLastPiecePrio` Parameter | Type | Description ------------|----------|------------ -`hashes` | string | The hashes of the torrents you want to toggle the first/last piece priority for. `hashes` can contain multiple hashes separated by `\|`, to toggle the first/last piece priority for multiple torrents, or set to `all`, to toggle the first/last piece priority for all torrents. +`hashes` | string | The hashes of the torrents you want to toggle the first/last piece priority for. `hashes` can contain multiple hashes separated by a pipe, to toggle the first/last piece priority for multiple torrents, or set to `all`, to toggle the first/last piece priority for all torrents. Example: @@ -3115,7 +3115,7 @@ Name: `start` Parameter | Type | Description ----------------------------------|---------|------------ `pattern` | string | Pattern to search for (e.g. "Ubuntu 18.04") -`plugins` | string | Plugins to use for searching (e.g. "legittorrents"). Supports multiple plugins separated by `\|`. Also supports `all` and `enabled` +`plugins` | string | Plugins to use for searching (e.g. "legittorrents"). Supports multiple plugins separated by a pipe. Also supports `all` and `enabled` `category` | string | Categories to limit your search to (e.g. "legittorrents"). Available categories depend on the specified `plugins`. Also supports `all` **Returns:** @@ -3353,7 +3353,7 @@ Name: `installPlugin` Parameter | Type | Description ----------------------------------|---------|------------ -`sources` | string | Url or file path of the plugin to install (e.g. "[https://raw.githubusercontent.com/qbittorrent/search-plugins/master/nova3/engines/legittorrents.py](https://raw.githubusercontent.com/qbittorrent/search-plugins/master/nova3/engines/legittorrents.py)"). Supports multiple sources separated by `\|` +`sources` | string | Url or file path of the plugin to install (e.g. "[https://raw.githubusercontent.com/qbittorrent/search-plugins/master/nova3/engines/legittorrents.py](https://raw.githubusercontent.com/qbittorrent/search-plugins/master/nova3/engines/legittorrents.py)"). Supports multiple sources separated by a pipe **Returns:** @@ -3369,7 +3369,7 @@ Name: `uninstallPlugin` Parameter | Type | Description ----------------------------------|---------|------------ -`names` | string | Name of the plugin to uninstall (e.g. "legittorrents"). Supports multiple names separated by `\|` +`names` | string | Name of the plugin to uninstall (e.g. "legittorrents"). Supports multiple names separated by a pipe **Returns:** @@ -3385,7 +3385,7 @@ Name: `enablePlugin` Parameter | Type | Description ----------------------------------|---------|------------ -`names` | string | Name of the plugin to enable/disable (e.g. "legittorrents"). Supports multiple names separated by `\|` +`names` | string | Name of the plugin to enable/disable (e.g. "legittorrents"). Supports multiple names separated by a pipe `enable` | bool | Whether the plugins should be enabled **Returns:** diff --git a/qbittorrent-web-api-gen/groups.txt b/qbittorrent-web-api-gen/groups.txt index 00654f3..d0d2dd7 100644 --- a/qbittorrent-web-api-gen/groups.txt +++ b/qbittorrent-web-api-gen/groups.txt @@ -3084,15 +3084,16 @@ Parameters( TypeWithoutName { types: [ - String( + JoinedStringArray( TypeInfo { name: "peers", description: Some( - "The peer to ban, or multiple peers separated by a pipe \\", + "The peer to ban, or multiple peers separated by a pipe. Each peer is a colon-separated host:port", ), is_optional: false, - is_list: false, + is_list: true, }, + "|", ), ], is_list: false, @@ -3155,10 +3156,10 @@ TypeInfo { name: "sort", description: Some( - "Sort torrents by given key. They can be sorted using any field of the response's JSON array (which are documented below) as the sort key.", + "Sort torrents by given key. They can be sorted using any field of the response (which are documented below) as the sort key.", ), is_optional: true, - is_list: true, + is_list: false, }, ), Bool( @@ -3191,15 +3192,16 @@ is_list: false, }, ), - String( + JoinedStringArray( TypeInfo { name: "hashes", description: Some( - "Filter by hashes. Can contain multiple hashes separated by \\", + "Filter by hashes. Can contain multiple hashes separated by a pipe", ), is_optional: true, - is_list: false, + is_list: true, }, + "|", ), ], is_list: false, @@ -4393,15 +4395,16 @@ is_list: false, }, ), - String( + JoinedStringArray( TypeInfo { name: "indexes", description: Some( - "The indexes of the files you want to retrieve. indexes can contain multiple values separated by \\", + "The indexes of the files you want to retrieve. indexes can contain multiple values separated by a pipe.", ), is_optional: true, - is_list: false, + is_list: true, }, + "|", ), ], is_list: false, @@ -4630,15 +4633,16 @@ Parameters( TypeWithoutName { types: [ - String( + JoinedStringArray( TypeInfo { name: "hashes", description: Some( - "The hashes of the torrents you want to pause. hashes can contain multiple hashes separated by \\", + "The hashes of the torrents you want to pause. hashes can contain multiple hashes separated by a pipe, to pause multiple torrents, or set to all, to pause all torrents.", ), is_optional: false, - is_list: false, + is_list: true, }, + "|", ), ], is_list: false, @@ -4656,15 +4660,16 @@ Parameters( TypeWithoutName { types: [ - String( + JoinedStringArray( TypeInfo { name: "hashes", description: Some( - "The hashes of the torrents you want to resume. hashes can contain multiple hashes separated by \\", + "The hashes of the torrents you want to resume. hashes can contain multiple hashes separated by a pipe, to resume multiple torrents, or set to all, to resume all torrents.", ), is_optional: false, - is_list: false, + is_list: true, }, + "|", ), ], is_list: false, @@ -4682,15 +4687,16 @@ Parameters( TypeWithoutName { types: [ - String( + JoinedStringArray( TypeInfo { name: "hashes", description: Some( - "The hashes of the torrents you want to delete. hashes can contain multiple hashes separated by \\", + "The hashes of the torrents you want to delete. hashes can contain multiple hashes separated by a pipe, to delete multiple torrents, or set to all, to delete all torrents.", ), is_optional: false, - is_list: false, + is_list: true, }, + "|", ), Bool( TypeInfo { @@ -4718,15 +4724,16 @@ Parameters( TypeWithoutName { types: [ - String( + JoinedStringArray( TypeInfo { name: "hashes", description: Some( - "The hashes of the torrents you want to recheck. hashes can contain multiple hashes separated by \\", + "The hashes of the torrents you want to recheck. hashes can contain multiple hashes separated by a pipe, to recheck multiple torrents, or set to all, to recheck all torrents.", ), is_optional: false, - is_list: false, + is_list: true, }, + "|", ), ], is_list: false, @@ -4744,15 +4751,16 @@ Parameters( TypeWithoutName { types: [ - String( + JoinedStringArray( TypeInfo { name: "hashes", description: Some( - "The hashes of the torrents you want to reannounce. hashes can contain multiple hashes separated by \\", + "The hashes of the torrents you want to reannounce. hashes can contain multiple hashes separated by a pipe, to reannounce multiple torrents, or set to all, to reannounce all torrents.", ), is_optional: false, - is_list: false, + is_list: true, }, + "|", ), ], is_list: false, @@ -5010,15 +5018,16 @@ is_list: false, }, ), - String( + JoinedStringArray( TypeInfo { name: "urls", description: Some( - "URLs to remove, separated by \\", + "URLs to remove, separated by a pipe", ), is_optional: false, - is_list: false, + is_list: true, }, + "|", ), ], is_list: false, @@ -5036,25 +5045,27 @@ Parameters( TypeWithoutName { types: [ - String( + JoinedStringArray( TypeInfo { name: "hashes", description: Some( - "The hash of the torrent, or multiple hashes separated by a pipe \\", + "The hash of the torrent, or multiple hashes separated by a pipe", ), is_optional: false, - is_list: false, + is_list: true, }, + "|", ), - String( + JoinedStringArray( TypeInfo { name: "peers", description: Some( - "The peer to add, or multiple peers separated by a pipe \\", + "The peer to add, or multiple peers separated by a pipe. Each peer is a colon-separated host:port", ), is_optional: false, - is_list: false, + is_list: true, }, + "|", ), ], is_list: false, @@ -5072,15 +5083,16 @@ Parameters( TypeWithoutName { types: [ - String( + JoinedStringArray( TypeInfo { name: "hashes", description: Some( - "The hashes of the torrents you want to increase the priority of. hashes can contain multiple hashes separated by \\", + "The hashes of the torrents you want to increase the priority of. hashes can contain multiple hashes separated by a pipe, to increase the priority of multiple torrents, or set to all, to increase the priority of all torrents.", ), is_optional: false, - is_list: false, + is_list: true, }, + "|", ), ], is_list: false, @@ -5098,15 +5110,16 @@ Parameters( TypeWithoutName { types: [ - String( + JoinedStringArray( TypeInfo { name: "hashes", description: Some( - "The hashes of the torrents you want to decrease the priority of. hashes can contain multiple hashes separated by \\", + "The hashes of the torrents you want to decrease the priority of. hashes can contain multiple hashes separated by a pipe, to decrease the priority of multiple torrents, or set to all, to decrease the priority of all torrents.", ), is_optional: false, - is_list: false, + is_list: true, }, + "|", ), ], is_list: false, @@ -5124,15 +5137,16 @@ Parameters( TypeWithoutName { types: [ - String( + JoinedStringArray( TypeInfo { name: "hashes", description: Some( - "The hashes of the torrents you want to set to the maximum priority. hashes can contain multiple hashes separated by \\", + "The hashes of the torrents you want to set to the maximum priority. hashes can contain multiple hashes separated by a pipe, to set multiple torrents to the maximum priority, or set to all, to set all torrents to the maximum priority.", ), is_optional: false, - is_list: false, + is_list: true, }, + "|", ), ], is_list: false, @@ -5150,15 +5164,16 @@ Parameters( TypeWithoutName { types: [ - String( + JoinedStringArray( TypeInfo { name: "hashes", description: Some( - "The hashes of the torrents you want to set to the minimum priority. hashes can contain multiple hashes separated by \\", + "The hashes of the torrents you want to set to the minimum priority. hashes can contain multiple hashes separated by a pipe, to set multiple torrents to the minimum priority, or set to all, to set all torrents to the minimum priority.", ), is_optional: false, - is_list: false, + is_list: true, }, + "|", ), ], is_list: false, @@ -5186,15 +5201,16 @@ is_list: false, }, ), - String( + JoinedStringArray( TypeInfo { name: "id", description: Some( - "File ids, separated by \\", + "File ids, separated by a pipe", ), is_optional: false, - is_list: false, + is_list: true, }, + "|", ), Object( Object { @@ -5398,15 +5414,16 @@ Parameters( TypeWithoutName { types: [ - String( + JoinedStringArray( TypeInfo { name: "hashes", description: Some( - "The hashes of the torrents you want to toggle sequential download for. hashes can contain multiple hashes separated by \\", + "The hashes of the torrents you want to toggle sequential download for. hashes can contain multiple hashes separated by a pipe, to toggle sequential download for multiple torrents, or set to all, to toggle sequential download for all torrents.", ), is_optional: false, - is_list: false, + is_list: true, }, + "|", ), ], is_list: false, @@ -5424,15 +5441,16 @@ Parameters( TypeWithoutName { types: [ - String( + JoinedStringArray( TypeInfo { name: "hashes", description: Some( - "The hashes of the torrents you want to toggle the first/last piece priority for. hashes can contain multiple hashes separated by \\", + "The hashes of the torrents you want to toggle the first/last piece priority for. hashes can contain multiple hashes separated by a pipe, to toggle the first/last piece priority for multiple torrents, or set to all, to toggle the first/last piece priority for all torrents.", ), is_optional: false, - is_list: false, + is_list: true, }, + "|", ), ], is_list: false, @@ -5914,15 +5932,16 @@ is_list: false, }, ), - String( + JoinedStringArray( TypeInfo { name: "plugins", description: Some( - "Plugins to use for searching (e.g. \"legittorrents\"). Supports multiple plugins separated by \\", + "Plugins to use for searching (e.g. \"legittorrents\"). Supports multiple plugins separated by a pipe. Also supports all and enabled", ), is_optional: false, - is_list: false, + is_list: true, }, + "|", ), String( TypeInfo { @@ -6361,15 +6380,16 @@ Parameters( TypeWithoutName { types: [ - String( + JoinedStringArray( TypeInfo { name: "sources", description: Some( - "Url or file path of the plugin to install (e.g. \"[https://raw.githubusercontent.com/qbittorrent/search-plugins/master/nova3/engines/legittorrents.py](https://raw.githubusercontent.com/qbittorrent/search-plugins/master/nova3/engines/legittorrents.py)\"). Supports multiple sources separated by \\", + "Url or file path of the plugin to install (e.g. \"[https://raw.githubusercontent.com/qbittorrent/search-plugins/master/nova3/engines/legittorrents.py](https://raw.githubusercontent.com/qbittorrent/search-plugins/master/nova3/engines/legittorrents.py)\"). Supports multiple sources separated by a pipe", ), is_optional: false, - is_list: false, + is_list: true, }, + "|", ), ], is_list: false, @@ -6387,15 +6407,16 @@ Parameters( TypeWithoutName { types: [ - String( + JoinedStringArray( TypeInfo { name: "names", description: Some( - "Name of the plugin to uninstall (e.g. \"legittorrents\"). Supports multiple names separated by \\", + "Name of the plugin to uninstall (e.g. \"legittorrents\"). Supports multiple names separated by a pipe", ), is_optional: false, - is_list: false, + is_list: true, }, + "|", ), ], is_list: false, @@ -6413,15 +6434,16 @@ Parameters( TypeWithoutName { types: [ - String( + JoinedStringArray( TypeInfo { name: "names", description: Some( - "Name of the plugin to enable/disable (e.g. \"legittorrents\"). Supports multiple names separated by \\", + "Name of the plugin to enable/disable (e.g. \"legittorrents\"). Supports multiple names separated by a pipe", ), is_optional: false, - is_list: false, + is_list: true, }, + "|", ), Bool( TypeInfo { diff --git a/qbittorrent-web-api-gen/src/generate/group.rs b/qbittorrent-web-api-gen/src/generate/group.rs index ba8bd1c..5694bcf 100644 --- a/qbittorrent-web-api-gen/src/generate/group.rs +++ b/qbittorrent-web-api-gen/src/generate/group.rs @@ -95,6 +95,7 @@ impl types::Type { quote! { std::collections::HashMap<#key_ident, #value_ident> } } }, + types::Type::JoinedStringArray(_, _) => quote! { Vec }, }; let owned_type = if self.is_optional() { @@ -184,8 +185,14 @@ impl types::Type { ) } - fn borrowed_type_ident(&self) -> Ident { - util::to_ident(&self.to_borrowed_type()) + fn borrowed_type_ident(&self) -> TokenStream { + let type_ident = util::to_ident(&self.to_borrowed_type()); + + if self.is_list() { + quote! { [&#type_ident] } + } else { + quote! { #type_ident } + } } pub fn to_parameter(&self) -> TokenStream { @@ -197,13 +204,7 @@ impl types::Type { pub fn generate_form_builder(&self, add_to: TokenStream) -> TokenStream { let name_str = self.name(); - let name_snake = self.name_snake(); - - let serialized = if self.is_object() { - quote! { serde_json::to_string(#name_snake).unwrap() } - } else { - quote! { #name_snake.to_string() } - }; + let serialized = self.serialized(); quote! { #add_to = #add_to.text(#name_str, #serialized); } } @@ -230,3 +231,21 @@ impl types::Type { } } } + +impl types::Type { + pub fn serialized(&self) -> TokenStream { + let name_snake = self.name_snake(); + + match self { + types::Type::Object(_) => { + quote! { serde_json::to_string(#name_snake).unwrap() } + } + types::Type::JoinedStringArray(_, sep) => { + quote! { #name_snake.join(#sep) } + } + _ => { + quote! { #name_snake.to_string() } + } + } + } +} diff --git a/qbittorrent-web-api-gen/src/types.rs b/qbittorrent-web-api-gen/src/types.rs index e283b85..23b6602 100644 --- a/qbittorrent-web-api-gen/src/types.rs +++ b/qbittorrent-web-api-gen/src/types.rs @@ -65,6 +65,8 @@ pub enum Type { Bool(TypeInfo), String(TypeInfo), StringArray(TypeInfo), + // the second arg is the separator + JoinedStringArray(TypeInfo, String), Object(Object), } @@ -75,7 +77,7 @@ impl Type { Type::Float(_) => "f32".into(), Type::Bool(_) => "bool".into(), Type::String(_) => "str".into(), - Type::StringArray(_) => "&[str]".into(), + Type::StringArray(_) | Type::JoinedStringArray(_, _) => "str".into(), Type::Object(t) => match &t.ref_type { RefType::String(s) => s.clone(), _ => todo!(), @@ -83,12 +85,14 @@ impl Type { } } - pub fn is_object(&self) -> bool { - matches!(self, Type::Object(_)) - } - pub fn should_borrow(&self) -> bool { - matches!(self, Type::String(_) | Type::Object(_)) + matches!( + self, + Type::String(_) + | Type::Object(_) + | Type::StringArray(_) + | Type::JoinedStringArray(_, _) + ) } pub fn is_optional(&self) -> bool { @@ -97,6 +101,7 @@ impl Type { pub fn is_list(&self) -> bool { self.get_type_info().is_list + || matches!(self, Type::StringArray(_) | Type::JoinedStringArray(_, _)) } pub fn get_type_info(&self) -> &TypeInfo { @@ -106,6 +111,7 @@ impl Type { Type::Bool(t) => t, Type::String(t) => t, Type::StringArray(t) => t, + Type::JoinedStringArray(t, _) => t, Type::Object(t) => &t.type_info, } } @@ -149,7 +155,9 @@ impl Type { "raw" => None, "bool" => Some(Type::Bool(create_type_info())), "integer" | "number" | "int" => Some(Type::Number(create_type_info())), - "string" => Some(Type::String(create_type_info())), + "string" => description + .to_string_list(type_name, is_optional) + .or_else(|| Some(Type::String(create_type_info()))), "array" => description .extract_type() .and_then(create_object_type) @@ -171,6 +179,25 @@ impl Type { } } +trait ToStringList { + fn to_string_list(&self, type_name: &str, optional: bool) -> Option; +} + +impl ToStringList for Option { + fn to_string_list(&self, type_name: &str, optional: bool) -> Option { + self.as_ref().and_then(|t| { + if t.contains("separated by a pipe") { + Some(Type::JoinedStringArray( + TypeInfo::new(type_name, optional, true, Some(t.clone())), + "|".into(), + )) + } else { + None + } + }) + } +} + trait ExtractType { fn extract_type(&self) -> Option; } diff --git a/qbittorrent-web-api-gen/tests/access_search.rs b/qbittorrent-web-api-gen/tests/access_search.rs index 504dbc3..231d578 100644 --- a/qbittorrent-web-api-gen/tests/access_search.rs +++ b/qbittorrent-web-api-gen/tests/access_search.rs @@ -11,10 +11,9 @@ struct Api {} async fn main() -> Result<()> { let api = Api::login(BASE_URL, USERNAME, PASSWORD).await?; - let _ = api.search().delete(1).send().await?; + let _ = api.search().delete(1).await?; let _ = api.search().plugins().await?; - let _ = api.search().plugins().await?; - let _ = api.search().install_plugin("https://raw.githubusercontent.com/qbittorrent/search-plugins/master/nova3/engines/legittorrents.py").send().await?; + let _ = api.search().install_plugin(&["https://raw.githubusercontent.com/qbittorrent/search-plugins/master/nova3/engines/legittorrents.py"]).await?; Ok(()) } diff --git a/qbittorrent-web-api-gen/tests/search_types.rs b/qbittorrent-web-api-gen/tests/search_types.rs index 4a21fbd..9601bb5 100644 --- a/qbittorrent-web-api-gen/tests/search_types.rs +++ b/qbittorrent-web-api-gen/tests/search_types.rs @@ -11,7 +11,7 @@ struct Api {} async fn main() -> Result<()> { let api = Api::login(BASE_URL, USERNAME, PASSWORD).await?; - let _ = api.search().install_plugin("https://raw.githubusercontent.com/qbittorrent/search-plugins/master/nova3/engines/legittorrents.py").await?; + let _ = api.search().install_plugin(&["https://raw.githubusercontent.com/qbittorrent/search-plugins/master/nova3/engines/legittorrents.py"]).await?; // just check that the deserialization works let _ = api.search().plugins().await?; diff --git a/qbittorrent-web-api-gen/tests/tests.rs b/qbittorrent-web-api-gen/tests/tests.rs index 873c7ba..c7dba58 100644 --- a/qbittorrent-web-api-gen/tests/tests.rs +++ b/qbittorrent-web-api-gen/tests/tests.rs @@ -21,4 +21,5 @@ fn tests() { t.pass("tests/another_struct_name.rs"); t.pass("tests/access_impl_types.rs"); t.pass("tests/search_types.rs"); + t.pass("tests/access_search.rs"); } diff --git a/qbittorrent-web-api-gen/token_tree.txt b/qbittorrent-web-api-gen/token_tree.txt index df2e2a6..79d470c 100644 --- a/qbittorrent-web-api-gen/token_tree.txt +++ b/qbittorrent-web-api-gen/token_tree.txt @@ -5989,12 +5989,11 @@ TokenTree { split: "----------------------------------|---------|------------", rows: [ TableRow { - raw: "`peers` | string | The peer to ban, or multiple peers separated by a pipe `\\|`. Each peer is a colon-separated `host:port`", + raw: "`peers` | string | The peer to ban, or multiple peers separated by a pipe. Each peer is a colon-separated `host:port`", columns: [ "peers", "string", - "The peer to ban, or multiple peers separated by a pipe \\", - ". Each peer is a colon-separated host:port", + "The peer to ban, or multiple peers separated by a pipe. Each peer is a colon-separated host:port", ], }, ], @@ -6111,11 +6110,11 @@ TokenTree { ], }, TableRow { - raw: "`sort` _optional_ | string | Sort torrents by given key. They can be sorted using any field of the response's JSON array (which are documented below) as the sort key.", + raw: "`sort` _optional_ | string | Sort torrents by given key. They can be sorted using any field of the response (which are documented below) as the sort key.", columns: [ "sort _optional_", "string", - "Sort torrents by given key. They can be sorted using any field of the response's JSON array (which are documented below) as the sort key.", + "Sort torrents by given key. They can be sorted using any field of the response (which are documented below) as the sort key.", ], }, TableRow { @@ -6143,12 +6142,11 @@ TokenTree { ], }, TableRow { - raw: "`hashes` _optional_ | string | Filter by hashes. Can contain multiple hashes separated by `\\|`", + raw: "`hashes` _optional_ | string | Filter by hashes. Can contain multiple hashes separated by a pipe", columns: [ "hashes _optional_", "string", - "Filter by hashes. Can contain multiple hashes separated by \\", - "", + "Filter by hashes. Can contain multiple hashes separated by a pipe", ], }, ], @@ -7846,12 +7844,11 @@ TokenTree { ], }, TableRow { - raw: "`indexes` _optional_ | string | The indexes of the files you want to retrieve. `indexes` can contain multiple values separated by `\\|`.", + raw: "`indexes` _optional_ | string | The indexes of the files you want to retrieve. `indexes` can contain multiple values separated by a pipe.", columns: [ "indexes _optional_", "string", - "The indexes of the files you want to retrieve. indexes can contain multiple values separated by \\", - ".", + "The indexes of the files you want to retrieve. indexes can contain multiple values separated by a pipe.", ], }, ], @@ -8408,12 +8405,11 @@ TokenTree { split: "------------|----------|------------", rows: [ TableRow { - raw: "`hashes` | string | The hashes of the torrents you want to pause. `hashes` can contain multiple hashes separated by `\\|`, to pause multiple torrents, or set to `all`, to pause all torrents.", + raw: "`hashes` | string | The hashes of the torrents you want to pause. `hashes` can contain multiple hashes separated by a pipe, to pause multiple torrents, or set to `all`, to pause all torrents.", columns: [ "hashes", "string", - "The hashes of the torrents you want to pause. hashes can contain multiple hashes separated by \\", - ", to pause multiple torrents, or set to all, to pause all torrents.", + "The hashes of the torrents you want to pause. hashes can contain multiple hashes separated by a pipe, to pause multiple torrents, or set to all, to pause all torrents.", ], }, ], @@ -8512,12 +8508,11 @@ TokenTree { split: "------------|----------|------------", rows: [ TableRow { - raw: "`hashes` | string | The hashes of the torrents you want to resume. `hashes` can contain multiple hashes separated by `\\|`, to resume multiple torrents, or set to `all`, to resume all torrents.", + raw: "`hashes` | string | The hashes of the torrents you want to resume. `hashes` can contain multiple hashes separated by a pipe, to resume multiple torrents, or set to `all`, to resume all torrents.", columns: [ "hashes", "string", - "The hashes of the torrents you want to resume. hashes can contain multiple hashes separated by \\", - ", to resume multiple torrents, or set to all, to resume all torrents.", + "The hashes of the torrents you want to resume. hashes can contain multiple hashes separated by a pipe, to resume multiple torrents, or set to all, to resume all torrents.", ], }, ], @@ -8616,12 +8611,11 @@ TokenTree { split: "------------|----------|------------", rows: [ TableRow { - raw: "`hashes` | string | The hashes of the torrents you want to delete. `hashes` can contain multiple hashes separated by `\\|`, to delete multiple torrents, or set to `all`, to delete all torrents.", + raw: "`hashes` | string | The hashes of the torrents you want to delete. `hashes` can contain multiple hashes separated by a pipe, to delete multiple torrents, or set to `all`, to delete all torrents.", columns: [ "hashes", "string", - "The hashes of the torrents you want to delete. hashes can contain multiple hashes separated by \\", - ", to delete multiple torrents, or set to all, to delete all torrents.", + "The hashes of the torrents you want to delete. hashes can contain multiple hashes separated by a pipe, to delete multiple torrents, or set to all, to delete all torrents.", ], }, TableRow { @@ -8728,12 +8722,11 @@ TokenTree { split: "------------|----------|------------", rows: [ TableRow { - raw: "`hashes` | string | The hashes of the torrents you want to recheck. `hashes` can contain multiple hashes separated by `\\|`, to recheck multiple torrents, or set to `all`, to recheck all torrents.", + raw: "`hashes` | string | The hashes of the torrents you want to recheck. `hashes` can contain multiple hashes separated by a pipe, to recheck multiple torrents, or set to `all`, to recheck all torrents.", columns: [ "hashes", "string", - "The hashes of the torrents you want to recheck. hashes can contain multiple hashes separated by \\", - ", to recheck multiple torrents, or set to all, to recheck all torrents.", + "The hashes of the torrents you want to recheck. hashes can contain multiple hashes separated by a pipe, to recheck multiple torrents, or set to all, to recheck all torrents.", ], }, ], @@ -8832,12 +8825,11 @@ TokenTree { split: "------------|----------|------------", rows: [ TableRow { - raw: "`hashes` | string | The hashes of the torrents you want to reannounce. `hashes` can contain multiple hashes separated by `\\|`, to reannounce multiple torrents, or set to `all`, to reannounce all torrents.", + raw: "`hashes` | string | The hashes of the torrents you want to reannounce. `hashes` can contain multiple hashes separated by a pipe, to reannounce multiple torrents, or set to `all`, to reannounce all torrents.", columns: [ "hashes", "string", - "The hashes of the torrents you want to reannounce. hashes can contain multiple hashes separated by \\", - ", to reannounce multiple torrents, or set to all, to reannounce all torrents.", + "The hashes of the torrents you want to reannounce. hashes can contain multiple hashes separated by a pipe, to reannounce multiple torrents, or set to all, to reannounce all torrents.", ], }, ], @@ -9584,12 +9576,11 @@ TokenTree { ], }, TableRow { - raw: "`urls` | string | URLs to remove, separated by `\\|`", + raw: "`urls` | string | URLs to remove, separated by a pipe", columns: [ "urls", "string", - "URLs to remove, separated by \\", - "", + "URLs to remove, separated by a pipe", ], }, ], @@ -9678,21 +9669,19 @@ TokenTree { split: "----------------------------------|---------|------------", rows: [ TableRow { - raw: "`hashes` | string | The hash of the torrent, or multiple hashes separated by a pipe `\\|`", + raw: "`hashes` | string | The hash of the torrent, or multiple hashes separated by a pipe", columns: [ "hashes", "string", - "The hash of the torrent, or multiple hashes separated by a pipe \\", - "", + "The hash of the torrent, or multiple hashes separated by a pipe", ], }, TableRow { - raw: "`peers` | string | The peer to add, or multiple peers separated by a pipe `\\|`. Each peer is a colon-separated `host:port`", + raw: "`peers` | string | The peer to add, or multiple peers separated by a pipe. Each peer is a colon-separated `host:port`", columns: [ "peers", "string", - "The peer to add, or multiple peers separated by a pipe \\", - ". Each peer is a colon-separated host:port", + "The peer to add, or multiple peers separated by a pipe. Each peer is a colon-separated host:port", ], }, ], @@ -9780,12 +9769,11 @@ TokenTree { split: "------------|----------|------------", rows: [ TableRow { - raw: "`hashes` | string | The hashes of the torrents you want to increase the priority of. `hashes` can contain multiple hashes separated by `\\|`, to increase the priority of multiple torrents, or set to `all`, to increase the priority of all torrents.", + raw: "`hashes` | string | The hashes of the torrents you want to increase the priority of. `hashes` can contain multiple hashes separated by a pipe, to increase the priority of multiple torrents, or set to `all`, to increase the priority of all torrents.", columns: [ "hashes", "string", - "The hashes of the torrents you want to increase the priority of. hashes can contain multiple hashes separated by \\", - ", to increase the priority of multiple torrents, or set to all, to increase the priority of all torrents.", + "The hashes of the torrents you want to increase the priority of. hashes can contain multiple hashes separated by a pipe, to increase the priority of multiple torrents, or set to all, to increase the priority of all torrents.", ], }, ], @@ -9891,12 +9879,11 @@ TokenTree { split: "------------|----------|------------", rows: [ TableRow { - raw: "`hashes` | string | The hashes of the torrents you want to decrease the priority of. `hashes` can contain multiple hashes separated by `\\|`, to decrease the priority of multiple torrents, or set to `all`, to decrease the priority of all torrents.", + raw: "`hashes` | string | The hashes of the torrents you want to decrease the priority of. `hashes` can contain multiple hashes separated by a pipe, to decrease the priority of multiple torrents, or set to `all`, to decrease the priority of all torrents.", columns: [ "hashes", "string", - "The hashes of the torrents you want to decrease the priority of. hashes can contain multiple hashes separated by \\", - ", to decrease the priority of multiple torrents, or set to all, to decrease the priority of all torrents.", + "The hashes of the torrents you want to decrease the priority of. hashes can contain multiple hashes separated by a pipe, to decrease the priority of multiple torrents, or set to all, to decrease the priority of all torrents.", ], }, ], @@ -10002,12 +9989,11 @@ TokenTree { split: "------------|----------|------------", rows: [ TableRow { - raw: "`hashes` | string | The hashes of the torrents you want to set to the maximum priority. `hashes` can contain multiple hashes separated by `\\|`, to set multiple torrents to the maximum priority, or set to `all`, to set all torrents to the maximum priority.", + raw: "`hashes` | string | The hashes of the torrents you want to set to the maximum priority. `hashes` can contain multiple hashes separated by a pipe, to set multiple torrents to the maximum priority, or set to `all`, to set all torrents to the maximum priority.", columns: [ "hashes", "string", - "The hashes of the torrents you want to set to the maximum priority. hashes can contain multiple hashes separated by \\", - ", to set multiple torrents to the maximum priority, or set to all, to set all torrents to the maximum priority.", + "The hashes of the torrents you want to set to the maximum priority. hashes can contain multiple hashes separated by a pipe, to set multiple torrents to the maximum priority, or set to all, to set all torrents to the maximum priority.", ], }, ], @@ -10113,12 +10099,11 @@ TokenTree { split: "------------|----------|------------", rows: [ TableRow { - raw: "`hashes` | string | The hashes of the torrents you want to set to the minimum priority. `hashes` can contain multiple hashes separated by `\\|`, to set multiple torrents to the minimum priority, or set to `all`, to set all torrents to the minimum priority.", + raw: "`hashes` | string | The hashes of the torrents you want to set to the minimum priority. `hashes` can contain multiple hashes separated by a pipe, to set multiple torrents to the minimum priority, or set to `all`, to set all torrents to the minimum priority.", columns: [ "hashes", "string", - "The hashes of the torrents you want to set to the minimum priority. hashes can contain multiple hashes separated by \\", - ", to set multiple torrents to the minimum priority, or set to all, to set all torrents to the minimum priority.", + "The hashes of the torrents you want to set to the minimum priority. hashes can contain multiple hashes separated by a pipe, to set multiple torrents to the minimum priority, or set to all, to set all torrents to the minimum priority.", ], }, ], @@ -10226,12 +10211,11 @@ TokenTree { ], }, TableRow { - raw: "`id` | string | File ids, separated by `\\|`", + raw: "`id` | string | File ids, separated by a pipe", columns: [ "id", "string", - "File ids, separated by \\", - "", + "File ids, separated by a pipe", ], }, TableRow { @@ -12150,12 +12134,11 @@ TokenTree { split: "------------|----------|------------", rows: [ TableRow { - raw: "`hashes` | string | The hashes of the torrents you want to toggle sequential download for. `hashes` can contain multiple hashes separated by `\\|`, to toggle sequential download for multiple torrents, or set to `all`, to toggle sequential download for all torrents.", + raw: "`hashes` | string | The hashes of the torrents you want to toggle sequential download for. `hashes` can contain multiple hashes separated by a pipe, to toggle sequential download for multiple torrents, or set to `all`, to toggle sequential download for all torrents.", columns: [ "hashes", "string", - "The hashes of the torrents you want to toggle sequential download for. hashes can contain multiple hashes separated by \\", - ", to toggle sequential download for multiple torrents, or set to all, to toggle sequential download for all torrents.", + "The hashes of the torrents you want to toggle sequential download for. hashes can contain multiple hashes separated by a pipe, to toggle sequential download for multiple torrents, or set to all, to toggle sequential download for all torrents.", ], }, ], @@ -12254,12 +12237,11 @@ TokenTree { split: "------------|----------|------------", rows: [ TableRow { - raw: "`hashes` | string | The hashes of the torrents you want to toggle the first/last piece priority for. `hashes` can contain multiple hashes separated by `\\|`, to toggle the first/last piece priority for multiple torrents, or set to `all`, to toggle the first/last piece priority for all torrents.", + raw: "`hashes` | string | The hashes of the torrents you want to toggle the first/last piece priority for. `hashes` can contain multiple hashes separated by a pipe, to toggle the first/last piece priority for multiple torrents, or set to `all`, to toggle the first/last piece priority for all torrents.", columns: [ "hashes", "string", - "The hashes of the torrents you want to toggle the first/last piece priority for. hashes can contain multiple hashes separated by \\", - ", to toggle the first/last piece priority for multiple torrents, or set to all, to toggle the first/last piece priority for all torrents.", + "The hashes of the torrents you want to toggle the first/last piece priority for. hashes can contain multiple hashes separated by a pipe, to toggle the first/last piece priority for multiple torrents, or set to all, to toggle the first/last piece priority for all torrents.", ], }, ], @@ -14129,12 +14111,11 @@ TokenTree { ], }, TableRow { - raw: "`plugins` | string | Plugins to use for searching (e.g. \"legittorrents\"). Supports multiple plugins separated by `\\|`. Also supports `all` and `enabled`", + raw: "`plugins` | string | Plugins to use for searching (e.g. \"legittorrents\"). Supports multiple plugins separated by a pipe. Also supports `all` and `enabled`", columns: [ "plugins", "string", - "Plugins to use for searching (e.g. \"legittorrents\"). Supports multiple plugins separated by \\", - ". Also supports all and enabled", + "Plugins to use for searching (e.g. \"legittorrents\"). Supports multiple plugins separated by a pipe. Also supports all and enabled", ], }, TableRow { @@ -15219,12 +15200,11 @@ TokenTree { split: "----------------------------------|---------|------------", rows: [ TableRow { - raw: "`sources` | string | Url or file path of the plugin to install (e.g. \"[https://raw.githubusercontent.com/qbittorrent/search-plugins/master/nova3/engines/legittorrents.py](https://raw.githubusercontent.com/qbittorrent/search-plugins/master/nova3/engines/legittorrents.py)\"). Supports multiple sources separated by `\\|`", + raw: "`sources` | string | Url or file path of the plugin to install (e.g. \"[https://raw.githubusercontent.com/qbittorrent/search-plugins/master/nova3/engines/legittorrents.py](https://raw.githubusercontent.com/qbittorrent/search-plugins/master/nova3/engines/legittorrents.py)\"). Supports multiple sources separated by a pipe", columns: [ "sources", "string", - "Url or file path of the plugin to install (e.g. \"[https://raw.githubusercontent.com/qbittorrent/search-plugins/master/nova3/engines/legittorrents.py](https://raw.githubusercontent.com/qbittorrent/search-plugins/master/nova3/engines/legittorrents.py)\"). Supports multiple sources separated by \\", - "", + "Url or file path of the plugin to install (e.g. \"[https://raw.githubusercontent.com/qbittorrent/search-plugins/master/nova3/engines/legittorrents.py](https://raw.githubusercontent.com/qbittorrent/search-plugins/master/nova3/engines/legittorrents.py)\"). Supports multiple sources separated by a pipe", ], }, ], @@ -15299,12 +15279,11 @@ TokenTree { split: "----------------------------------|---------|------------", rows: [ TableRow { - raw: "`names` | string | Name of the plugin to uninstall (e.g. \"legittorrents\"). Supports multiple names separated by `\\|`", + raw: "`names` | string | Name of the plugin to uninstall (e.g. \"legittorrents\"). Supports multiple names separated by a pipe", columns: [ "names", "string", - "Name of the plugin to uninstall (e.g. \"legittorrents\"). Supports multiple names separated by \\", - "", + "Name of the plugin to uninstall (e.g. \"legittorrents\"). Supports multiple names separated by a pipe", ], }, ], @@ -15379,12 +15358,11 @@ TokenTree { split: "----------------------------------|---------|------------", rows: [ TableRow { - raw: "`names` | string | Name of the plugin to enable/disable (e.g. \"legittorrents\"). Supports multiple names separated by `\\|`", + raw: "`names` | string | Name of the plugin to enable/disable (e.g. \"legittorrents\"). Supports multiple names separated by a pipe", columns: [ "names", "string", - "Name of the plugin to enable/disable (e.g. \"legittorrents\"). Supports multiple names separated by \\", - "", + "Name of the plugin to enable/disable (e.g. \"legittorrents\"). Supports multiple names separated by a pipe", ], }, TableRow {