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-using-php-curl/70155185#70155185 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" }], ]
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.
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:
(tried with GET instead of POST, but that's the same)
Is this https://github.com/jhthorsen/mojolicious-plugin-openapi/issues/209 ?
(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) """