|
| 1 | +(ns codegen3.methods |
| 2 | + (:require [clojure.data.json :as json] |
| 3 | + [codegen3.javagen :as javagen] |
| 4 | + [codegen3.signatures :as sgn]) |
| 5 | + (:gen-class) ) |
| 6 | + |
| 7 | + |
| 8 | +;; Il metodo di base si aspetta: |
| 9 | +;; :path |
| 10 | +;; :descr |
| 11 | +;; :op (che è una sola delle operations) |
| 12 | + |
| 13 | + |
| 14 | +; { |
| 15 | +; "path": "/applications/{applicationName}", |
| 16 | +; "description": "Stasis application", |
| 17 | +; "operations": [ |
| 18 | +; { |
| 19 | +; "httpMethod": "GET", |
| 20 | +; "summary": "Get details of an application.", |
| 21 | +; "nickname": "get", |
| 22 | +; "responseClass": "Application", |
| 23 | +; "parameters": [ |
| 24 | +; { |
| 25 | +; "name": "applicationName", |
| 26 | +; "description": "Application's name", |
| 27 | +; "paramType": "path", |
| 28 | +; "required": true, |
| 29 | +; "allowMultiple": false, |
| 30 | +; "dataType": "string" |
| 31 | +; } |
| 32 | +; ], |
| 33 | +; "errorResponses": [ |
| 34 | +; { |
| 35 | +; "code": 404, |
| 36 | +; "reason": "Application does not exist." |
| 37 | +; } |
| 38 | +; ] |
| 39 | +; } |
| 40 | +; ] |
| 41 | +; } |
| 42 | + |
| 43 | + |
| 44 | +(defn mkParm |
| 45 | + "Dato un elemento parameters e un tipo di espansione, ritorna il |
| 46 | + parametro in formato {:type :name :comment}" |
| 47 | + [parm exp] |
| 48 | + (let [n (:name parm) |
| 49 | + t (javagen/typeTranslator (:dataType parm) "") |
| 50 | + c (:description parm)] |
| 51 | + {:type t |
| 52 | + :name n |
| 53 | + :comment c})) |
| 54 | + |
| 55 | + |
| 56 | +(defn baseSignature |
| 57 | + "La signature di base, senza callback" |
| 58 | + [path descr op] |
| 59 | + (let [nick (:nickname op) |
| 60 | + summary (str descr "\n" (:summary op)) |
| 61 | + response (javagen/typeTranslator (:responseClass op) "") |
| 62 | + parms (:parameters op)] |
| 63 | + { |
| 64 | + :method nick |
| 65 | + :returns response |
| 66 | + :isPrivate false |
| 67 | + :args (mapv #(mkParm % "") parms) |
| 68 | + :notes summary |
| 69 | + :body "" |
| 70 | + :isAbstract true |
| 71 | + })) |
| 72 | + |
| 73 | + |
| 74 | +(defn allSignsForPath |
| 75 | + "Per un path dato, tutte le sue signatures" |
| 76 | + [path-str] |
| 77 | + (let [path (:path path-str) |
| 78 | + des (:description path-str) |
| 79 | + ops (:operations path-str)] |
| 80 | + (map #(baseSignature path des %) ops))) |
| 81 | + |
| 82 | + |
| 83 | + |
| 84 | +(defn allSigsForAriFile |
| 85 | + "Tutte le signatures per un file dato di un'ari data" |
| 86 | + [db ari-ver file] |
| 87 | + (let [file-paths (get-in db [ari-ver file :apis])] |
| 88 | + (flatten (mapv allSignsForPath file-paths)))) |
| 89 | + |
| 90 | + |
| 91 | +(defn- rdc-addSigToMap |
| 92 | + [acc sig] |
| 93 | + (let [k (sgn/getMethodSignature sig)] |
| 94 | + (assoc-in acc [k] sig))) |
| 95 | + |
| 96 | + |
| 97 | +(defn allSigsForInterface |
| 98 | + "Tutte le signatures per creare un'interfaccia. |
| 99 | + Per calcolarle: |
| 100 | + - cerco le signatures per tutte le versioni note dell'ari |
| 101 | + - le rendo univoche sulla base della loro signature java |
| 102 | + Restituisco un hash la cui chiave è la sig Java ed il contenuto è |
| 103 | + il metodo. |
| 104 | + " |
| 105 | + [DB file ari-versions] |
| 106 | + (let [all-possible-sgns |
| 107 | + (reduce into [] |
| 108 | + (map #(allSigsForAriFile DB % file) ari-versions))] |
| 109 | + (reduce rdc-addSigToMap {} all-possible-sgns) |
| 110 | + |
| 111 | + )) |
| 112 | + |
| 113 | + |
| 114 | + |
| 115 | +;(def DB (readAll)) |
| 116 | +;(reduce into #{} (map #(allSigsForAriFile DB % :applications) |
| 117 | +; [:ari_0_0_1 :ari_1_0_0]))) |
| 118 | + |
| 119 | + |
| 120 | + |
| 121 | + |
| 122 | + |
| 123 | + |
| 124 | + |
| 125 | + |
| 126 | + |
0 commit comments