|
8 | 8 | [ring.swagger.core :as swagger]
|
9 | 9 | [ring.swagger.ui :as rsui]
|
10 | 10 | [ring.swagger.swagger2 :as swagger2]
|
11 |
| - [compojure.api.routes :as routes] |
12 |
| - [cheshire.core :as cheshire])) |
| 11 | + [compojure.api.routes :as routes])) |
13 | 12 |
|
14 | 13 | (defn base-path [request]
|
15 | 14 | (let [context (swagger/context request)]
|
|
95 | 94 | (c/routes
|
96 | 95 | (if ui (apply swagger-ui ui (mapcat identity (merge (if spec {:swagger-docs (apply str (remove clojure.string/blank? [(:basePath data) spec]))}) ui-options))))
|
97 | 96 | (if spec (apply swagger-docs spec (mapcat identity data))))))))
|
98 |
| - |
99 |
| -(defn validate |
100 |
| - "Validates a api. If the api is Swagger-enabled, the swagger-spec |
101 |
| - is requested and validated against the JSON Schema. Returns either |
102 |
| - the (valid) api or throws an exception. Requires lazily the |
103 |
| - ring.swagger.validator -namespace allowing it to be excluded, #227" |
104 |
| - [api] |
105 |
| - (require 'ring.swagger.validator) |
106 |
| - (when-let [uri (swagger-spec-path api)] |
107 |
| - (let [validate (resolve 'ring.swagger.validator/validate) |
108 |
| - {status :status :as response} (api {:request-method :get |
109 |
| - :uri uri |
110 |
| - mw/rethrow-exceptions? true}) |
111 |
| - body (-> response :body slurp (cheshire/parse-string true))] |
112 |
| - |
113 |
| - (when-not (= status 200) |
114 |
| - (throw (ex-info (str "Coudn't read swagger spec from " uri) |
115 |
| - {:status status |
116 |
| - :body body}))) |
117 |
| - |
118 |
| - (when-let [errors (seq (validate body))] |
119 |
| - (throw (ex-info (str "Invalid swagger spec from " uri) |
120 |
| - {:errors errors |
121 |
| - :body body}))))) |
122 |
| - api) |
0 commit comments