https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44035
--- Comment #1 from Martin Renvoize (ashimema) <[email protected]> --- Created attachment 211065 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=211065&action=edit Bug 44035: Negotiate request and response body formats in the OpenAPI helpers Bug 37762 made Koha::REST::V1 rewrite every request body sent as application/xml into JSON in an around_action hook, and every application/xml response from JSON back to XML in an after_dispatch hook. They applied to all routes regardless of what the route declared, which destroyed the body for plugins with a native XML protocol (NCIP), and bug 43460 had to add an x-koha-raw-payload spec extension to opt out. Mojolicious::Plugin::OpenAPI already checks Content-Type against consumes and Accept against produces, but only knows how to read and write JSON. This adds Koha::REST::Plugin::Payload, which wraps its openapi.parse_request_body and openapi.build_response_body helpers with a table of codecs keyed by media type (JSON and XML to start with): * the request body is decoded with the codec for its content type and that is what gets validated against the body schema. The request itself is never modified. * a structure rendered with render( openapi => ... ) is encoded with the codec for the type negotiated from Accept and produces. Controllers no longer care which format was used. They call $c->payload for the request as a structure and render( openapi => $structure ) for the response. $c->payload is the structure that was validated, coerced to the types the schema declares, whichever format it arrived in. It deliberately does not rely on $c->validation->output, which we moved away from in bugs 33556, 40417 and 40424 as the OpenAPI plugin does not keep it stable. What a route does is driven by its spec: declare the body as a string to get the XML untouched, or as an object to get a structure. x-koha-raw-payload is no longer needed and is removed. The ISO18626 controller reads $c->payload instead of decoding the rewritten request body. To test: 1. prove t/db_dependent/Koha/REST/V1.t \ t/db_dependent/Koha/REST/Plugin/PluginRoutes.t \ t/db_dependent/api/v1/iso18626/ Co-Authored-By: Claude Sonnet 5.5 <[email protected]> -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes. _______________________________________________ Koha-bugs mailing list -- [email protected] To unsubscribe send an email to [email protected] website : http://www.koha-community.org/ git : http://git.koha-community.org/ bugs : http://bugs.koha-community.org/
