parses a project codebases and generates a swagger/OpenAPI schema
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

47 satır
1.5KB

  1. (ns scan.lang.php.laravel5
  2. (:require [clojure.string :as str]
  3. [clojure.java.io :as io]))
  4. (def
  5. ^{}
  6. load-method-signature!
  7. (fn [route]
  8. (cond (.exists (io/file (:ctl route)))
  9. (let [src (slurp (:ctl route))]
  10. (->>
  11. (-> (re-pattern (str "function " (:act route) "\\((.*)\\)"))
  12. (re-find src)
  13. last
  14. (or "")
  15. (str/split #","))
  16. (map str/trim)
  17. (filter (fn [e] (not (str/includes? e "Request"))))
  18. (into [])))
  19. :else nil)))
  20. (def
  21. ^{}
  22. routes
  23. (fn [project-path]
  24. (map (fn [route]
  25. (assoc route
  26. :signature
  27. (load-method-signature! route)))
  28. (let [route-file (str project-path "/routes/web.php")]
  29. (filter
  30. (fn [e]
  31. (not (nil? e)))
  32. (map
  33. (fn [hit]
  34. (let [[_ verb raw-params] hit
  35. params (map (fn [e] (str/trim (str/escape e {\' ""}))) (str/split raw-params #","))
  36. [route ctl] params]
  37. (if ctl
  38. {:verb verb
  39. :path route
  40. :ctl (str project-path "/app/Http/Controllers/" (str/replace (str/replace ctl #"\@(.*)" ".php") "\\" "/"))
  41. :act (str/replace ctl #"(.*)\@" "")}
  42. nil)))
  43. (re-seq
  44. #"router->(.*)\((.*)\)"
  45. (slurp route-file))))))))