Tevo45 / juniper

A macro-based swagger binding generator for Common Lisp
MIT License
2 stars 2 forks source link

Multiple fixes & additions #5

Open jmeissen opened 1 year ago

jmeissen commented 1 year ago

Hello,

Nice little macro you have here. I've had to use it for a swagger spec, and it worked pretty well. Except I needed some stuff in there as well. So I decided to add these & also fix some of the FIXME comments.

Apply whatever you want from it.

Fixes

The JSON assumption & body response mapping

Drakma has a builtin variable *text-content-types* which says what body content is definitely text. So since drakma automatically maps the response body to characters based on the content type header, I've added a let-binding after the generated URL which overrides the default drakma:*text-content-types* to ensure correct behavior for json decoding which comes after. So leaving the default behavior the same, while the assumed json body is dropped. The generated function now also returns the string/byte-array when the content type header is not json as its mime subtype.

base-path to endpoint

Idk if you noticed this, but the parameters for the generated functions were applied to the base-path, not to the endpoint, which seems erroneous? So I put that fix in a separate commit as well.

In my case at least I got an error, because the endpoints included the path variables, not the basepath...

Additions

default-headers keyword

The keyword allows to add in :additional-headers some default headers. The headers will be overwritten by headers when applicable. I needed to add some custom authentication headers, so I added this one.

Optional export keyword

Setting the keyword to t automatically adds an export statement for the function symbol. Defaults to nil, so it does not mess with the existing behavior. I wanted a separate package with exported function symbols, so I added this.

Thanks in advance for reviewing the PR.