diff --git a/qbittorrent-web-api-gen/src/generate/mod.rs b/qbittorrent-web-api-gen/src/generate/mod.rs index 2a29a99..5f123a3 100644 --- a/qbittorrent-web-api-gen/src/generate/mod.rs +++ b/qbittorrent-web-api-gen/src/generate/mod.rs @@ -1,4 +1,5 @@ mod skeleton; +mod util; use std::{collections::HashMap, vec::Vec}; @@ -7,7 +8,7 @@ use proc_macro2::TokenStream; use quote::{format_ident, quote}; use regex::Regex; -use crate::{md_parser, parser, types, util}; +use crate::{md_parser, parser, types}; use self::skeleton::{auth_ident, generate_skeleton}; diff --git a/qbittorrent-web-api-gen/src/generate/skeleton.rs b/qbittorrent-web-api-gen/src/generate/skeleton.rs index e08050e..e2118a7 100644 --- a/qbittorrent-web-api-gen/src/generate/skeleton.rs +++ b/qbittorrent-web-api-gen/src/generate/skeleton.rs @@ -1,6 +1,6 @@ use quote::quote; -use crate::util; +use super::util; pub const AUTH_IDENT: &str = "Authenticated"; diff --git a/qbittorrent-web-api-gen/src/util.rs b/qbittorrent-web-api-gen/src/generate/util.rs similarity index 100% rename from qbittorrent-web-api-gen/src/util.rs rename to qbittorrent-web-api-gen/src/generate/util.rs diff --git a/qbittorrent-web-api-gen/src/lib.rs b/qbittorrent-web-api-gen/src/lib.rs index 0d0814c..5953ad2 100644 --- a/qbittorrent-web-api-gen/src/lib.rs +++ b/qbittorrent-web-api-gen/src/lib.rs @@ -2,7 +2,6 @@ mod generate; mod md_parser; mod parser; mod types; -mod util; use proc_macro::TokenStream; use syn::parse_macro_input; diff --git a/qbittorrent-web-api-gen/src/parser/group/method/mod.rs b/qbittorrent-web-api-gen/src/parser/group/method/mod.rs index 22e3584..83aaf67 100644 --- a/qbittorrent-web-api-gen/src/parser/group/method/mod.rs +++ b/qbittorrent-web-api-gen/src/parser/group/method/mod.rs @@ -1,15 +1,13 @@ mod description; +mod parameters; mod return_type; mod url; -use crate::{ - md_parser, - parser::{parameters::parse_parameters, util}, - types, -}; +use crate::{md_parser, parser::util, types}; use self::{ description::parse_method_description, + parameters::parse_parameters, return_type::{parse_return_type, ReturnType}, url::get_method_url, }; diff --git a/qbittorrent-web-api-gen/src/parser/parameters.rs b/qbittorrent-web-api-gen/src/parser/group/method/parameters.rs similarity index 100% rename from qbittorrent-web-api-gen/src/parser/parameters.rs rename to qbittorrent-web-api-gen/src/parser/group/method/parameters.rs diff --git a/qbittorrent-web-api-gen/src/parser/group/method/return_type.rs b/qbittorrent-web-api-gen/src/parser/group/method/return_type.rs index 293f1fa..6ff8342 100644 --- a/qbittorrent-web-api-gen/src/parser/group/method/return_type.rs +++ b/qbittorrent-web-api-gen/src/parser/group/method/return_type.rs @@ -1,6 +1,8 @@ +use std::collections::HashMap; + use crate::{ - md_parser::MdContent, - parser::{object_types::parse_object_types, types, ReturnTypeParameter}, + md_parser::{self, MdContent}, + parser::{types, ReturnTypeParameter}, }; #[derive(Debug)] @@ -56,3 +58,43 @@ pub fn parse_return_type(content: &[MdContent]) -> Option { is_list, }) } + +pub fn parse_object_types( + content: &[md_parser::MdContent], +) -> HashMap { + let mut output = HashMap::new(); + let mut content_it = content.iter(); + + while let Some(entry) = content_it.next() { + if let md_parser::MdContent::Text(content) = entry { + const POSSIBLE_VALUES_OF: &str = "Possible values of "; + if content.contains(POSSIBLE_VALUES_OF) { + // is empty + content_it.next(); + if let Some(md_parser::MdContent::Table(table)) = content_it.next() { + let enum_types = to_type_descriptions(table); + + let name = content + .trim_start_matches(POSSIBLE_VALUES_OF) + .replace('`', "") + .replace(':', ""); + + output.insert(name, types::TypeDescription { values: enum_types }); + } + } + } + } + + output +} + +fn to_type_descriptions(table: &md_parser::Table) -> Vec { + table + .rows + .iter() + .map(|row| types::TypeDescriptions { + value: row.columns[0].to_string(), + description: row.columns[1].to_string(), + }) + .collect() +} diff --git a/qbittorrent-web-api-gen/src/parser/mod.rs b/qbittorrent-web-api-gen/src/parser/mod.rs index a386430..35f7a2e 100644 --- a/qbittorrent-web-api-gen/src/parser/mod.rs +++ b/qbittorrent-web-api-gen/src/parser/mod.rs @@ -3,8 +3,6 @@ use crate::{md_parser, types}; use self::group::parse_api_group; mod group; -mod object_types; -mod parameters; mod util; #[derive(Debug)] diff --git a/qbittorrent-web-api-gen/src/parser/object_types.rs b/qbittorrent-web-api-gen/src/parser/object_types.rs deleted file mode 100644 index 1dd6d72..0000000 --- a/qbittorrent-web-api-gen/src/parser/object_types.rs +++ /dev/null @@ -1,43 +0,0 @@ -use std::collections::HashMap; - -use crate::{md_parser, parser::types}; - -pub fn parse_object_types( - content: &[md_parser::MdContent], -) -> HashMap { - let mut output = HashMap::new(); - let mut content_it = content.iter(); - - while let Some(entry) = content_it.next() { - if let md_parser::MdContent::Text(content) = entry { - const POSSIBLE_VALUES_OF: &str = "Possible values of "; - if content.contains(POSSIBLE_VALUES_OF) { - // is empty - content_it.next(); - if let Some(md_parser::MdContent::Table(table)) = content_it.next() { - let enum_types = to_type_descriptions(table); - - let name = content - .trim_start_matches(POSSIBLE_VALUES_OF) - .replace('`', "") - .replace(':', ""); - - output.insert(name, types::TypeDescription { values: enum_types }); - } - } - } - } - - output -} - -fn to_type_descriptions(table: &md_parser::Table) -> Vec { - table - .rows - .iter() - .map(|row| types::TypeDescriptions { - value: row.columns[0].to_string(), - description: row.columns[1].to_string(), - }) - .collect() -}