Bug 17032

Summary: REST API tests: Make sure Swagger object definition is up-to-date with database
Product: Koha Reporter: Lari Taskula <lari.taskula>
Component: Web servicesAssignee: Lari Taskula <lari.taskula>
Status: CLOSED FIXED QA Contact: Testopia <testopia>
Severity: enhancement    
Priority: P5 - low CC: benjamin.rokseth, jonathan.druart, kyle, mtj
Version: Main   
Hardware: All   
OS: All   
See Also: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=16825
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Bug Depends on: 13799, 13903, 17041, 17042    
Bug Blocks: 17008, 17654    
Attachments: Bug 17032: Make sure Swagger object definition is up-to-date with Koha-object
Bug 17032: Make sure Swagger object definition is up-to-date with Koha-object
Bug 17032: Make sure Swagger object definition is up-to-date with Koha-object
Bug 17032: Make sure Swagger object definition is up-to-date with Koha-object
Bug 17032: Remove warning "keys on reference is experimental"
Bug 17032 [QA Followup] - Update path to swagger.json file

Description Lari Taskula 2016-08-02 16:33:07 UTC
If a Swagger object definition is based on some database table, the definition should be covered by tests to ensure that it is up-to-date with database.
Comment 1 Lari Taskula 2016-08-03 12:09:32 UTC Comment hidden (obsolete)
Comment 2 Jonathan Druart 2016-08-03 15:48:55 UTC
Comment on attachment 53936 [details] [review]
Bug 17032: Make sure Swagger object definition is up-to-date with Koha-object

Review of attachment 53936 [details] [review]:
-----------------------------------------------------------------

::: t/db_dependent/api/v1/swagger/definitions.t
@@ +72,5 @@
> +
> +    $name = "Koha::" . ucfirst $name;
> +
> +    return eval {
> +        Module::Load::load($name);

The correct way to do that is to use Module::Load::Conditional.
Comment 3 Lari Taskula 2016-08-03 16:05:24 UTC Comment hidden (obsolete)
Comment 4 Lari Taskula 2016-08-03 16:07:57 UTC
(In reply to Jonathan Druart from comment #2)
> The correct way to do that is to use Module::Load::Conditional.
As requested, patch above.

By the way, at the moment tests are failing, because patron.json is missing 2 properties and hold.json is missing one. Apply bugs Bug 17041 and Bug 17042 to run this cleanly (also sign-off for them will be appreciated :).
Comment 5 Benjamin Rokseth 2016-08-03 21:54:30 UTC Comment hidden (obsolete)
Comment 6 Benjamin Rokseth 2016-08-03 21:55:18 UTC
Works as intended! Good work!
Comment 7 Jonathan Druart 2016-08-05 10:24:59 UTC
Created attachment 54022 [details] [review]
Bug 17032: Make sure Swagger object definition is up-to-date with Koha-object

If a definition in api/v1/definitions/*.json has a corresponding Koha-object by
filename, compare properties of the definition and columns of the Koha-object
and ensure that all columns are defined inside properties of the definition.

To test:
1. Run t/db_dependent/api/v1/swagger/definitions.t
2. See that all of the tests pass. (If not, file a bug report to fix missing
   properties in the Swagger definition.)
3. Remove a property from api/v1/swagger/definitions/patron.json
4. Repeat step 1
5. See that test fails and lets you know that the property you just removed
   is missing from the definition.

Signed-off-by: Benjamin Rokseth <benjamin.rokseth@kul.oslo.kommune.no>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 8 Jonathan Druart 2016-08-05 10:25:03 UTC
Created attachment 54023 [details] [review]
Bug 17032: Remove warning "keys on reference is experimental"

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 9 Jonathan Druart 2016-08-05 10:26:20 UTC
Thanks Lari!
Comment 10 Lari Taskula 2016-08-09 11:19:28 UTC
In case this test doesn't always return the same result, and fails sometimes, you might be interested in this:

I applied many API-related patches on top of master and ran this test multiple times. I noticed it didn't always have the same result; Swagger2 wasn't always able to find the type of definition because for some reason $ref was left unresolved for that definition - but after updating to the latest versions of Swagger2 (0.83) and JSON::Validator (0.82), it now seems to work. Looks like the author of JSON::Validator just patched some issues regarding to resolving $refs.
Comment 11 Kyle M Hall 2016-09-09 13:59:37 UTC
Created attachment 55437 [details] [review]
Bug 17032 [QA Followup] - Update path to swagger.json file
Comment 12 Kyle M Hall 2016-09-09 14:04:47 UTC
Pushed to master for 16.11, thanks Lari, Jonathan!
Comment 13 Mason James 2016-12-14 11:25:02 UTC
Enhancement, skipping for 16.05.x