Skip to content

Commit

Permalink
fix(typescript): replace hardcoded search params with generated
Browse files Browse the repository at this point in the history
  • Loading branch information
krvital committed Nov 7, 2024
1 parent fd4b548 commit 42ac573
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 23 deletions.
16 changes: 12 additions & 4 deletions src/aidbox_sdk/converter.clj
Original file line number Diff line number Diff line change
Expand Up @@ -345,12 +345,18 @@
;; Search Params
;;

(defn distinct-by [key-fn coll]
(reduce (fn [acc item]
(if (some #(= (key-fn %) (key-fn item)) acc)
acc
(conj acc item)))
[]
coll))

(defn resolve-elements [schemas resource]
(->> schemas
(filter #(contains? (set (:base %)) resource))
(map :code)
(distinct)
(sort)))
(distinct-by :code)))

(defn convert-search-params [search-params-schemas all-schemas]
(->> all-schemas
Expand All @@ -363,7 +369,9 @@
:base (when-let [base (:base schema)]
(->pascal-case (url->resource-name base)))
:elements (->> (resolve-elements search-params-schemas (:id schema))
(map (fn [el] {:type "string" :name el})))}))
(map (fn [el] {:type "string"
:name (:code el)
:target (:target el)})))}))
(remove #(and
(not= (:name %) "Base")
(empty? (:elements %))))))
Expand Down
Loading

0 comments on commit 42ac573

Please sign in to comment.