-
Notifications
You must be signed in to change notification settings - Fork 150
Untraceable error with Swagger UI for GET method that requires a body. #251
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
Comments
Upon closer inspection this appears to be due to the fact that, for GET calls from the Swagger UI, the body is not actually sent in the request to the server. Which is why the error referring to something (presumably the body of the request) is |
This tripped me last night with compojure-api 1.1.8. I was using Swagger as the API prototype test and couldn't figure why I was getting the error. Works from curl/httpie. |
Bug or "feature" is in Swagger UI, and they won't change this: swagger-api/swagger-ui#2136 Reason is that message-body on GET request is not supposed to have any effect on the response, so trying to use it is not a good idea:
https://tools.ietf.org/html/rfc2616#section-4.3
|
@Deraen thank for you the explanation on this! Sorry to raise the issue here, I should have thought to check on Swagger's issues for this before posting. As a passing thought, it could perhaps be beneficial to have some debug text on startup of compojure-api so that if there are GET's with body parameters so that users could be aware of this behavior. Regardless I appreciate the explanation and have made the appropriate changes in my project. |
Yeah, I agree that a warning should be a good idea. |
Actually while this no-body on GET behavior is recommended in the RFC for HTTP (I think), it is not universal, and I think a bit short sighted. Elastisearch uses the body on get request to good effect. They point out that REST gives poor granularity in selecting resources (individual item, or collection) and query params are space limited, poorly structured, and inherently part of the URL (sometimes intended and sometimes not). By allowing a GET request to send a query as a body, a much more regular language is possible for specifying views over collections of resources. Many new technologies are heading this way too, graph-ql, falcor, etc. Clients, especially mobile clients need to be able to send a lot of info as part of get requests, and often the URL is not part of it, as it is not the data they want in a users bookmark. While there is a separate verb for this function (SEARCH) it is very hard to find implementations that service this correctly as a GET with a body. The real issue here is the behavior of caching proxies. They do not generally allow this as an optimization. But I do not think API design should be limited by the implementation details of caching proxies. I will update the linked swagger case with my thoughts in case that has any effect. |
I believe compojure-api works correctly here as it allows bodys with |
Verified for:
[org.clojure/clojure "1.8.0"]
[compojure "1.5.1"]
[ring/ring-defaults "0.2.1"]
[metosin/compojure-api "1.1.8"]
and[metosin/compojure-api "1.1.7"]
lein ring server-headless
Issue
A method declared as GET which only takes a body fails, such as this one:
fails without a traceable explanation on the server console output. The Swagger UI only says:
This appears to be related to the GET method as changing this to a POST fixes this problem.
Also, this issue doesn't occur when using curl, as the following succeeds with the appropriate response:
Regardless though the failure from the Swagger UI still indicates an issue with the library and, with no other debug text, left me to twiddle around with all other aspects of my application for a few hours before finding out what I have reported here.
Let me know if any further information is needed!
Cheers,
codeape
The text was updated successfully, but these errors were encountered: