Bug 25048

Summary: Successful resource deletion should return 204
Product: Koha Reporter: Tomás Cohen Arazi (tcohen) <tomascohen>
Component: REST APIAssignee: Tomás Cohen Arazi (tcohen) <tomascohen>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P5 - low CC: 1joynelson, jonathan.druart, kyle, martin.renvoize
Version: Main   
Hardware: All   
OS: All   
URL: https://wiki.koha-community.org/wiki/Coding_Guidelines_-_API#SWAGGER3.2.4_DELETE
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
20.05.00
Circulation function:
Bug Depends on: 25032    
Bug Blocks:    
Attachments: Bug 25048: Regression tests
Bug 25048: Make successful resource deletion return 204
Bug 25048: Regression tests
Bug 25048: Make successful resource deletion return 204
Bug 25048: Regression tests
Bug 25048: Make successful resource deletion return 204

Description Tomás Cohen Arazi (tcohen) 2020-04-02 18:25:16 UTC
As stated in our coding guidelines for the API [1], when deleting a resource, the API should return a 204 instead of the 200 some do now.

[1] https://wiki.koha-community.org/wiki/Coding_Guidelines_-_API#SWAGGER3.2.4_DELETE
Comment 1 Tomás Cohen Arazi (tcohen) 2020-04-02 18:30:44 UTC
References for people reviewing this:

- RESTful DELETE: https://restfulapi.net/http-methods/#delete
- OpenAPI handling on 204: https://swagger.io/docs/specification/2-0/describing-responses/

In the latter search for 'Empty Response Body'.
Comment 2 Tomás Cohen Arazi (tcohen) 2020-04-02 21:51:00 UTC
Created attachment 102332 [details] [review]
Bug 25048: Regression tests

This patch adds regression tests for the response bodies and statuses on
DELETE actions against existing API routes. This is just enforcing the
existing (voted) Coding guidelines for the API (tm).

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/api/v1/*.t
=> FAIL: Several routes have problems
Comment 3 Tomás Cohen Arazi (tcohen) 2020-04-02 21:51:05 UTC
Created attachment 102333 [details] [review]
Bug 25048: Make successful resource deletion return 204

This patch adapts the spec and the controllers so existing routes return
204 and an empty response body when a successful deletion happens.

Right now we have a coding guideline but haven't adapted the existing
routes.

To test:
1. Apply the regression tests patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/api/v1/*.t
=> FAIL: Some tests fail
3. Apply this patch
4. Repeat 2.
=> SUCCESS: Tests pass!
5. Sign off :-D
Comment 4 Jonathan Druart 2020-04-03 08:52:08 UTC
+      ->status_is(204, 'SWAGGER3.2.4')
+      ->content_is('', 'SWAGGER3.3.4');

Can you explain that?
Comment 5 Tomás Cohen Arazi (tcohen) 2020-04-03 11:41:30 UTC
(In reply to Jonathan Druart from comment #4)
> +      ->status_is(204, 'SWAGGER3.2.4')
> +      ->content_is('', 'SWAGGER3.3.4');
> 
> Can you explain that?

That refers to the API coding guidelines pointed by the bug. This is something already present in some tests.
Comment 6 David Nind 2020-04-04 21:50:58 UTC
Created attachment 102403 [details] [review]
Bug 25048: Regression tests

This patch adds regression tests for the response bodies and statuses on
DELETE actions against existing API routes. This is just enforcing the
existing (voted) Coding guidelines for the API (tm).

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/api/v1/*.t
=> FAIL: Several routes have problems

Signed-off-by: David Nind <david@davidnind.com>
Comment 7 David Nind 2020-04-04 21:51:01 UTC
Created attachment 102404 [details] [review]
Bug 25048: Make successful resource deletion return 204

This patch adapts the spec and the controllers so existing routes return
204 and an empty response body when a successful deletion happens.

Right now we have a coding guideline but haven't adapted the existing
routes.

To test:
1. Apply the regression tests patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/api/v1/*.t
=> FAIL: Some tests fail
3. Apply this patch
4. Repeat 2.
=> SUCCESS: Tests pass!
5. Sign off :-D

Signed-off-by: David Nind <david@davidnind.com>
Comment 8 Katrin Fischer 2020-04-12 19:21:14 UTC
Dependency is not signed off yet - moving to BLOCKED. Please unlock when bug 25032 is ready.
Comment 9 Tomás Cohen Arazi (tcohen) 2020-04-24 12:44:40 UTC
(In reply to Katrin Fischer from comment #8)
> Dependency is not signed off yet - moving to BLOCKED. Please unlock when bug
> 25032 is ready.

Dependency unlocked.
Comment 10 Kyle M Hall (khall) 2020-04-29 13:59:58 UTC
Created attachment 103943 [details] [review]
Bug 25048: Regression tests

This patch adds regression tests for the response bodies and statuses on
DELETE actions against existing API routes. This is just enforcing the
existing (voted) Coding guidelines for the API (tm).

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/api/v1/*.t
=> FAIL: Several routes have problems

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 11 Kyle M Hall (khall) 2020-04-29 14:00:19 UTC
Created attachment 103944 [details] [review]
Bug 25048: Make successful resource deletion return 204

This patch adapts the spec and the controllers so existing routes return
204 and an empty response body when a successful deletion happens.

Right now we have a coding guideline but haven't adapted the existing
routes.

To test:
1. Apply the regression tests patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/api/v1/*.t
=> FAIL: Some tests fail
3. Apply this patch
4. Repeat 2.
=> SUCCESS: Tests pass!
5. Sign off :-D

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 12 Martin Renvoize (ashimema) 2020-04-29 15:25:17 UTC
Nice work everyone!

Pushed to master for 20.05
Comment 13 Joy Nelson 2020-05-08 22:20:37 UTC
missing dependencies - not backported