|
6 | 6 |
|
7 | 7 | (ns navi.impl-test |
8 | 8 | (:require |
| 9 | + [clojure.java.io :as io] |
9 | 10 | [clojure.test :refer [deftest is testing]] |
10 | 11 | [navi.core :as navi] |
11 | | - [navi.impl :as i] |
12 | | - [clojure.java.io :as io]) |
| 12 | + [navi.impl :as i]) |
13 | 13 | (:import |
14 | 14 | [clojure.lang ExceptionInfo] |
15 | 15 | [io.swagger.v3.oas.models Operation PathItem] |
16 | 16 | [io.swagger.v3.oas.models.media |
17 | 17 | Content |
| 18 | + DateSchema |
| 19 | + DateTimeSchema |
18 | 20 | IntegerSchema |
19 | 21 | MediaType |
20 | 22 | ObjectSchema |
|
39 | 41 | (testing "convert an optional OpenAPI Map entry" |
40 | 42 | (let [property (Map/entry "id" (StringSchema.))] |
41 | 43 | (is (= [:id {:optional true} string?] |
42 | | - (i/->prop-schema #{"x"} property)))))) |
| 44 | + (i/->prop-schema #{"x"} property))))) |
| 45 | + |
| 46 | + (testing "convert a DateTime OpenAPI Map entry" |
| 47 | + (let [property (Map/entry "timestamp" (DateTimeSchema.))] |
| 48 | + (is (= [:timestamp inst?] |
| 49 | + (i/->prop-schema #{"timestamp"} property))))) |
| 50 | + |
| 51 | + (testing "convert a Date OpenAPI Map entry" |
| 52 | + (let [property (Map/entry "date" (DateSchema.))] |
| 53 | + (is (= [:date inst?] |
| 54 | + (i/->prop-schema #{"date"} property)))))) |
43 | 55 |
|
44 | 56 | (deftest openapi-parameters-to-malli-spec |
45 | 57 | (testing "convert a required OpenAPI Parameter" |
|
144 | 156 | (is (= {:get {:handler "a handler" |
145 | 157 | :parameters {:path [:map [:x int?]]}}} |
146 | 158 | (i/path-item->data path-item handlers)))))) |
| 159 | + |
147 | 160 | (defn find-route [rts path method] |
148 | | - (some (fn [[p r]] |
149 | | - (when (= p path) |
150 | | - (get r method))) |
151 | | - rts)) |
| 161 | + (some (fn [[p r]] |
| 162 | + (when (= p path) |
| 163 | + (get r method))) |
| 164 | + rts)) |
152 | 165 |
|
153 | 166 | (deftest security-requirements-test |
154 | 167 | (testing "Verifying security requirements from security-users.yml" |
155 | 168 | ;; A dummy map of operationId to handler (the actual function doesn't matter for this test). |
156 | | - (let [handlers {"listUsers" (constantly :ok) |
157 | | - "listUsersSingle" (constantly :ok) |
158 | | - "listUsersNoScope" (constantly :ok) |
| 169 | + (let [handlers {"listUsers" (constantly :ok) |
| 170 | + "listUsersSingle" (constantly :ok) |
| 171 | + "listUsersNoScope" (constantly :ok) |
159 | 172 | "listUsersNoSecurity" (constantly :ok)} |
160 | 173 | api-spec (slurp (io/resource "security-users.yml")) |
161 | | - routes (navi/routes-from api-spec handlers)] |
162 | | - |
| 174 | + routes (navi/routes-from api-spec handlers)] |
| 175 | + |
163 | 176 | (testing "multiple security schemes" |
164 | 177 | (let [route (find-route routes "/users" :get)] |
165 | 178 | (is (some? route) "Should have found /users GET route") |
|
0 commit comments