Skip to content

Commit

Permalink
fix(typescript): valueset names should clash with resource names
Browse files Browse the repository at this point in the history
  • Loading branch information
krvital committed Oct 21, 2024
1 parent 528b059 commit e0cf9ad
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/aidbox_sdk/generator/typescript.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
(:import
[aidbox_sdk.generator CodeGenerator]))


(def reserved-names #{"RequestPriority"})
(def valuset-exception #{"SubscriptionStatus"})
(def reserved-name-suffix "_")

(defn package->directory
Expand All @@ -28,10 +28,6 @@
(io/file (package->directory (:package ir-schema))
(str (->pascal-case (:resource-name ir-schema)) ".ts")))

(defn constraint-file-path [ir-schema name]
(io/file (package->directory (:package ir-schema))
(str (->pascal-case (:resource-name ir-schema)) ".ts")))

(defn search-param-filepath [ir-schema]
(io/file "search" (str (:name ir-schema) "SearchParameters.ts")))

Expand Down Expand Up @@ -77,6 +73,12 @@
(str name' "_")
name')))

(defn valueset-name [type-name]
(let [name' (class-name type-name)]
(if (contains? valuset-exception name')
(str name' "VS")
name')))

(defn generate-polymorphic-property [{:keys [name required choices]}]
(let [type (->> choices
(map :type)
Expand Down Expand Up @@ -104,7 +106,7 @@
(->backbone-type element)

(:valueset element)
(class-name (:valueset element))
(valueset-name (:valueset element))

:else
(->lang-type (:type element)))
Expand Down Expand Up @@ -177,7 +179,7 @@
(seq (:valueset-deps ir-schema)))
(format "import { %s } from \"./valuesets\""
(->> (:valueset-deps ir-schema)
(map class-name)
(map valueset-name)
(str/join ", "))))]
(str (->> (:deps ir-schema)
(map class-name)
Expand Down Expand Up @@ -257,7 +259,7 @@
:content
(->> schemas
(mapv (fn [vs]
(let [type-name (class-name (:name vs))
(let [type-name (valueset-name (:name vs))
values (->> (:values vs)
(map #(format "\"%s\"" %))
(str/join " | "))]
Expand Down

0 comments on commit e0cf9ad

Please sign in to comment.