Skip to content
Snippets Groups Projects
Unverified Commit e9a744b7 authored by Bryan Maass's avatar Bryan Maass Committed by GitHub
Browse files

fix malli io link for nils (#27639)

* handle nil directly <-> u/pprint-to-str ignores it

* quick refactor

* pprint-to-str handles `nil`, by returning "nil"

* trim schema and value in malli.io url params
parent 43aa7cd4
Branches
Tags
No related merge requests found
......@@ -260,10 +260,9 @@
(pprint-to-str 'green some-obj)"
(^String [x]
(when x
(with-open [w (java.io.StringWriter.)]
(pprint x w)
(str w))))
(with-open [w (java.io.StringWriter.)]
(pprint x w)
(str w)))
(^String [color-symb x]
(colorize color-symb (pprint-to-str x))))
......
......@@ -2,6 +2,7 @@
(:refer-clojure :exclude [defn])
(:require
[clojure.core :as core]
[clojure.string :as str]
[malli.core :as mc]
[malli.destructure]
[malli.error :as me]
......@@ -14,15 +15,18 @@
(core/defn- ->malli-io-link
([schema]
(->malli-io-link schema (try (mg/generate schema {:seed 1 :size 1})
;; not all schemas can generate values
(catch Exception _ ::none))))
(->malli-io-link schema (try
;; try to make a sample value
(mg/generate schema {:seed 1 :size 1})
;; not all schemas can generate values
(catch Exception _ ::none))))
([schema value]
(let [url-schema (codec/url-encode (u/pprint-to-str (mc/form schema)))
url-value (if (= ::none value)
""
(codec/url-encode (u/pprint-to-str value)))]
(str "https://malli.io?schema=" url-schema "&value=" url-value))))
(str "https://malli.io?schema="
(codec/url-encode (str/trim (u/pprint-to-str (mc/form schema))))
"&value="
(if (= ::none value)
""
(codec/url-encode (str/trim (u/pprint-to-str value)))))))
(core/defn- explain-fn-fail!
"Used as reporting function to minst/instrument!"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment