mirror of
https://github.com/penpot/penpot.git
synced 2025-05-29 20:26:10 +02:00
✨ Add minor js-like type schema formatting improvements
This commit is contained in:
parent
c87fa4f723
commit
004a9f17d3
1 changed files with 16 additions and 15 deletions
|
@ -7,6 +7,7 @@
|
||||||
(ns app.common.schema.desc-js-like
|
(ns app.common.schema.desc-js-like
|
||||||
(:require
|
(:require
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
|
[app.common.schema :as-alias sm]
|
||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str]
|
||||||
[malli.core :as m]
|
[malli.core :as m]
|
||||||
[malli.util :as mu]))
|
[malli.util :as mu]))
|
||||||
|
@ -90,7 +91,7 @@
|
||||||
(defmethod visit :int [_ schema _ _] (str "integer" (-titled schema) (-min-max-suffix-number schema)))
|
(defmethod visit :int [_ schema _ _] (str "integer" (-titled schema) (-min-max-suffix-number schema)))
|
||||||
(defmethod visit :double [_ schema _ _] (str "double" (-titled schema) (-min-max-suffix-number schema)))
|
(defmethod visit :double [_ schema _ _] (str "double" (-titled schema) (-min-max-suffix-number schema)))
|
||||||
(defmethod visit :select-keys [_ schema _ options] (describe* (m/deref schema) options))
|
(defmethod visit :select-keys [_ schema _ options] (describe* (m/deref schema) options))
|
||||||
(defmethod visit :and [_ s children _] (str (str/join ", and " children) (-titled s)))
|
(defmethod visit :and [_ s children _] (str (str/join " && " children) (-titled s)))
|
||||||
(defmethod visit :enum [_ s children _options] (str "enum" (-titled s) " of " (str/join ", " children)))
|
(defmethod visit :enum [_ s children _options] (str "enum" (-titled s) " of " (str/join ", " children)))
|
||||||
(defmethod visit :maybe [_ _ children _] (str (first children) " nullable"))
|
(defmethod visit :maybe [_ _ children _] (str (first children) " nullable"))
|
||||||
(defmethod visit :tuple [_ _ children _] (str "(" (str/join ", " children) ")"))
|
(defmethod visit :tuple [_ _ children _] (str "(" (str/join ", " children) ")"))
|
||||||
|
@ -106,7 +107,8 @@
|
||||||
(defmethod visit :qualified-symbol [_ _ _ _] "qualified symbol")
|
(defmethod visit :qualified-symbol [_ _ _ _] "qualified symbol")
|
||||||
(defmethod visit :uuid [_ _ _ _] "uuid")
|
(defmethod visit :uuid [_ _ _ _] "uuid")
|
||||||
(defmethod visit :boolean [_ _ _ _] "boolean")
|
(defmethod visit :boolean [_ _ _ _] "boolean")
|
||||||
(defmethod visit :keyword [_ _ _ _] "keyword")
|
(defmethod visit :keyword [_ _ _ _] "string")
|
||||||
|
(defmethod visit :fn [_ _ _ _] "FN")
|
||||||
|
|
||||||
(defmethod visit :vector [_ _ children _]
|
(defmethod visit :vector [_ _ children _]
|
||||||
(str "[" (last children) "]"))
|
(str "[" (last children) "]"))
|
||||||
|
@ -123,10 +125,12 @@
|
||||||
(defmethod visit :repeat [_ schema children _]
|
(defmethod visit :repeat [_ schema children _]
|
||||||
(str "repeat " (-diamond (first children)) (-repeat-suffix schema)))
|
(str "repeat " (-diamond (first children)) (-repeat-suffix schema)))
|
||||||
|
|
||||||
|
|
||||||
(defmethod visit :set [_ schema children _]
|
(defmethod visit :set [_ schema children _]
|
||||||
(str "set[" (first children) "]" (minmax-suffix schema)))
|
(str "set[" (first children) "]" (minmax-suffix schema)))
|
||||||
|
|
||||||
|
(defmethod visit ::sm/set [_ schema children _]
|
||||||
|
(str "set[" (first children) "]" (minmax-suffix schema)))
|
||||||
|
|
||||||
(defmethod visit ::m/val [_ schema children _]
|
(defmethod visit ::m/val [_ schema children _]
|
||||||
(let [suffix (minmax-suffix schema)]
|
(let [suffix (minmax-suffix schema)]
|
||||||
(cond-> (first children)
|
(cond-> (first children)
|
||||||
|
@ -152,7 +156,6 @@
|
||||||
(or (:title props)
|
(or (:title props)
|
||||||
"*")))
|
"*")))
|
||||||
|
|
||||||
|
|
||||||
(defmethod visit :map
|
(defmethod visit :map
|
||||||
[_ schema children {:keys [::level ::max-level] :as options}]
|
[_ schema children {:keys [::level ::max-level] :as options}]
|
||||||
(let [props (m/properties schema)
|
(let [props (m/properties schema)
|
||||||
|
@ -172,13 +175,11 @@
|
||||||
": " s)))
|
": " s)))
|
||||||
(str/join ",\n"))
|
(str/join ",\n"))
|
||||||
|
|
||||||
header (cond-> (if (zero? level)
|
header (cond-> (str "type " title)
|
||||||
(str "type " title)
|
|
||||||
(str title))
|
|
||||||
closed? (str "!")
|
closed? (str "!")
|
||||||
(some? title) (str " "))]
|
(some? title) (str " "))]
|
||||||
|
|
||||||
(str header "{\n" entries "\n" (pad "}" level))))))
|
(str (pad header level) "{\n" entries "\n" (pad "}\n" level))))))
|
||||||
|
|
||||||
(defmethod visit :multi
|
(defmethod visit :multi
|
||||||
[_ s children {:keys [::level ::max-level] :as options}]
|
[_ s children {:keys [::level ::max-level] :as options}]
|
||||||
|
@ -205,18 +206,18 @@
|
||||||
|
|
||||||
(defmethod visit :merge
|
(defmethod visit :merge
|
||||||
[_ schema children _]
|
[_ schema children _]
|
||||||
(let [entries (str/join " , " children)
|
(let [entries (str/join ",\n" children)
|
||||||
props (m/properties schema)
|
props (m/properties schema)
|
||||||
title (or (some-> (:title props) str/camel str/capital)
|
title (or (some-> (:title props) str/camel str/capital)
|
||||||
"<untitled>")]
|
"<untitled>")]
|
||||||
(str "merge object " title " { " entries " }")))
|
(str "merge type " title " { \n" entries "\n}\n")))
|
||||||
|
|
||||||
(defmethod visit :app.common.schema/one-of
|
(defmethod visit ::sm/one-of
|
||||||
[_ _ children _]
|
[_ _ children _]
|
||||||
(let [elems (last children)]
|
(let [elems (last children)]
|
||||||
(str "OneOf[" (->> elems
|
(str "string oneOf (" (->> elems
|
||||||
(map d/name)
|
(map d/name)
|
||||||
(str/join ",")) "]")))
|
(str/join "|")) ")")))
|
||||||
|
|
||||||
(defmethod visit :schema [_ schema children options]
|
(defmethod visit :schema [_ schema children options]
|
||||||
(visit ::m/schema schema children options))
|
(visit ::m/schema schema children options))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue