This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
Is there a way to get compojure-swagger to handle single value form parameters more gracefully when having only a single value?
I am using
:form-params [inputs :- [String] outputs :- [String] name :- String]
but it is only working, iff I include more than one parameter for inputs and more than one for outputs.Hmh, not too familiar with form-params but I guess they are encoded like query params, thus collection with one item is the same as single input
It would need one item -> collection coercer for form-params
This is how it's done for query params: https://github.com/metosin/ring-swagger/blob/master/src/ring/swagger/coerce.clj#L99-L108
Compojure-api should already use query-schema-coercion-matcher
for :form-params
: https://github.com/metosin/ring-swagger/blob/master/src/ring/swagger/coerce.clj#L99-L108 https://github.com/metosin/compojure-api/blob/82e46fd801608dbcb457a763c7e629e8d859aa8b/src/compojure/api/meta.clj#L232
@trieloff: Which compojure-api version are you using?
Hmm should work
The default coercion should already be wrapping single items in collections for query and form params
Okay, looks like collections are not supported in url-encoded form-data currently
At least for swagger-ui generated requests
In url-encoded form-data collections are encoded as comma separated string
I don't remember exactly why it was commented out, but probably because there should be some way to control when it's used
As a quick fix you can set up custom coercer using split-params-matcher
Or use JSON params
And perhaps if you set swagger to use :collectionFormat multi
it will generate requests with separate properties for each value
?name=help&inputs=A1&outputs=A2&inputs=B1&outputs=B2
works fine, but don’t leave one out
According to Swagger-spec this should work: :form-params [x :- (field [String] {:collectionFormat "multi"})]
and it generates valid swagger.json, but looks like Swagger-ui doesn't care about that
For now, I’m building the requests manually in curl – Swagger UI is secondary, but even then it fails unless I really have more than one value
Do you have a reason to use either form or query params?
body params work fine
With query-params, ?inputs=a
and ?inputs=a&inputs=b
should both give a vector
How to I use field
https://clojurians.slack.com/archives/ring-swagger/p1444590854000049
I can’t find it in the docs and the compiler is complaining that it can’t find it either.
It's in ring.swagger.json-schema
That seems to have helped. @juhoteperi – thanks for the help. I should have started with the version bump.
Oh right, now that I check changelogs, 0.23 entry mentions this