From 988de0b96e094affbf772fc1b012c510eeb9a1fd Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 5 May 2019 09:21:57 +0200 Subject: [PATCH] Updated edit short URL endpoint to be used with patch instead of put --- .../paths/v1_short-urls_{shortCode}.json | 91 ++++++++++++++++++- docs/swagger/swagger.json | 4 +- .../Action/ShortUrl/EditShortUrlAction.php | 2 +- .../src/Middleware/CrossDomainMiddleware.php | 2 +- 4 files changed, 94 insertions(+), 5 deletions(-) diff --git a/docs/swagger/paths/v1_short-urls_{shortCode}.json b/docs/swagger/paths/v1_short-urls_{shortCode}.json index 778d0fb1..c312db8a 100644 --- a/docs/swagger/paths/v1_short-urls_{shortCode}.json +++ b/docs/swagger/paths/v1_short-urls_{shortCode}.json @@ -81,7 +81,7 @@ } }, - "put": { + "patch": { "operationId": "editShortUrl", "tags": [ "Short URLs" @@ -169,6 +169,95 @@ } }, + "put": { + "deprecated": true, + "operationId": "editShortUrlPut", + "tags": [ + "Short URLs" + ], + "summary": "[DEPRECATED] Edit short URL", + "description": "**[DEPRECATED]** Use [editShortUrl](#/Short_URLs/getShortUrl) instead", + "parameters": [ + { + "name": "shortCode", + "in": "path", + "description": "The short code to edit.", + "required": true, + "schema": { + "type": "string" + } + } + ], + "requestBody": { + "description": "Request body.", + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "validSince": { + "description": "The date (in ISO-8601 format) from which this short code will be valid", + "type": "string" + }, + "validUntil": { + "description": "The date (in ISO-8601 format) until which this short code will be valid", + "type": "string" + }, + "maxVisits": { + "description": "The maximum number of allowed visits for this short code", + "type": "number" + } + } + } + } + } + }, + "security": [ + { + "ApiKey": [] + }, + { + "Bearer": [] + } + ], + "responses": { + "204": { + "description": "The short code has been properly updated." + }, + "400": { + "description": "Provided meta arguments are invalid.", + "content": { + "application/json": { + "schema": { + "$ref": "../definitions/Error.json" + } + } + } + }, + "404": { + "description": "No short URL was found for provided short code.", + "content": { + "application/json": { + "schema": { + "$ref": "../definitions/Error.json" + } + } + } + }, + "500": { + "description": "Unexpected error.", + "content": { + "application/json": { + "schema": { + "$ref": "../definitions/Error.json" + } + } + } + } + } + }, + "delete": { "operationId": "deleteShortUrl", "tags": [ diff --git a/docs/swagger/swagger.json b/docs/swagger/swagger.json index 8f996886..6dd3ff8f 100644 --- a/docs/swagger/swagger.json +++ b/docs/swagger/swagger.json @@ -35,7 +35,7 @@ "name": "X-Api-Key" }, "Bearer": { - "description": "**[Deprecated]** The JWT identifying a previously authenticated API key", + "description": "**[DEPRECATED]** The JWT identifying a previously authenticated API key", "type": "http", "scheme": "bearer", "bearerFormat": "JWT" @@ -66,7 +66,7 @@ }, { "name": "Authentication", - "description": "**[Deprecated]** Authentication-related endpoints" + "description": "**[DEPRECATED]** Authentication-related endpoints" } ], diff --git a/module/Rest/src/Action/ShortUrl/EditShortUrlAction.php b/module/Rest/src/Action/ShortUrl/EditShortUrlAction.php index bd8a8f36..b7bc54ab 100644 --- a/module/Rest/src/Action/ShortUrl/EditShortUrlAction.php +++ b/module/Rest/src/Action/ShortUrl/EditShortUrlAction.php @@ -19,7 +19,7 @@ use function sprintf; class EditShortUrlAction extends AbstractRestAction { protected const ROUTE_PATH = '/short-urls/{shortCode}'; - protected const ROUTE_ALLOWED_METHODS = [self::METHOD_PUT]; + protected const ROUTE_ALLOWED_METHODS = [self::METHOD_PATCH, self::METHOD_PUT]; /** @var ShortUrlServiceInterface */ private $shortUrlService; diff --git a/module/Rest/src/Middleware/CrossDomainMiddleware.php b/module/Rest/src/Middleware/CrossDomainMiddleware.php index b6cead2e..75024b62 100644 --- a/module/Rest/src/Middleware/CrossDomainMiddleware.php +++ b/module/Rest/src/Middleware/CrossDomainMiddleware.php @@ -44,7 +44,7 @@ class CrossDomainMiddleware implements MiddlewareInterface, RequestMethodInterfa // Add OPTIONS-specific headers foreach ([ - 'Access-Control-Allow-Methods' => 'GET,POST,PUT,DELETE,OPTIONS', // TODO Should be dynamic + 'Access-Control-Allow-Methods' => 'GET,POST,PUT,PATCH,DELETE,OPTIONS', // TODO Should be dynamic // 'Access-Control-Allow-Methods' => $response->getHeaderLine('Allow'), 'Access-Control-Max-Age' => '1000', 'Access-Control-Allow-Headers' => $request->getHeaderLine('Access-Control-Request-Headers'),