Skip to content

Commit e6806b4

Browse files
committed
refactor: remove duplicate code
1 parent 0038d76 commit e6806b4

File tree

6 files changed

+2922
-2932
lines changed

6 files changed

+2922
-2932
lines changed

src/aidbox_sdk/converter.clj

+6-5
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,12 @@
117117
(or (:required schema) [])
118118
(seq (:elements schema)))
119119
backbone-elements (remove empty? (:backbone-elements data))]
120-
(conj data
121-
{:backbone-elements
122-
(if (empty? backbone-elements)
123-
[]
124-
(map (fn [[k, v]] (compile-backbone name k v)) backbone-elements))})))
120+
(-> data
121+
(assoc :backbone-elements
122+
(if (empty? backbone-elements)
123+
[]
124+
(map (fn [[k, v]] (compile-backbone name k v)) backbone-elements)))
125+
(assoc :base "BackboneElement"))))
125126

126127
(defn- clear-backbone-elements [resource-type schema]
127128
(->> (:backbone-elements schema)

src/aidbox_sdk/generator/dotnet.clj

+7-16
Original file line numberDiff line numberDiff line change
@@ -295,25 +295,16 @@
295295
constraint-schemas)))))
296296

297297
(defn generate-constraint-module [schema]
298-
(let [backbone-elements-classes (->> (:backbone-elements schema)
299-
(map #(assoc % :base "BackboneElement"))
300-
(mapv generate-class))
301-
resource-class (generate-class schema backbone-elements-classes)]
302-
(generate-module
303-
:name (package->module-name (:package schema))
304-
:deps [{:module "Aidbox.FHIR.Base" :members []}
305-
{:module "Aidbox.FHIR.Utils" :members []}]
306-
:classes resource-class)))
298+
(generate-module
299+
:name (package->module-name (:package schema))
300+
:deps [{:module "Aidbox.FHIR.Base" :members []}
301+
{:module "Aidbox.FHIR.Utils" :members []}]
302+
:classes (generate-class schema (map generate-class schema))))
307303

308304
;;
309305
;; main
310306
;;
311307

312-
(defn generate-backbone-classes [ir-schema]
313-
(->> (ir-schema :backbone-elements)
314-
(map #(assoc % :base "BackboneElement"))
315-
(map generate-class)))
316-
317308
(defn datatypes-file-path []
318309
(io/file "Base.cs"))
319310

@@ -333,7 +324,7 @@
333324
:name "Aidbox.FHIR.Base"
334325
:classes (map (fn [ir-schema]
335326
(generate-class ir-schema
336-
(generate-backbone-classes ir-schema)))
327+
(map generate-class (:backbone-elements ir-schema))))
337328
ir-schemas))}])
338329

339330
(generate-resource-module [_ ir-schema]
@@ -343,7 +334,7 @@
343334
:deps [{:module "Aidbox.FHIR.Base" :members []}
344335
{:module "Aidbox.FHIR.Utils" :members []}]
345336
:classes [(generate-class ir-schema
346-
(generate-backbone-classes ir-schema))])})
337+
(map generate-class (:backbone-elements ir-schema)))])})
347338

348339
(generate-search-params [_ ir-schemas]
349340
(map (fn [ir-schema]

src/aidbox_sdk/generator/python.clj

+4-10
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,6 @@
167167
(flatten)
168168
(str/join "\n\n")))
169169

170-
(defn generate-backbone-classes
171-
"Generates classes from schema's backbone elements."
172-
[ir-schema]
173-
(->> (ir-schema :backbone-elements)
174-
(map #(assoc % :base "BackboneElement"))
175-
(map generate-class)))
176-
177170
;;
178171
;; Main
179172
;;
@@ -187,7 +180,8 @@
187180
{:module "typing" :members ["Optional" "List"]}]
188181
:classes (map (fn [ir-schema]
189182
(generate-class ir-schema
190-
(generate-backbone-classes ir-schema)))
183+
(map generate-class (:backbone-elements ir-schema))
184+
))
191185
ir-schemas))}])
192186

193187
(generate-resource-module [_ ir-schema]
@@ -197,7 +191,7 @@
197191
{:module "typing" :members ["Optional" "List"]}
198192
{:module "..base" :members ["*"]}]
199193
:classes [(generate-class ir-schema
200-
(generate-backbone-classes ir-schema))])})
194+
(map generate-class (:backbone-elements ir-schema)))])})
201195

202196
(generate-search-params [_ ir-schemas]
203197
(map (fn [ir-schema]
@@ -219,7 +213,7 @@
219213
{:module "typing" :members ["Optional" "List"]}
220214
{:module "..base" :members ["*"]}]
221215
:classes (generate-class (assoc schema :url constraint-name)
222-
(generate-backbone-classes schema)))})
216+
(map generate-class (:backbone-elements schema))))})
223217
constraint-ir-schemas))
224218

225219
(generate-sdk-files [_] (generator/prepare-sdk-files :python)))

src/aidbox_sdk/generator/typescript.clj

+3-10
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,6 @@
127127
(flatten)
128128
(str/join "\n\n")))
129129

130-
(defn generate-backbone-classes
131-
"Generates classes from schema's backbone elements."
132-
[ir-schema]
133-
(->> (ir-schema :backbone-elements)
134-
(map #(assoc % :base "BackboneElement"))
135-
(map generate-class)))
136-
137130
(defrecord TypeScriptCodeGenerator []
138131
CodeGenerator
139132
(generate-datatypes [_ ir-schemas]
@@ -144,13 +137,13 @@
144137
(sort-by :base)
145138
(map (fn [ir-schema]
146139
(generate-class ir-schema
147-
(generate-backbone-classes ir-schema))))))}])
140+
(map generate-class (:backbone-elements ir-schema)))))))}])
148141
(generate-resource-module [_ ir-schema]
149142
{:path (resource-file-path ir-schema)
150143
:content (generate-module
151144
{:deps [{:module "../datatypes" :members (:deps ir-schema)}]
152145
:classes [(generate-class ir-schema
153-
(generate-backbone-classes ir-schema))]})})
146+
(map generate-class (:backbone-elements ir-schema)))]})})
154147

155148
(generate-search-params [_ ir-schemas] []
156149
(map (fn [ir-schema]
@@ -170,7 +163,7 @@
170163
:content (generate-module
171164
:deps [{:module "../datatypes" :members (:deps schema)}]
172165
:classes (generate-class (assoc schema :url constraint-name)
173-
(generate-backbone-classes schema)))})
166+
(map generate-class (:backbone-elements schema))))})
174167
ir-schemas))
175168
(generate-sdk-files [this] (generator/prepare-sdk-files :typescript)))
176169

test/aidbox_sdk/converter_test.clj

+3-1
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,6 @@
4848
(is
4949
(= fixtures/observation-constraints-ir-schema
5050
(sut/convert-constraints fixtures/observation-constraints
51-
[fixtures/observation-ir-schema])))))
51+
[fixtures/observation-ir-schema])
52+
53+
))))

0 commit comments

Comments
 (0)