File tree Expand file tree Collapse file tree 3 files changed +38
-13
lines changed Expand file tree Collapse file tree 3 files changed +38
-13
lines changed Original file line number Diff line number Diff line change 7
7
{:deps {io.swagger.parser.v3/swagger-parser {:mvn/version " 2.1.22" }}
8
8
:aliases {:test {:extra-paths [" test" ]
9
9
:extra-deps {io.github.cognitect-labs/test-runner
10
- {:git/tag " v0.5.1" :git/sha " dfb30dd" }}
10
+ {:git/tag " v0.5.1" :git/sha " dfb30dd" }
11
+ metosin/malli {:mvn/version " 0.16.4" }}
11
12
:main-opts [" -m" " cognitect.test-runner" ]
12
13
:exec-fn cognitect.test-runner.api/test}}}
Original file line number Diff line number Diff line change 95
95
(let [content-fn (if (= " uuid" (.getFormat schema))
96
96
uuid?
97
97
string?)
98
- pattern (.getPattern schema)]
99
- (if pattern
100
- [:and content-fn (re-pattern pattern)]
101
- content-fn)))
98
+ max-length (.getMaxLength schema)
99
+ min-length (.getMinLength schema)
100
+ properties (cond-> nil
101
+ max-length (assoc :max max-length)
102
+ min-length (assoc :min min-length))
103
+ pattern (some-> schema .getPattern re-pattern)]
104
+ (cond
105
+ (and properties pattern)
106
+ [:and content-fn [:string properties] pattern]
107
+
108
+ (and properties (= string? content-fn))
109
+ [:string properties]
110
+
111
+ properties
112
+ [:and content-fn [:string properties]]
113
+
114
+ pattern
115
+ [:and content-fn pattern]
116
+
117
+ :else content-fn)))
102
118
103
119
(defmethod spec
104
120
" integer"
Original file line number Diff line number Diff line change 6
6
7
7
(ns navi.core-test
8
8
(:require [clojure.test :refer [deftest testing is]]
9
+ [malli.core :as m]
9
10
[navi.core :as core])
10
11
(:import [clojure.lang ExceptionInfo]
11
12
[io.swagger.v3.oas.models Operation PathItem]
127
128
(is (#{[:or string? int?] [:or int? string?]}
128
129
(core/schema->spec strint)))))
129
130
(testing " regex string"
130
- (let [[kw f regex] (core/schema->spec (doto (Schema. )
131
- (.addType " string" )
132
- (.setPattern " ^(\\ d+)([KMGTPE]i{0,1})$" )))]
133
- (is (= :and kw))
134
- (is (= string? f))
135
- (is (instance? java.util.regex.Pattern regex))
136
- (is (some? (re-matches regex " 1024Ki" )))
137
- (is (nil? (re-matches regex " 1024Kib" ))))))
131
+ (let [spec (core/schema->spec (doto (Schema. )
132
+ (.addType " string" )
133
+ (.setPattern " ^(\\ d+)([KMGTPE]i{0,1})$" )))]
134
+ (is (m/validate spec " 1024Ki" ))
135
+ (is (not (m/validate spec " 1024Kib" ))))
136
+ (testing " minLength and maxLength"
137
+ (let [spec (core/schema->spec (doto (Schema. )
138
+ (.addType " string" )
139
+ (.setMinLength (int 3 ))
140
+ (.setMaxLength (int 8 ))))]
141
+ (is (not (m/validate spec " " )))
142
+ (is (not (m/validate spec " 1" )))
143
+ (is (m/validate spec " 123" ))
144
+ (is (m/validate spec " 12345678" ))
145
+ (is (not (m/validate spec " 123456789" )))))))
138
146
139
147
(deftest responses-to-malli-spec
140
148
(testing " empty response"
You can’t perform that action at this time.
0 commit comments