Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create endpoint to list redirect rules for a specific short URL #2031

Merged
merged 4 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016-2023 Alejandro Celaya
Copyright (c) 2016-2024 Alejandro Celaya

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
12 changes: 7 additions & 5 deletions config/autoload/routes.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use function sprintf;

return (static function (): array {
$contentNegotiationMiddleware = Middleware\ShortUrl\CreateShortUrlContentNegotiationMiddleware::class;
$dropDomainMiddleware = Middleware\ShortUrl\DropDefaultDomainFromRequestMiddleware::class;
$overrideDomainMiddleware = Middleware\ShortUrl\OverrideDomainMiddleware::class;

Expand All @@ -32,9 +31,10 @@
...ConfigProvider::applyRoutesPrefix([
Action\HealthAction::getRouteDef(),

// Visits and rules routes must go first, as they have a more specific path, otherwise, when
// multi-segment slugs are enabled, routes with a less-specific path might match first

// Visits.
// These routes must go first, as they have a more specific path, otherwise, when multi-segment slugs
// are enabled, routes with a less-specific path might match first
Action\Visit\ShortUrlVisitsAction::getRouteDef([$dropDomainMiddleware]),
Action\ShortUrl\DeleteShortUrlVisitsAction::getRouteDef([$dropDomainMiddleware]),
Action\Visit\TagVisitsAction::getRouteDef(),
Expand All @@ -44,15 +44,17 @@
Action\Visit\DeleteOrphanVisitsAction::getRouteDef(),
Action\Visit\NonOrphanVisitsAction::getRouteDef(),

//Redirect rules
Action\RedirectRule\ListRedirectRulesAction::getRouteDef([$dropDomainMiddleware]),

// Short URLs
Action\ShortUrl\CreateShortUrlAction::getRouteDef([
$contentNegotiationMiddleware,
$dropDomainMiddleware,
$overrideDomainMiddleware,
Middleware\ShortUrl\DefaultShortCodesLengthMiddleware::class,
]),
Action\ShortUrl\SingleStepCreateShortUrlAction::getRouteDef([
$contentNegotiationMiddleware,
Middleware\ShortUrl\CreateShortUrlContentNegotiationMiddleware::class,
$overrideDomainMiddleware,
]),
Action\ShortUrl\EditShortUrlAction::getRouteDef([$dropDomainMiddleware]),
Expand Down
39 changes: 39 additions & 0 deletions docs/swagger/definitions/ShortUrlRedirectRule.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"type": "object",
"required": ["priority", "longUrl", "conditions"],
"properties": {
"longUrl": {
"description": "Long URL to redirect to when this condition matches",
"type": "string"
},
"priority": {
"description": "Order in which attempting to match the rule. Lower goes first",
"type": "number"
},
"conditions": {
"description": "List of conditions that need to match in order to consider this rule matches",
"type": "array",
"items": {
"type": "object",
"required": ["name", "type", "matchKey", "matchValue"],
"properties": {
"name": {
"type": "string",
"description": "Unique condition name"
},
"type": {
"type": "string",
"enum": ["device", "language", "query"],
"description": "The type of the condition, which will condition the logic used to match it"
},
"matchKey": {
"type": ["string", "null"]
},
"matchValue": {
"type": "string"
}
}
}
}
}
}
9 changes: 0 additions & 9 deletions docs/swagger/examples/short-url-invalid-args-v2.json

This file was deleted.

9 changes: 0 additions & 9 deletions docs/swagger/examples/short-url-not-found-v2.json

This file was deleted.

9 changes: 0 additions & 9 deletions docs/swagger/examples/tag-not-found-v2.json

This file was deleted.

16 changes: 2 additions & 14 deletions docs/swagger/paths/v1_short-urls.json
Original file line number Diff line number Diff line change
Expand Up @@ -383,29 +383,17 @@
]
},
"examples": {
"Invalid arguments with API v3 and newer": {
"Invalid arguments": {
"$ref": "../examples/short-url-invalid-args-v3.json"
},
"Non-unique slug with API v3 and newer": {
"Non-unique slug": {
"value": {
"title": "Invalid custom slug",
"type": "https://shlink.io/api/error/non-unique-slug",
"detail": "Provided slug \"my-slug\" is already in use.",
"status": 400,
"customSlug": "my-slug"
}
},
"Invalid arguments previous to API v3": {
"$ref": "../examples/short-url-invalid-args-v2.json"
},
"Non-unique slug previous to API v3": {
"value": {
"title": "Invalid custom slug",
"type": "INVALID_SLUG",
"detail": "Provided slug \"my-slug\" is already in use.",
"status": 400,
"customSlug": "my-slug"
}
}
}
}
Expand Down
20 changes: 4 additions & 16 deletions docs/swagger/paths/v1_short-urls_{shortCode}.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,8 @@
]
},
"examples": {
"API v3 and newer": {
"Short URL not found": {
"$ref": "../examples/short-url-not-found-v3.json"
},
"Previous to API v3": {
"$ref": "../examples/short-url-not-found-v2.json"
}
}
}
Expand Down Expand Up @@ -202,11 +199,8 @@
]
},
"examples": {
"API v3 and newer": {
"Invalid arguments": {
"$ref": "../examples/short-url-invalid-args-v3.json"
},
"Previous to API v3": {
"$ref": "../examples/short-url-invalid-args-v2.json"
}
}
}
Expand Down Expand Up @@ -238,11 +232,8 @@
]
},
"examples": {
"API v3 and newer": {
"Short URL not found": {
"$ref": "../examples/short-url-not-found-v3.json"
},
"Previous to API v3": {
"$ref": "../examples/short-url-not-found-v2.json"
}
}
}
Expand Down Expand Up @@ -368,11 +359,8 @@
]
},
"examples": {
"API v3 and newer": {
"Short URL not found": {
"$ref": "../examples/short-url-not-found-v3.json"
},
"Previous to API v3": {
"$ref": "../examples/short-url-not-found-v2.json"
}
}
}
Expand Down
10 changes: 2 additions & 8 deletions docs/swagger/paths/v1_short-urls_{shortCode}_visits.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,8 @@
"$ref": "../definitions/Error.json"
},
"examples": {
"Short URL not found with API v3 and newer": {
"Short URL not found": {
"$ref": "../examples/short-url-not-found-v3.json"
},
"Short URL not found previous to API v3": {
"$ref": "../examples/short-url-not-found-v2.json"
}
}
}
Expand Down Expand Up @@ -219,11 +216,8 @@
"$ref": "../definitions/Error.json"
},
"examples": {
"Short URL not found with API v3 and newer": {
"Short URL not found": {
"$ref": "../examples/short-url-not-found-v3.json"
},
"Short URL not found previous to API v3": {
"$ref": "../examples/short-url-not-found-v2.json"
}
}
}
Expand Down
3 changes: 0 additions & 3 deletions docs/swagger/paths/v1_tags.json
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,6 @@
"examples": {
"API v3 and newer": {
"$ref": "../examples/tag-not-found-v3.json"
},
"Previous to API v3": {
"$ref": "../examples/tag-not-found-v2.json"
}
}
}
Expand Down
6 changes: 1 addition & 5 deletions docs/swagger/paths/v2_tags_{tag}_visits.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,8 @@
"$ref": "../definitions/Error.json"
},
"examples": {

"API v3 and newer": {
"Tag not found": {
"$ref": "../examples/tag-not-found-v3.json"
},
"Previous to API v3": {
"$ref": "../examples/tag-not-found-v2.json"
}
}
}
Expand Down
146 changes: 146 additions & 0 deletions docs/swagger/paths/v3_short-urls_{shortCode}_redirect-rules.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
{
"get": {
"operationId": "listShortUrlRedirectRules",
"tags": [
"Redirect rules"
],
"summary": "List short URL redirect rules",
"description": "Returns the list of redirect rules for a short URL.",
"parameters": [
{
"$ref": "../parameters/version.json"
},
{
"$ref": "../parameters/shortCode.json"
},
{
"$ref": "../parameters/domain.json"
}
],
"security": [
{
"ApiKey": []
}
],
"responses": {
"200": {
"description": "The list of rules",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": ["defaultLongUrl", "redirectRules"],
"properties": {
"defaultLongUrl": {
"type": "string"
},
"redirectRules": {
"type": "array",
"items": {
"$ref": "../definitions/ShortUrlRedirectRule.json"
}
}
}
},
"example": {
"defaultLongUrl": "https://example.com",
"redirectRules": [
{
"longUrl": "https://example.com/android-en-us",
"priority": 1,
"conditions": [
{
"name": "device-android",
"type": "device",
"matchValue": "android",
"matchKey": null
},
{
"name": "language-en-US",
"type": "language",
"matchValue": "en-US",
"matchKey": null
}
]
},
{
"longUrl": "https://example.com/fr",
"priority": 2,
"conditions": [
{
"name": "language-fr",
"type": "language",
"matchValue": "fr",
"matchKey": null
}
]
},
{
"longUrl": "https://example.com/query-foo-bar-hello-world",
"priority": 3,
"conditions": [
{
"name": "query-foo-bar",
"type": "query",
"matchKey": "foo",
"matchValue": "bar"
},
{
"name": "query-hello-world",
"type": "query",
"matchKey": "hello",
"matchValue": "world"
}
]
}
]
}
}
}
},
"404": {
"description": "No URL was found for provided short code.",
"content": {
"application/problem+json": {
"schema": {
"allOf": [
{
"$ref": "../definitions/Error.json"
},
{
"type": "object",
"required": ["shortCode"],
"properties": {
"shortCode": {
"type": "string",
"description": "The short code with which we tried to find the short URL"
},
"domain": {
"type": "string",
"description": "The domain with which we tried to find the short URL"
}
}
}
]
},
"examples": {
"Short URL not found": {
"$ref": "../examples/short-url-not-found-v3.json"
}
}
}
}
},
"default": {
"description": "Unexpected error.",
"content": {
"application/problem+json": {
"schema": {
"$ref": "../definitions/Error.json"
}
}
}
}
}
}
}
Loading
Loading