Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple fixes & additions #5

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix auto-conversion byte->char & fix json assumption
  • Loading branch information
jmeissen committed Mar 17, 2023
commit 87f0f464872a12ce0d0ce9e199ed64f4500f48c8
45 changes: 22 additions & 23 deletions juniper.lisp
Original file line number Diff line number Diff line change
@@ -102,7 +102,7 @@
; FIXME barely readable mess
(defun function-for-op (op &aux required optional assistance-code)
(with-gensyms (url query-params headers body uses-form proto host port base-path
endpoint response response-string stream)
endpoint response response-string status-code response-headers)
(labels ((parse-parameter (param)
(let* ((name (field :|name| param))
(symbolic-name (lisp-symbol name))
@@ -160,28 +160,27 @@
,headers ,query-params ,body ,uses-form))
,(field :|summary| (cdr op))
,@assistance-code
(let* ((,url (build-url ,proto ,host ,port ,base-path ,endpoint))
(,response
(apply #'drakma:http-request ,url
:method ,(intern (string-upcase
(string (car op)))
'keyword)
:parameters ,query-params
:additional-headers ,headers
:form-data ,uses-form
:content-type ,*content-type*
:content ,body
:accept ,*accept-header*
juniper:*drakma-extra-args*))
(,response-string
; FIXME extract encoding from response headers?
(flexi-streams:octets-to-string ,response
:external-format :utf-8)))
(unless (zerop (length ,response-string))
; FIXME don't assume json
; FIXME there's likely a way to get a stream from the connection directly
(with-input-from-string (,stream ,response-string)
(json:decode-json ,stream))))))))
(let ((,url (build-url ,proto ,host ,port ,base-path ,endpoint))
(drakma:*text-content-types* '(("text" . nil)
(nil . "json"))))
;; FIXME unused variable `status-code'
(multiple-value-setq (,response-string ,status-code ,response-headers)
(apply #'drakma:http-request ,url
:method ,(intern (string-upcase
(string (car op)))
'keyword)
:parameters ,query-params
:additional-headers ,headers
:form-data ,uses-form
:content-type ,*content-type*
:content ,body
:accept ,*accept-header*
juniper:*drakma-extra-args*))
(if (not (zerop (length ,response-string)))
(when (string= (nth-value 1 (drakma:get-content-type ,response-headers))
"json")
(json:decode-json-from-string ,response-string))
,response-string))))))

(defun swagger-path-bindings (path &aux (name (car path)) (ops (cdr path)))
(let* ((*endpoint* (string name))