[Bug 29595] New: missing Content-Type / HTTP 415 check for POST requests to /api/v1/patrons
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=29595 Bug ID: 29595 Summary: missing Content-Type / HTTP 415 check for POST requests to /api/v1/patrons Change sponsored?: --- Product: Koha Version: unspecified Hardware: All OS: All Status: NEW Severity: trivial Priority: P5 - low Component: REST API Assignee: koha-bugs@lists.koha-community.org Reporter: divinity76@gmail.com if you send a POST request to /api/v1/patrons with the header Content-Type: application/x-www-form-urlencoded which is a default header for curl and libcurl with POST requests, by the way, then Koha will try to parse it as a JSON, which leads to questions like this https://stackoverflow.com/questions/68106741/post-koha-patrons-to-koha-lms-u... and responses like this ``` { //Here is missing some code. "errors": [{ "message": "Missing property.", "path": "/body/address" }, { "message": "Missing property.", "path": "/body/category_id" }, { "message": "Missing property.", "path": "/body/city" }, { "message": "Missing property.", "path": "/body/library_id" }, { "message": "Missing property.", "path": "/body/surname" }], "status": 400 } ``` while HTTP 400 is a pretty good response, the correct response for unsupported Content-Type is actually
HTTP/1.1 415 Unsupported Media Type
and the error message could be something like { "errors": [{ "message": "request body must be application/json" }], ] -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=29595 Jonathan Druart <jonathan.druart+koha@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jonathan.druart+koha@gmail. | |com, tomascohen@gmail.com -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=29595 --- Comment #1 from Tomás Cohen Arazi <tomascohen@gmail.com> --- We rely on the Mojolicious::Plugin::OpenAPI library to validate requests based on our OpenAPI 2.0 spec. I'll try to check if there's a way to avoid this fallback behavior in the spec, but I haven't found anything yet. So, we depend on the library to take care of this situation. -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=29595 Jonathan Druart <jonathan.druart+koha@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- See Also| |https://bugs.koha-community | |.org/bugzilla3/show_bug.cgi | |?id=32637 -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=29595 --- Comment #2 from Jonathan Druart <jonathan.druart+koha@gmail.com> --- I am expecting this to be enough, but apparently the spec validation is not working here. diff --git a/api/v1/swagger/paths/patrons.yaml b/api/v1/swagger/paths/patrons.yaml index 1100a9fba96..493be03d507 100644 --- a/api/v1/swagger/paths/patrons.yaml +++ b/api/v1/swagger/paths/patrons.yaml @@ -6,6 +6,8 @@ tags: - patrons summary: List patrons + consumes: + - application/json produces: - application/json parameters: -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=29595 --- Comment #3 from Jonathan Druart <jonathan.druart+koha@gmail.com> --- (tried with GET instead of POST, but that's the same) -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=29595 --- Comment #4 from Jonathan Druart <jonathan.druart+koha@gmail.com> --- Is this https://github.com/jhthorsen/mojolicious-plugin-openapi/issues/209 ? -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=29595 --- Comment #5 from Jonathan Druart <jonathan.druart+koha@gmail.com> --- (In reply to Jonathan Druart from comment #4)
Is this https://github.com/jhthorsen/mojolicious-plugin-openapi/issues/209 ?
Well, almost... """ Please ask on IRC or open an issue if you found a bug, as this issue if for v3. (Sorry, but I’m unsure what you try to point out in the last comment) """ -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org