From f95817bf8eb527ae79a0b567b85ec161c84ceaf3 Mon Sep 17 00:00:00 2001 From: Bryan Maass <bryan.maass@gmail.com> Date: Tue, 7 Feb 2023 10:14:49 -0700 Subject: [PATCH] mu/defn fix: no return schema docstring generation (#28121) * handle nil return schemas for docstring gen * adds more mu/defn docstring generation tests --- src/metabase/util/malli.clj | 2 +- test/metabase/util/malli_test.clj | 49 +++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/metabase/util/malli.clj b/src/metabase/util/malli.clj index d07648e627e..30b2679599a 100644 --- a/src/metabase/util/malli.clj +++ b/src/metabase/util/malli.clj @@ -70,7 +70,7 @@ explain-fn-fail! (str "Inputs: " (if single (pr-str (first (mapv :raw-arglist parglists))) (str "(" (str/join "\n " (map (comp pr-str :raw-arglist) parglists)) ")")) - "\n Return: " (str/replace (u/pprint-to-str (:schema return)) + "\n Return: " (str/replace (u/pprint-to-str (:schema return :any)) "\n" (str "\n ")) (when (not-empty doc) (str "\n\n " doc)))) diff --git a/test/metabase/util/malli_test.clj b/test/metabase/util/malli_test.clj index 908f1990cd5..5312f87a952 100644 --- a/test/metabase/util/malli_test.clj +++ b/test/metabase/util/malli_test.clj @@ -35,6 +35,55 @@ (is (str/ends-with? (:doc (meta #'boo)) "something very important to remember goes here")) (ns-unmap *ns* 'boo)) + (testing "no schemas given should work" + (mu/defn qux []) + (is (= "Inputs: []\n Return: :any" + (:doc (meta #'qux)))) + (ns-unmap *ns* 'qux) + (mu/defn qux "Original docstring." []) + (is (= (str/join "\n" + [ "Inputs: []" + " Return: :any" + " " + "" + " Original docstring."]) + (:doc (meta #'qux)))) + (ns-unmap *ns* 'qux)) + + (testing "no return schemas given should work" + (mu/defn qux [x :- :int]) + (is (= "Inputs: [x :- :int]\n Return: :any" + (:doc (meta #'qux)))) + (ns-unmap *ns* 'qux) + (mu/defn qux "Original docstring." [x :- :int]) + (is (= (str/join "\n" + [ "Inputs: [x :- :int]" + " Return: :any" + " " + "" + " Original docstring."]) + (:doc (meta #'qux)))) + (ns-unmap *ns* 'qux)) + + (testing "no input schemas given should work" + (mu/defn qux :- :int []) + (is (= "Inputs: []\n Return: :int" + (:doc (meta #'qux)))) + (ns-unmap *ns* 'qux) + (mu/defn qux :- :int + "Original docstring." + [x :- :int]) + (is (= (str/join "\n" + [ "Inputs: [x :- :int]" + " Return: :int" + " " + "" + " Original docstring."]) + (:doc (meta #'qux)))) + (ns-unmap *ns* 'qux)) + + + (testing "multi-arity, and varargs doc strings should work" (mu/defn ^:private foo :- [:multi {:dispatch :type} [:sized [:map [:type [:= :sized]] -- GitLab