compojure-api / schema / swagger中的非必需参数?

时间:2015-08-01 22:39:39

标签: clojure swagger plumatic-schema compojure-api

当我有这样的API定义时:

(POST* "/register" []
    :body-params [username :- String,
                  password :- String,
                  name :- String]
    (ok)))

什么是使名称可选的合适方式?是吗:

(POST* "/register" []
    :body-params [username :- String,
                  password :- String,
                  {name :- String nil}]
    (ok)))

1 个答案:

答案 0 :(得分:8)

如你所知它使用letk管道符号并且我记得语法是正确的但是默认值应该与预期类型一致所以我认为它应该是""而不是nil(string? nil) = false相比(POST* "/register" [] :body-params [username :- String, password :- String, {name :- String ""}] (ok))) extension String { func stringByURLEncoding() -> String? { let characters = NSCharacterSet.URLQueryAllowedCharacterSet().mutableCopy() as! NSMutableCharacterSet characters.removeCharactersInString("&") guard let encodedString = self.stringByAddingPercentEncodingWithAllowedCharacters(characters) else { return nil } return encodedString } }

 string query = string.Format("SELECT * from {0}", sym);  
 cmd.CommandText = query; 
 MySqlDataReader myresults = cmd.ExecuteReader();