diff --git a/src/ring/swagger/swagger2.clj b/src/ring/swagger/swagger2.clj index 6eb770cf..6b673c85 100644 --- a/src/ring/swagger/swagger2.clj +++ b/src/ring/swagger/swagger2.clj @@ -39,13 +39,15 @@ (defmulti ^:private extract-parameter (fn [in _ _] in)) (defmethod extract-parameter :body [_ model options] - (if-let [schema (rsc/peek-schema model)] - (let [schema-json (rsjs/->swagger model options)] - (vector {:in "body" - :name (common/title schema) - :description (or (:description (rsjs/json-schema-meta schema)) "") - :required (not (rsjs/maybe? model)) - :schema schema-json})))) + (if model + (let [schema (rsc/peek-schema model) + schema-json (rsjs/->swagger model options)] + (vector + {:in "body" + :name (or (common/title schema) "") + :description (or (:description (rsjs/json-schema-meta schema)) "") + :required (not (rsjs/maybe? model)) + :schema schema-json})))) (defmethod extract-parameter :default [in model options] (if model diff --git a/test/ring/swagger/swagger2_test.clj b/test/ring/swagger/swagger2_test.clj index cbba648b..faf1f12c 100644 --- a/test/ring/swagger/swagger2_test.clj +++ b/test/ring/swagger/swagger2_test.clj @@ -479,3 +479,57 @@ :responses {:default {:description ""}}}}}}) (validate swagger) => nil)) + +(fact "primitive vector body parameters & responses" + (let [swagger {:paths {"/api" {:post {:parameters {:body [s/Str]} + :responses {200 {:schema [s/Str]}}}}}}] + (swagger2/swagger-json swagger) + => (contains + {:definitions {} + :paths {"/api" {:post {:parameters [{:in "body" + :name "" + :description "" + :required true + :schema {:items {:type "string"} + :type "array"}}] + :responses {200 {:description "" + :schema {:items {:type "string"} + :type "array"}}}}}}}) + + (validate swagger) => nil)) + +(fact "primitive set body parameters & responses" + (let [swagger {:paths {"/api" {:post {:parameters {:body #{s/Str}} + :responses {200 {:schema #{s/Str}}}}}}}] + (swagger2/swagger-json swagger) + => (contains + {:definitions {} + :paths {"/api" {:post {:parameters [{:in "body" + :name "" + :description "" + :required true + :schema {:items {:type "string"} + :uniqueItems true + :type "array"}}] + :responses {200 {:description "" + :schema {:items {:type "string"} + :uniqueItems true + :type "array"}}}}}}}) + + (validate swagger) => nil)) + +(fact "primitive body parameters & responses" + (let [swagger {:paths {"/api" {:post {:parameters {:body s/Str} + :responses {200 {:schema s/Str}}}}}}] + (swagger2/swagger-json swagger) + => (contains + {:definitions {} + :paths {"/api" {:post {:parameters [{:in "body" + :name "" + :description "" + :required true + :schema {:type "string"}}] + :responses {200 {:description "" + :schema {:type "string"}}}}}}}) + + (validate swagger) => nil))