File tree 2 files changed +21
-23
lines changed
2 files changed +21
-23
lines changed Original file line number Diff line number Diff line change 150
150
151
151
; ; resolve references
152
152
153
- (defn- find-schema-by-url [schemas url]
154
- (->> schemas
155
- (filter #(= url (:url %)))
156
- (first )))
157
-
158
- (defn- find-element-by-reference [element-reference schemas]
159
- (let [[schema-url & path] element-reference
160
- schema (find-schema-by-url schemas schema-url)
161
- element (get-in schema (map keyword path))]
162
- (or element {})))
163
-
164
- (defn find-elements-by-names [element-names schema]
165
- (filter #(contains?
166
- (set element-names)
167
- (:name %))
168
- (:elements schema)))
169
-
170
- (defn resolve-references [schemas]
153
+ (defn resolve-element-references [schemas]
171
154
(walk/postwalk
172
155
(fn [x]
173
- (if-let [reference (:elementReference x)]
156
+ ; ; TODO add type of the reference
157
+ (if (:elementReference x)
174
158
(merge (dissoc x :elementReference )
175
- ( find-element-by-reference reference schemas) )
159
+ { :type " Reference " } )
176
160
x))
177
161
schemas))
178
162
179
163
; ;
180
164
165
+ (defn find-elements-by-names [element-names schema]
166
+ (filter #(contains?
167
+ (set element-names)
168
+ (:name %))
169
+ (:elements schema)))
170
+
181
171
(defn resolve-element-choices [schema el]
182
172
(if (:choices el)
183
173
(let [choices (find-elements-by-names (:choices el) schema)]
224
214
225
215
(defn convert [schemas]
226
216
(->> schemas
227
- (resolve-references )
217
+ (resolve-element- references )
228
218
(compile-elements )
229
219
(combine-elements )
230
220
(map (fn [schema]
Original file line number Diff line number Diff line change 1
1
(ns aidbox-sdk.converter-test
2
2
(:require
3
3
[aidbox-sdk.converter :as sut]
4
+ [aidbox-sdk.fixtures :as fixt]
4
5
[aidbox-sdk.fixtures.schemas :as fixtures]
5
- [clojure.test :refer [are deftest is testing]]))
6
+ [clojure.test :refer [are deftest is testing use-fixtures]]))
7
+
8
+ (use-fixtures :once fixt/prepare-examples)
6
9
7
10
(deftest test-converter-utils
8
11
(testing " url->resource-name"
24
27
25
28
(deftest test-resolve-references
26
29
(is (= fixtures/schemas-with-element-reference-resolved
27
- (sut/resolve-references fixtures/schemas-with-element-reference))))
30
+ (sut/resolve-element- references fixtures/schemas-with-element-reference))))
28
31
29
32
(deftest test-resolve-choices
30
33
(is (= fixtures/schemas-with-element-choices-resolved
49
52
(= fixtures/observation-constraints-ir-schema
50
53
(sut/convert-constraints fixtures/observation-constraints
51
54
[fixtures/observation-ir-schema])))))
55
+
56
+ (comment
57
+ (fixt/load-data! )
58
+
59
+ @fixt/data)
You can’t perform that action at this time.
0 commit comments