     ~(str desc "\n\nDocumentation link: " docs-link)
     (:gen-class)
     (:require [clj-http.client :as http])))
+
+(defn generate-global-vars
+  "Generates global variables that are used throughout the namespace"
+  [root-url service-path]
+  `[(def base-url ~(str root-url service-path))])
 
 (defn split-required-params
   "Returns a vector of two maps: first with the required params, second with the optional"

(defn generate-function-name
  "Generates a symbol in the form of 'verb-resource', from a method map."
  [method]
  (let [[_ resource-name method-name] (s/split (:id method) #"\.")]
    (-> (str method-name "-" resource-name)
        ->kebab-case-symbol)))


                              keys
                              (map name))))

(defn generate-request
  "Generates the request map to be passed to the http library.
  NB: uses the `base-url` symbol, it should be generated in the ns including the method."
  [method]
  {:method (-> method :httpMethod str/lower-case keyword)
   :url `(str base-url ~@(generate-path method))})

(defn generate-function-from-method
  [method]
  `(defn ~(generate-function-name method)
     ~(generate-docs method)
     ~(generate-args method)
     (http/request ~(generate-request method))))

(defn generate-ns-file
  "Given a service model, generates a clojure namespace with the implementation
  of all the API methods as functions, and writes it to file."
  [{:keys [name version description documentationLink rootUrl servicePath] :as model}]
  (let [symbols->str #(-> %
                          (f/pprint {:width 100}) ;; Fipp pretty prints clojure code nicely
                          with-out-str)]
    (->> [[(generate-ns-sexp name version description documentationLink)]
          (generate-global-vars rootUrl servicePath)]
          ;;(mapv generate-function-from-method ;; TODO get all the methods)])))
         (apply concat) ;; <- this is for flattening the methods
         (mapv symbols->str)
         (str/join "\n\n"))))
