Bug 17032 - REST API tests: Make sure Swagger object definition is up-to-date with database
Summary: REST API tests: Make sure Swagger object definition is up-to-date with database
Status: RESOLVED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Web services (show other bugs)
Version: master
Hardware: All All
: P5 - low enhancement (vote)
Assignee: Lari Taskula
QA Contact: Testopia
URL:
Whiteboard:
Keywords:
Depends on: 13799 13903 17041 17042
Blocks: 17008 17654
  Show dependency treegraph
 
Reported: 2016-08-02 16:33 UTC by Lari Taskula
Modified: 2017-06-14 22:18 UTC (History)
4 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Bot Control: ---
When did the bot last check this:
Who signed the patch off:
Text to go in the release notes:


Attachments
Bug 17032: Make sure Swagger object definition is up-to-date with Koha-object (4.33 KB, patch)
2016-08-03 12:09 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 17032: Make sure Swagger object definition is up-to-date with Koha-object (4.34 KB, patch)
2016-08-03 16:05 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 17032: Make sure Swagger object definition is up-to-date with Koha-object (4.41 KB, patch)
2016-08-03 21:54 UTC, Benjamin Rokseth
Details | Diff | Splinter Review
Bug 17032: Make sure Swagger object definition is up-to-date with Koha-object (4.48 KB, patch)
2016-08-05 10:24 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 17032: Remove warning "keys on reference is experimental" (1.17 KB, patch)
2016-08-05 10:25 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 17032 [QA Followup] - Update path to swagger.json file (1.08 KB, patch)
2016-09-09 13:59 UTC, Kyle M Hall
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
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