File tree Expand file tree Collapse file tree 2 files changed +27
-6
lines changed Expand file tree Collapse file tree 2 files changed +27
-6
lines changed Original file line number Diff line number Diff line change 85
85
.getSchema
86
86
schema->spec))))
87
87
88
+ (defn matches-regex?
89
+ [exp s]
90
+ (-> exp
91
+ (re-pattern )
92
+ (re-matches s)
93
+ (some? )))
94
+
88
95
(defmulti spec
89
96
(fn [^Schema schema]
90
97
(or (first (.getTypes schema)) " null" )))
91
98
92
99
(defmethod spec
93
100
" string"
94
101
[^Schema schema]
95
- (if (= " uuid" (.getFormat schema))
96
- uuid?
97
- string?))
102
+ (let [content-fn (if (= " uuid" (.getFormat schema))
103
+ uuid?
104
+ string?)
105
+ pattern (.getPattern schema)]
106
+ (if pattern
107
+ [:and content-fn [:fn #(matches-regex? pattern %)]]
108
+ content-fn)))
98
109
99
110
(defmethod spec
100
111
" integer"
283
294
(-> " api.yaml"
284
295
slurp
285
296
(routes-from handlers)
286
- pp/pprint))
297
+ pp/pprint)
298
+
299
+ (matches-regex? " ^(\\ d+)([KMGTPE]i{0,1})$" " 1024Mi" ))
Original file line number Diff line number Diff line change 121
121
(core/schema->spec (doto (Schema. )
122
122
(.addType " string" )
123
123
(.setFormat " uuid" ))))))
124
-
125
124
(testing " jsonschemas with multiple types"
126
125
(let [strint (-> (JsonSchema. )
127
126
(.types #{" string" " integer" }))]
128
127
(is (#{[:or string? int?] [:or int? string?]}
129
- (core/schema->spec strint))))))
128
+ (core/schema->spec strint)))))
129
+ (testing " regex string"
130
+ (let [[kw1 fn1 [kw2 fn2]] (core/schema->spec (doto (Schema. )
131
+ (.addType " string" )
132
+ (.setPattern " ^(\\ d+)([KMGTPE]i{0,1})$" )))]
133
+ (is (= :and kw1))
134
+ (is (= string? fn1))
135
+ (is (= :fn kw2))
136
+ (is (fn2 " 1024Ki" ))
137
+ (is (not (fn2 " 1024Kib" ))))))
130
138
131
139
(deftest responses-to-malli-spec
132
140
(testing " empty response"
You can’t perform that action at this time.
0 commit comments