+use failure::*;
use std::collections::HashMap;
+use url::form_urlencoded;
+use serde_json::{json, Value};
pub type PropertyMap = HashMap<&'static str, Jss>;
pub description: &'static str,
pub optional: Option<bool>,
pub additional_properties: Option<bool>,
- pub properties: Box<HashMap<&'static str, Jss>>,
+ pub properties: HashMap<&'static str, Jss>,
}
#[derive(Debug)]
$(
map.insert(stringify!($name), $e);
)*
- Box::new(map)
+ map
}
};
}
+pub fn parse_parameter_strings(data: &Vec<(String, String)>, schema: &Jss) -> Result<Value, Error> {
+
+ println!("QUERY Strings {:?}", data);
+
+ Ok(json!(null))
+}
+
+pub fn parse_query(query: &str, schema: &Jss) -> Result<Value, Error> {
+
+ let raw_param: Vec<(String, String)> =
+ form_urlencoded::parse(query.as_bytes()).into_owned().collect();
+
+ parse_parameter_strings(&raw_param, schema)
+}
#[test]
fn test_shema1() {
extern crate apitest;
-//use failure::*;
+use failure::*;
use std::collections::HashMap;
use lazy_static::lazy_static;
//use apitest::json_schema::*;
use apitest::api_info::*;
+use apitest::json_schema::*;
//use serde_derive::{Serialize, Deserialize};
use serde_json::{json, Value};
}}
}
-fn parse_query(query: &str) -> Value {
-
- println!("PARSE QUERY {}", query);
-
- // fixme: what about repeated parameters (arrays?)
- let mut raw_param = HashMap::new();
- for (k, v) in form_urlencoded::parse(query.as_bytes()) {
- println!("QUERY PARAM {} value {}", k, v);
- raw_param.insert(k, v);
- }
- println!("QUERY HASH {:?}", raw_param);
-
- return json!(null);
-}
fn handle_request(req: Request<Body>) -> Response<Body> {
println!("FOUND INFO");
let api_method_opt = match method {
&Method::GET => &info.get,
- // &Method::PUT => info.put,
- // &Method::POST => info.post,
- // &Method::DELETE => info.delete,
+ &Method::PUT => &info.put,
+ &Method::POST => &info.post,
+ &Method::DELETE => &info.delete,
_ => &None,
};
let api_method = match api_method_opt {
// extract param
let param = match query {
- Some(data) => parse_query(data),
+ Some(data) => {
+ match parse_query(data, &api_method.parameters) {
+ Ok(query) => query,
+ Err(err) => http_error!(NOT_FOUND, format!("Unable to parse query parameters '{}' - {}", data, err)),
+ }
+ }
None => json!({}),
};