|
41 | 41 | m)))
|
42 | 42 |
|
43 | 43 | (defn schema->spec [^Schema schema]
|
44 |
| - (let [types (.getTypes schema)] |
45 |
| - (if (= 1 (count types)) |
46 |
| - (spec schema) |
47 |
| - (try |
48 |
| - (->> (map (fn [type] |
49 |
| - (.setTypes schema #{type}) |
50 |
| - (spec schema)) |
51 |
| - types) |
52 |
| - (into [:or])) |
53 |
| - (finally |
54 |
| - (.setTypes schema types)))))) |
| 44 | + (if schema |
| 45 | + (let [types (.getTypes schema)] |
| 46 | + (if (= 1 (count types)) |
| 47 | + (spec schema) |
| 48 | + (try |
| 49 | + (->> (map (fn [type] |
| 50 | + (.setTypes schema #{type}) |
| 51 | + (spec schema)) |
| 52 | + types) |
| 53 | + (into [:or])) |
| 54 | + (finally |
| 55 | + (.setTypes schema types))))) |
| 56 | + (throw (ex-info "Missing schema" {})))) |
55 | 57 |
|
56 | 58 | ;; TODO: Better
|
57 | 59 | (defn ->prop-schema
|
|
192 | 194 | (defn media-type->data
|
193 | 195 | "Convert a Java Schema's MediaType to a spec that Reitit will accept."
|
194 | 196 | [^MediaType mt]
|
195 |
| - {:schema (spec (.getSchema mt))}) |
| 197 | + (if-let [schema (some-> mt .getSchema spec)] |
| 198 | + {:schema schema} |
| 199 | + (throw (ex-info "MediaType has no schema" {:media-type mt})))) |
196 | 200 |
|
197 | 201 | (defn handle-media-type-key
|
198 | 202 | "If the media type is \"default\", then return it as a keyword, otherwise pass through."
|
|
220 | 224 | "Converts a Java Operation to a map of parameters, responses, schemas and handler
|
221 | 225 | that conforms to reitit."
|
222 | 226 | [^Operation op handlers]
|
223 |
| - (let [params (into [] (.getParameters op)) |
224 |
| - request-body (.getRequestBody op) |
225 |
| - params (if (nil? request-body) |
226 |
| - params |
227 |
| - (conj params request-body)) |
228 |
| - schemas (->> params |
229 |
| - (map param->data) |
230 |
| - (apply merge-with into) |
231 |
| - (wrap-map :path) |
232 |
| - (wrap-map :query) |
233 |
| - (wrap-map :header)) |
234 |
| - responses (-> (.getResponses op) |
235 |
| - (update-kvs handle-response-key response->data))] |
236 |
| - (cond-> {:handler (get handlers (.getOperationId op))} |
237 |
| - (seq schemas) (assoc :parameters schemas) |
238 |
| - (seq responses) (assoc :responses responses)))) |
| 227 | + (try |
| 228 | + (let [params (into [] (.getParameters op)) |
| 229 | + request-body (.getRequestBody op) |
| 230 | + params (if (nil? request-body) |
| 231 | + params |
| 232 | + (conj params request-body)) |
| 233 | + schemas (->> params |
| 234 | + (map param->data) |
| 235 | + (apply merge-with into) |
| 236 | + (wrap-map :path) |
| 237 | + (wrap-map :query) |
| 238 | + (wrap-map :header)) |
| 239 | + responses (-> (.getResponses op) |
| 240 | + (update-kvs handle-response-key response->data))] |
| 241 | + (cond-> {:handler (get handlers (.getOperationId op))} |
| 242 | + (seq schemas) (assoc :parameters schemas) |
| 243 | + (seq responses) (assoc :responses responses))) |
| 244 | + (catch Exception e |
| 245 | + (throw (ex-info (str "Exception processing operation " |
| 246 | + (pr-str (.getOperationId op)) |
| 247 | + ": "(ex-message e)) |
| 248 | + {:operation op} |
| 249 | + e))))) |
239 | 250 |
|
240 | 251 | (defn path-item->data
|
241 | 252 | "Converts a path to its corresponding vector of method and the operation map"
|
|
0 commit comments