From e21f9dd1fbb13ebabbc695f62239c7e0b37871f9 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 2 Oct 2021 10:31:23 +0200 Subject: [PATCH] Added forwardQuery prop to the SHortUrl serialization --- docs/swagger/definitions/ShortUrl.json | 17 +++++++++++++++++ .../Transformer/ShortUrlDataTransformer.php | 1 + .../Mercure/MercureUpdatesGeneratorTest.php | 1 + .../Rest/test-api/Action/ListShortUrlsTest.php | 6 ++++++ .../Rest/test-api/Fixtures/ShortUrlsFixture.php | 10 +++++++--- 5 files changed, 32 insertions(+), 3 deletions(-) diff --git a/docs/swagger/definitions/ShortUrl.json b/docs/swagger/definitions/ShortUrl.json index b2ffd3f6..a5dee481 100644 --- a/docs/swagger/definitions/ShortUrl.json +++ b/docs/swagger/definitions/ShortUrl.json @@ -1,5 +1,18 @@ { "type": "object", + "required": [ + "shortCode", + "shortUrl", + "longUrl", + "dateCreated", + "visitsCount", + "tags", + "meta", + "domain", + "title", + "crawlable", + "forwardQuery" + ], "properties": { "shortCode": { "type": "string", @@ -45,6 +58,10 @@ "crawlable": { "type": "boolean", "description": "Tells if this URL will be included as 'Allow' in Shlink's robots.txt." + }, + "forwardQuery": { + "type": "boolean", + "description": "Tells if this URL will forward the query params to the long URL when visited, as explained in [the docs](https://shlink.io/documentation/some-features/#query-params-forwarding)." } } } diff --git a/module/Core/src/ShortUrl/Transformer/ShortUrlDataTransformer.php b/module/Core/src/ShortUrl/Transformer/ShortUrlDataTransformer.php index 61049626..554f9894 100644 --- a/module/Core/src/ShortUrl/Transformer/ShortUrlDataTransformer.php +++ b/module/Core/src/ShortUrl/Transformer/ShortUrlDataTransformer.php @@ -33,6 +33,7 @@ class ShortUrlDataTransformer implements DataTransformerInterface 'domain' => $shortUrl->getDomain(), 'title' => $shortUrl->title(), 'crawlable' => $shortUrl->crawlable(), + 'forwardQuery' => $shortUrl->forwardQuery(), ]; } diff --git a/module/Core/test/Mercure/MercureUpdatesGeneratorTest.php b/module/Core/test/Mercure/MercureUpdatesGeneratorTest.php index 86d1b3d5..14378b4f 100644 --- a/module/Core/test/Mercure/MercureUpdatesGeneratorTest.php +++ b/module/Core/test/Mercure/MercureUpdatesGeneratorTest.php @@ -60,6 +60,7 @@ class MercureUpdatesGeneratorTest extends TestCase 'domain' => null, 'title' => $title, 'crawlable' => false, + 'forwardQuery' => true, ], 'visit' => [ 'referer' => '', diff --git a/module/Rest/test-api/Action/ListShortUrlsTest.php b/module/Rest/test-api/Action/ListShortUrlsTest.php index 95d77dc6..fcc07719 100644 --- a/module/Rest/test-api/Action/ListShortUrlsTest.php +++ b/module/Rest/test-api/Action/ListShortUrlsTest.php @@ -27,6 +27,7 @@ class ListShortUrlsTest extends ApiTestCase 'domain' => null, 'title' => 'My cool title', 'crawlable' => true, + 'forwardQuery' => true, ]; private const SHORT_URL_DOCS = [ 'shortCode' => 'ghi789', @@ -43,6 +44,7 @@ class ListShortUrlsTest extends ApiTestCase 'domain' => null, 'title' => null, 'crawlable' => false, + 'forwardQuery' => true, ]; private const SHORT_URL_CUSTOM_SLUG_AND_DOMAIN = [ 'shortCode' => 'custom-with-domain', @@ -59,6 +61,7 @@ class ListShortUrlsTest extends ApiTestCase 'domain' => 'some-domain.com', 'title' => null, 'crawlable' => false, + 'forwardQuery' => true, ]; private const SHORT_URL_META = [ 'shortCode' => 'def456', @@ -77,6 +80,7 @@ class ListShortUrlsTest extends ApiTestCase 'domain' => null, 'title' => null, 'crawlable' => false, + 'forwardQuery' => true, ]; private const SHORT_URL_CUSTOM_SLUG = [ 'shortCode' => 'custom', @@ -93,6 +97,7 @@ class ListShortUrlsTest extends ApiTestCase 'domain' => null, 'title' => null, 'crawlable' => false, + 'forwardQuery' => false, ]; private const SHORT_URL_CUSTOM_DOMAIN = [ 'shortCode' => 'ghi789', @@ -111,6 +116,7 @@ class ListShortUrlsTest extends ApiTestCase 'domain' => 'example.com', 'title' => null, 'crawlable' => false, + 'forwardQuery' => true, ]; /** diff --git a/module/Rest/test-api/Fixtures/ShortUrlsFixture.php b/module/Rest/test-api/Fixtures/ShortUrlsFixture.php index ccc83525..9510f8ed 100644 --- a/module/Rest/test-api/Fixtures/ShortUrlsFixture.php +++ b/module/Rest/test-api/Fixtures/ShortUrlsFixture.php @@ -51,9 +51,13 @@ class ShortUrlsFixture extends AbstractFixture implements DependentFixtureInterf ]), $relationResolver), '2019-01-01 00:00:10'); $manager->persist($defShortUrl); - $customShortUrl = $this->setShortUrlDate(ShortUrl::fromMeta(ShortUrlMeta::fromRawData( - ['customSlug' => 'custom', 'maxVisits' => 2, 'apiKey' => $authorApiKey, 'longUrl' => 'https://shlink.io'], - )), '2019-01-01 00:00:20'); + $customShortUrl = $this->setShortUrlDate(ShortUrl::fromMeta(ShortUrlMeta::fromRawData([ + 'customSlug' => 'custom', + 'maxVisits' => 2, + 'apiKey' => $authorApiKey, + 'longUrl' => 'https://shlink.io', + 'forwardQuery' => false, + ])), '2019-01-01 00:00:20'); $manager->persist($customShortUrl); $ghiShortUrl = $this->setShortUrlDate(