[Bug 33503] New: Plugin OpenAPI2.0 specification schema fragments are not resolved. Merge full schema definitions.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33503 Bug ID: 33503 Summary: Plugin OpenAPI2.0 specification schema fragments are not resolved. Merge full schema definitions. Change sponsored?: --- Product: Koha Version: master Hardware: All OS: All Status: NEW Severity: enhancement Priority: P5 - low Component: Plugin architecture Assignee: koha-bugs@lists.koha-community.org Reporter: olli-antti.kivilahti@hypernova.fi QA Contact: testopia@bugs.koha-community.org Koha::REST::Plugin::PluginRoutes.pm simply injects a plugin's OpenAPI2.0 route definitions into the /paths -object. Possibly after Bug 30194, dereferencing OpenAPI2.0 schema fragments/components has started to fail. This plugin: https://github.com/Hypernova-Oy/koha-plugin-self-service/releases/tag/v1.0.1... used to get it's REST API paths injected and dereferenced/bundled correctly, for Koha versions 22.05 and before, but in the new Koha version the same schema definitions no longer work. This patch adds a new plugin hook, api_spec which injects a full OpenAPI2.0 compatible schema into the full Koha schema, avoiding to overwrite any existing definitions/parameters/info/paths/etc. This way we maintain backwards compatibility with existing plugins, which are not broken, and maintain updated plugins' ability to use complex schemas. We need to inject full schema definitions, because of the way how the new OpenAPI validator does dereferencing, by creating /parameters and /definitions -objects inside the plugin's OpenAPI schema object. The api_route()-plugin hook then proceeds to strip away only the paths/routes and loses the internal data structure references to the schema fragments/components. -- 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=33503 Olli-Antti Kivilahti <olli-antti.kivilahti@hypernova.fi> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |ASSIGNED CC| |olli-antti.kivilahti@hypern | |ova.fi Assignee|koha-bugs@lists.koha-commun |olli-antti.kivilahti@hypern |ity.org |ova.fi --- Comment #1 from Olli-Antti Kivilahti <olli-antti.kivilahti@hypernova.fi> --- Created attachment 149520 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=149520&action=edit Bug 33503 - Plugin OpenAPI2.0 specification schema fragments are not resolved. Merge full schema definitions. Bug 33503 - Plugin OpenAPI2.0 specification schema fragments are not resolved. Merge full schema definitions. Koha::REST::Plugin::PluginRoutes.pm simply injects a plugin's OpenAPI2.0 route definitions into the /paths -object. Possibly after Bug 30194, dereferencing OpenAPI2.0 schema fragments/components has started to fail. This plugin: https://github.com/Hypernova-Oy/koha-plugin-self-service/releases/tag/v1.0.1... used to get it's REST API paths injected and dereferenced/bundled correctly, for Koha versions 22.05 and before, but in the new Koha version the same schema definitions no longer work. This patch adds a new plugin hook, api_spec which injects a full OpenAPI2.0 compatible schema into the full Koha schema, avoiding to overwrite any existing definitions/parameters/info/paths/etc. This way we maintain backwards compatibility with existing plugins, which are not broken, and maintain updated plugins' ability to use complex schemas. We need to inject full schema definitions, because of the way how the new OpenAPI validator does dereferencing, by creating /parameters and /definitions -objects inside the plugin's OpenAPI schema object. The api_route()-plugin hook then proceeds to strip away only the paths/routes and loses the internal data structure references to the schema fragments/components. -- 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=33503 Olli-Antti Kivilahti <olli-antti.kivilahti@hypernova.fi> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #149520|0 |1 is obsolete| | --- Comment #2 from Olli-Antti Kivilahti <olli-antti.kivilahti@hypernova.fi> --- Created attachment 149533 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=149533&action=edit Bug 33503 - Plugin OpenAPI2.0 specification schema fragments are not resolved. Merge full schema definitions. Koha::REST::Plugin::PluginRoutes.pm simply injects a plugin's OpenAPI2.0 route definitions into the /paths -object. Possibly after Bug 30194, dereferencing OpenAPI2.0 schema fragments/components has started to fail. This plugin: https://github.com/Hypernova-Oy/koha-plugin-self-service/releases/tag/v1.0.1... used to get it's REST API paths injected and dereferenced/bundled correctly, for Koha versions 22.05 and before, but in the new Koha version the same schema definitions no longer work. This patch adds a new plugin hook, api_spec which injects a full OpenAPI2.0 compatible schema into the full Koha schema, avoiding to overwrite any existing definitions/parameters/info/paths/etc. This way we maintain backwards compatibility with existing plugins, which are not broken, and maintain updated plugins' ability to use complex schemas. We need to inject full schema definitions, because of the way how the new OpenAPI validator does dereferencing, by creating /parameters and /definitions -objects inside the plugin's OpenAPI schema object. The api_route()-plugin hook then proceeds to strip away only the paths/routes and loses the internal data structure references to the schema fragments/components. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33503 --- Comment #3 from Olli-Antti Kivilahti <olli-antti.kivilahti@hypernova.fi> ---
From the plugin, one can implement this hook with this code fragment:
sub api_spec { my ( $plugin, $args ) = @_; return JSON::Validator::Schema::OpenAPIv2->new; my $schema2 = JSON::Validator::Schema::OpenAPIv2->new; $schema2->resolve($plugin->mbf_dir() . "/openapi.yaml"); return $schema2->bundle->data; #Bundle merges the external/internal/local references in the plugin schema path. } -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33503 Ere Maijala <ere.maijala@helsinki.fi> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |ere.maijala@helsinki.fi -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33503 David Cook <dcook@prosentient.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |dcook@prosentient.com.au -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33503 Olli-Antti Kivilahti <olli-antti.kivilahti@hypernova.fi> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|ASSIGNED |Needs Signoff -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33503 Victor Grousset/tuxayo <victor@tuxayo.net> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Needs Signoff |Failed QA CC| |victor@tuxayo.net --- Comment #4 from Victor Grousset/tuxayo <victor@tuxayo.net> --- Test plan (asked in chat): 1. prove t/db_dependent/Koha/REST/Plugin/PluginRoutes.t Turns out it fails ^^" ``` t/db_dependent/Koha/REST/Plugin/PluginRoutes.t .. 2/4 # Looks like you planned 16 tests but ran 17. t/db_dependent/Koha/REST/Plugin/PluginRoutes.t .. 3/4 # Failed test 'Permissions and access to plugin routes tests' # at t/db_dependent/Koha/REST/Plugin/PluginRoutes.t line 206. t/db_dependent/Koha/REST/Plugin/PluginRoutes.t .. 4/4 # Looks like you failed 1 test of 4. t/db_dependent/Koha/REST/Plugin/PluginRoutes.t .. Dubious, test returned 1 (wstat 256, 0x100) Failed 1/4 subtests ``` -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33503 Olli-Antti Kivilahti <olli-antti.kivilahti@hypernova.fi> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #149533|0 |1 is obsolete| | --- Comment #5 from Olli-Antti Kivilahti <olli-antti.kivilahti@hypernova.fi> --- Created attachment 156304 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=156304&action=edit Bug 33503 - Plugin OpenAPI2.0 specification schema fragments are not resolved. Merge full schema definitions. Koha::REST::Plugin::PluginRoutes.pm simply injects a plugin's OpenAPI2.0 route definitions into the /paths -object. Possibly after Bug 30194, dereferencing OpenAPI2.0 schema fragments/components has started to fail. This plugin: https://github.com/Hypernova-Oy/koha-plugin-self-service/releases/tag/v1.0.1... used to get it's REST API paths injected and dereferenced/bundled correctly, for Koha versions 22.05 and before, but in the new Koha version the same schema definitions no longer work. This patch adds a new plugin hook, api_spec which injects a full OpenAPI2.0 compatible schema into the full Koha schema, avoiding to overwrite any existing definitions/parameters/info/paths/etc. This way we maintain backwards compatibility with existing plugins, which are not broken, and maintain updated plugins' ability to use complex schemas. We need to inject full schema definitions, because of the way how the new OpenAPI validator does dereferencing, by creating /parameters and /definitions -objects inside the plugin's OpenAPI schema object. The api_route()-plugin hook then proceeds to strip away only the paths/routes and loses the internal data structure references to the schema fragments/components. If the api_spec is defined in the plugin, the api_routes-hook is never called. TEST PLAN: a) Run the modified test. or b) Install this plugin, and observe the routes are not loaded into the REST API. https://github.com/Hypernova-Oy/koha-plugin-self-service/releases/tag/v1.0.1... b1) Deploying this patch doesnt fix the plugin, as the whole subsystem to load OpenAPI2 spec has changed, and the plugins updated with workarounds. Plugins can be updated to support api_spec once it has been pushed. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33503 Olli-Antti Kivilahti <olli-antti.kivilahti@hypernova.fi> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Failed QA |Needs Signoff -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33503 Victor Grousset/tuxayo <victor@tuxayo.net> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #156304|0 |1 is obsolete| | --- Comment #6 from Victor Grousset/tuxayo <victor@tuxayo.net> --- Created attachment 156312 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=156312&action=edit Bug 33503 - Plugin OpenAPI2.0 specification schema fragments are not resolved. Merge full schema definitions. Koha::REST::Plugin::PluginRoutes.pm simply injects a plugin's OpenAPI2.0 route definitions into the /paths -object. Possibly after Bug 30194, dereferencing OpenAPI2.0 schema fragments/components has started to fail. This plugin: https://github.com/Hypernova-Oy/koha-plugin-self-service/releases/tag/v1.0.1... used to get it's REST API paths injected and dereferenced/bundled correctly, for Koha versions 22.05 and before, but in the new Koha version the same schema definitions no longer work. This patch adds a new plugin hook, api_spec which injects a full OpenAPI2.0 compatible schema into the full Koha schema, avoiding to overwrite any existing definitions/parameters/info/paths/etc. This way we maintain backwards compatibility with existing plugins, which are not broken, and maintain updated plugins' ability to use complex schemas. We need to inject full schema definitions, because of the way how the new OpenAPI validator does dereferencing, by creating /parameters and /definitions -objects inside the plugin's OpenAPI schema object. The api_route()-plugin hook then proceeds to strip away only the paths/routes and loses the internal data structure references to the schema fragments/components. If the api_spec is defined in the plugin, the api_routes-hook is never called. TEST PLAN: a) Run the modified test. or b) Install this plugin, and observe the routes are not loaded into the REST API. https://github.com/Hypernova-Oy/koha-plugin-self-service/releases/tag/v1.0.1... b1) Deploying this patch doesnt fix the plugin, as the whole subsystem to load OpenAPI2 spec has changed, and the plugins updated with workarounds. Plugins can be updated to support api_spec once it has been pushed. Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33503 Victor Grousset/tuxayo <victor@tuxayo.net> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Needs Signoff |Signed Off --- Comment #7 from Victor Grousset/tuxayo <victor@tuxayo.net> --- So it was just a number-of-tests problem?! :o Sorry, I could have fixed it. I was confused by «Failed test 'Permissions and access to plugin routes tests'» Anyway, test pass so signed-off. I gave a go at the alternative: «Install this plugin, and observe the routes are not loaded into the REST API» How? -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33503 --- Comment #8 from Olli-Antti Kivilahti <olli-antti.kivilahti@hypernova.fi> --- (In reply to Victor Grousset/tuxayo from comment #7)
So it was just a number-of-tests problem?! :o Sorry, I could have fixed it. I was confused by «Failed test 'Permissions and access to plugin routes tests'»
Anyway, test pass so signed-off.
I gave a go at the alternative: «Install this plugin, and observe the routes are not loaded into the REST API» How?
Make a GET request to /api/v1/ and you can see the schema definition. The plugin's openapi-directory has the path definitions and you can see that the path definitions are not loaded in the aforementioned schema definition from /api/v1/ This is standard Koha-plugin development workflow and it is a bit difficult to test this if there is no previous experience with developing plugins with complex rest api schemas. You have to restart plack for the route definitions to take place. I appreciate the sign-off. Also the plugin loaded into the test case explains more briefly what is the exact case that is being tested. Most plugins just have the /paths defined in the OpenAPI schema and not very many different paths. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33503 --- Comment #9 from Victor Grousset/tuxayo <victor@tuxayo.net> ---
Install this plugin, and observe the routes are not loaded into the REST API [...] Make a GET request to /api/v1/ and you can see the schema definition.
Indeed, /api/v1/ content didn't chance with and without the patch + plugin (after restart_all) -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33503 Jonathan Druart <jonathan.druart+koha@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Signed Off |Failed QA CC| |jonathan.druart+koha@gmail. | |com --- Comment #10 from Jonathan Druart <jonathan.druart+koha@gmail.com> --- 1. QA failures WARN Koha/REST/Plugin/PluginRoutes.pm WARN tidiness The file is less tidy than before (bad/messy lines before: 28, now: 52) WARN t/db_dependent/Koha/REST/Plugin/PluginRoutes.t WARN tidiness The file is less tidy than before (bad/messy lines before: 30, now: 31) FAIL t/lib/plugins/Koha/Plugin/BundledApiSpec.pm FAIL pod coverage POD coverage was greater before, try perl -MPod::Coverage=PackageName -e666 WARN tidiness The file is less tidy than before (bad/messy lines before: 0, now: 2) OK t/lib/plugins/Koha/Plugin/BundledApiSpec/openapi.yaml Processing additional checks * Commit title does not start with 'Bug XXXXX: ' - 5b055c172d3 2. bundledass?.. 3. You are talking about a regression, did you bisect/investigate from where it could come? -- You are receiving this mail because: You are watching all bug changes.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org