Skip to content

Commit

Permalink
handle empty case
Browse files Browse the repository at this point in the history
  • Loading branch information
ikitommi committed Apr 15, 2015
1 parent 0f2acf0 commit 9b2f716
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
4 changes: 3 additions & 1 deletion src/ring/swagger/swagger2.clj
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@

(defn ->properties [schema]
(binding [jsons/*swagger-spec-version* "2.0"]
(jsons/properties schema)))
(let [properties (jsons/properties schema)]
(if-not (empty? properties)
properties))))

(defn ->additional-properties [schema]
(binding [jsons/*swagger-spec-version* "2.0"]
Expand Down
27 changes: 18 additions & 9 deletions test/ring/swagger/swagger2_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -245,19 +245,28 @@
(fact "additionalProperties"
(let [Kikka (s/schema-with-name {:a s/Str s/Keyword s/Str} 'Kikka)
Kukka (s/schema-with-name {:a s/Str s/Keyword Kikka} 'Kukka)
Kakka (s/schema-with-name {s/Keyword Kukka} 'Kakka)
swagger {:paths {"/kikka" {:post {:parameters {:body Kikka}}}
"/kukka" {:post {:parameters {:body Kukka}}}}}
"/kukka" {:post {:parameters {:body Kukka}}}
"/kakka" {:post {:parameters {:body Kakka}}}}}
spec (swagger-json swagger)]
(validate swagger) => nil

(fact "keyword to primitive mapping"
spec => (has-definition 'Kikka
{:properties {:a {:type "string"}}
:additionalProperties {:type "string"}
:required [:a]}))
spec => (has-definition
'Kikka
{:properties {:a {:type "string"}}
:additionalProperties {:type "string"}
:required [:a]}))

(fact "keyword to model mapping"
spec => (has-definition 'Kukka
{:properties {:a {:type "string"}}
:additionalProperties {:$ref "#/definitions/Kikka"}
:required [:a]}))))
spec => (has-definition
'Kukka
{:properties {:a {:type "string"}}
:additionalProperties {:$ref "#/definitions/Kikka"}
:required [:a]}))

(fact "just additional properties"
spec => (has-definition
'Kakka
{:additionalProperties {:$ref "#/definitions/Kukka"}}))))

0 comments on commit 9b2f716

Please sign in to comment.