forked from kat-co/openapi2cl
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.lisp
43 lines (33 loc) · 1.49 KB
/
example.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
;; Load the expressions in this file, interactively, one by one.
(require :openapi2cl)
;; Define a function to generate our api client code:
(defun generate-petstore-api ()
(let ((*print-case* :downcase))
(openapi2cl:with-directory-generate-files
(merge-pathnames "*.json" (asdf:system-relative-pathname :openapi2cl "example/"))
(princ-to-string (asdf:system-relative-pathname :openapi2cl "example/"))
'petstore
:export t))
t)
;; Generate api client code:
(generate-petstore-api)
;; Load the generated api client code:
(load (asdf:system-relative-pathname :openapi2cl "example/petstore.v3.lisp"))
;; Define a function for doing HTTP requests:
(defun make-http-request (uri &key method additional-headers content-type content parameters multipart-params)
(yason:parse
(drakma:http-request uri
:method method
:additional-headers additional-headers
:content-type content-type
:parameters (append parameters multipart-params)
:content content
:want-stream t)))
;; Create an instance of our api client passing our MAKE-HTTP-REQUEST function:
(defparameter *petstore-client*
(make-instance 'petstore/petstore.v3:petstore.v3
:consumes-media-type "application/json"
:http-request #'make-http-request))
;; Test the api client:
(petstore/petstore.v3:find-pets-by-status *petstore-client* "pending")
(petstore/petstore.v3:find-pets-by-tags *petstore-client* "pet")