File tree Expand file tree Collapse file tree 2 files changed +18
-12
lines changed Expand file tree Collapse file tree 2 files changed +18
-12
lines changed Original file line number Diff line number Diff line change 31
31
RequestBody]))
32
32
33
33
(defn- transform-object
34
- [schema]
34
+ [^ObjectSchema schema]
35
35
(let [required (->> schema
36
36
.getRequired
37
37
(into #{}))
41
41
(into []))]
42
42
(into [:map {:closed false }] schemas)))
43
43
44
- (defn- transform-array [schema]
44
+ (defn- transform-array
45
+ [^ArraySchema schema]
45
46
(let [items (.getItems schema)]
46
47
[:sequential
47
48
(if (nil? items)
48
49
any?
49
50
(p/transform items))]))
50
51
51
- (defn- transform-composed [schema]
52
+ (defn- transform-composed
53
+ [^ComposedSchema schema]
52
54
(let [[schemas compose-as] (cond
53
55
(< 0 (count (.getAnyOf schema)))
54
56
[(.getAnyOf schema) :or ]
55
-
57
+
56
58
(< 0 (count (.getAllOf schema)))
57
59
[(.getAllOf schema) :and ]
58
-
59
- :else
60
+
61
+ :else ; ; TODO: Implement oneOf
60
62
(throw (IllegalArgumentException. " Unsupported composite schema. Use either anyOf, allOf" )))]
61
63
(->> schemas
62
64
(map p/transform)
101
103
BooleanSchema
102
104
(p/transform [_] boolean?)
103
105
104
- ; ; TODO: Implement oneOf
105
106
ComposedSchema
106
107
(p/transform [schema]
107
108
(transform-composed schema))
116
117
117
118
JsonSchema
118
119
(p/transform [schema]
119
- (let [pred (fn [type ]
120
- (case type
120
+ (let [pred (fn [typ ]
121
+ (case typ
121
122
" array" (transform-array schema)
122
123
" boolean" boolean?
123
124
" integer" int?
124
125
" null" nil?
125
126
" number" number?
126
127
" object" (transform-object schema)
127
128
" string" string?
128
- (throw (Exception . (str " Unsupported schema" schema)))))
129
+ (throw (IllegalArgumentException . (format " Unsupported type %s for schema %s " typ schema)))))
129
130
types (.getTypes schema)]
130
131
(case (count types)
131
132
0 (transform-composed schema)
182
183
body-spec
183
184
[:or nil? body-spec])})
184
185
{})))
186
+
187
+ (comment
188
+ (set! *warn-on-reflection* true ))
Original file line number Diff line number Diff line change 175
175
(.setAnyOf [(StringSchema. ) (IntegerSchema. )])))))
176
176
(is (= [:or string? int?]
177
177
(p/transform (doto (JsonSchema. )
178
- (.setAnyOf [(.types (JsonSchema. ) #{" string" }) (.types (JsonSchema. ) #{" integer" })]))))))
178
+ (.setAnyOf [(.types (JsonSchema. ) #{" string" })
179
+ (.types (JsonSchema. ) #{" integer" })]))))))
179
180
(testing " allOf"
180
181
(is (= [:and string? int?]
181
182
(p/transform (doto (ComposedSchema. )
182
183
(.setAllOf [(StringSchema. ) (IntegerSchema. )])))))
183
184
(is (= [:and string? int?]
184
185
(p/transform (doto (JsonSchema. )
185
- (.setAllOf [(.types (JsonSchema. ) #{" string" }) (.types (JsonSchema. ) #{" integer" })])))))))
186
+ (.setAllOf [(.types (JsonSchema. ) #{" string" })
187
+ (.types (JsonSchema. ) #{" integer" })])))))))
You can’t perform that action at this time.
0 commit comments