Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/navi/transform.clj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
ObjectSchema
Schema
StringSchema
DateTimeSchema
UUIDSchema]
[io.swagger.v3.oas.models.parameters
CookieParameter
Expand Down Expand Up @@ -57,6 +58,9 @@
:else
content-fn)))

DateTimeSchema
(p/transform [_] inst?)

UUIDSchema
(p/transform [_] uuid?)

Expand Down
12 changes: 10 additions & 2 deletions test/navi/impl_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
(is (= {:query [:map [:x string?]]}
(i/wrap-map :path {:query [:map [:x string?]]})))))



(deftest openapi-properties-to-malli-spec
(testing "convert a required OpenAPI Map entry"
(let [property (Map/entry "id" (StringSchema.))]
Expand All @@ -37,7 +39,11 @@
(testing "convert an optional OpenAPI Map entry"
(let [property (Map/entry "id" (StringSchema.))]
(is (= [:id {:optional true} string?]
(i/->prop-schema #{"x"} property))))))
(i/->prop-schema #{"x"} property)))))
(testing "convert a DateTime OpenAPI Map entry"
(let [property (Map/entry "timestamp" (.DateTimeSchema.))]
(is (= [:timestamp inst?]
(i/->prop-schema #{"timestamp"} property))))))

(deftest openapi-parameters-to-malli-spec
(testing "convert a required OpenAPI Parameter"
Expand All @@ -54,6 +60,8 @@
(is (= [:x {:optional true} string?]
(i/->param-schema param))))))



(deftest responses-to-malli-spec
(testing "empty response"
(let [response (ApiResponse.)]
Expand Down Expand Up @@ -141,4 +149,4 @@
(.setGet operation))]
(is (= {:get {:handler "a handler"
:parameters {:path [:map [:x int?]]}}}
(i/path-item->data path-item handlers))))))
(i/path-item->data path-item handlers))))))
3 changes: 3 additions & 0 deletions test/navi/transform_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
ByteArraySchema
ComposedSchema
Content
DateTimeSchema
IntegerSchema
JsonSchema
MediaType
Expand All @@ -34,6 +35,8 @@
[java.util LinkedHashMap]))

(deftest primitives
(testing "datetime"
(is (= inst? (p/transform (DateTimeSchema.)))))
(testing "string"
(is (= string? (p/transform (StringSchema.)))))
(testing "integer"
Expand Down