Skip to content
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
5 changes: 4 additions & 1 deletion scripts/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -euo pipefail
# (php), then sync it into src/Client/ without touching the hand-written SDK
# code (the rest of src/, incl. webhook verify).
#
# Requires: java 17+, rsync, curl, yq (mikefarah v4). Run from the repo root.
# Requires: java 17+, rsync, curl, yq (mikefarah v4), Python 3. Run from the repo root.

SPEC_URL="${SPEC_URL:-https://raw.githubusercontent.com/frain-dev/convoy/main/docs/v3/openapi3.yaml}"
# Pin so regeneration output is reproducible; bump deliberately.
Expand Down Expand Up @@ -56,6 +56,9 @@ java -jar "$GENERATOR_JAR" generate \
-c .openapi-generator-config.yaml \
-o "$tmp/gen"

# Keep existing positional calls compatible when the API gains optional filters.
python3 scripts/preserve-parameter-order.py "$tmp/gen/lib/Api"

# Mirror only the generated namespace. --delete keeps src/Client an exact
# mirror of generator output; the hand-written src/ code is never touched.
rsync -a --delete "$tmp/gen/lib/" src/Client/
Expand Down
66 changes: 66 additions & 0 deletions scripts/preserve-parameter-order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
"""Preserve released PHP parameter positions when regenerating the client."""

import re
import sys
from pathlib import Path

DELIVERY_PARAMETERS = (
"project_id direction end_date endpoint_id event_id event_type idempotency_key "
"next_page_cursor per_page prev_page_cursor query sort start_date status "
"subscription_id contentType"
).split()
EVENT_PARAMETERS = (
"project_id body direction end_date endpoint_id idempotency_key "
"next_page_cursor per_page prev_page_cursor query sort source_id start_date contentType"
).split()
OPERATIONS = {
"DeliveryAttemptsApi.php": {
"getDeliveryAttempts": ["project_id", "event_delivery_id", "contentType"],
},
"EventDeliveriesApi.php": {
"batchRetryEventDelivery": DELIVERY_PARAMETERS,
"getEventDeliveriesPaged": DELIVERY_PARAMETERS,
},
"EventsApi.php": {
"batchReplayEvents": EVENT_PARAMETERS,
"countAffectedEvents": EVENT_PARAMETERS,
"getEventsPaged": EVENT_PARAMETERS,
},
}
SUFFIXES = ("", "WithHttpInfo", "Async", "AsyncWithHttpInfo", "Request")


def preserve_order(source, operation, legacy_order):
methods = "|".join(operation + suffix for suffix in SUFFIXES)
pattern = rf"(public function |\$this->)({methods})\(([^\n()]*)\)"

def reorder(match):
prefix, method, arguments = match.groups()
parts = dict(
(re.search(r"\$(\w+)", part).group(1), part)
for part in arguments.split(", ")
)
missing = set(legacy_order).difference(parts)
if missing:
raise ValueError(f"{method} is missing released parameters: {sorted(missing)}")
order = legacy_order + [name for name in parts if name not in legacy_order]
return f"{prefix}{method}({', '.join(parts[name] for name in order)})"

source, count = re.subn(pattern, reorder, source)
# Each operation has five public methods and four internal calls.
if count != 9:
raise ValueError(f"{operation}: expected 9 signatures and calls, found {count}")
return source


def main(api_directory):
for filename, operations in OPERATIONS.items():
path = api_directory / filename
source = path.read_text()
for operation, legacy_order in operations.items():
source = preserve_order(source, operation, legacy_order)
path.write_text(source)


if __name__ == "__main__":
main(Path(sys.argv[1]))
48 changes: 39 additions & 9 deletions src/Client/Api/DeliveryAttemptsApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -490,15 +490,17 @@ public function getDeliveryAttemptRequest($project_id, $event_delivery_id, $deli
*
* @param string $project_id Project ID (required)
* @param string $event_delivery_id event delivery id (required)
* @param bool|null $paginated Return a page of ten attempts and next_cursor (optional)
* @param string|null $before Exclusive attempt cursor from next_cursor; requires paginated=true (optional)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['getDeliveryAttempts'] to see the possible values for this operation
*
* @throws \Convoy\Client\ApiException on non-2xx response or if the response body is not in the expected format
* @throws \InvalidArgumentException
* @return \Convoy\Client\Model\GetDeliveryAttempts200Response|\Convoy\Client\Model\GetProjects400Response|\Convoy\Client\Model\GetProjects400Response|\Convoy\Client\Model\GetProjects400Response
*/
public function getDeliveryAttempts($project_id, $event_delivery_id, string $contentType = self::contentTypes['getDeliveryAttempts'][0])
public function getDeliveryAttempts($project_id, $event_delivery_id, string $contentType = self::contentTypes['getDeliveryAttempts'][0], $paginated = null, $before = null)
{
list($response) = $this->getDeliveryAttemptsWithHttpInfo($project_id, $event_delivery_id, $contentType);
list($response) = $this->getDeliveryAttemptsWithHttpInfo($project_id, $event_delivery_id, $contentType, $paginated, $before);
return $response;
}

Expand All @@ -509,15 +511,17 @@ public function getDeliveryAttempts($project_id, $event_delivery_id, string $con
*
* @param string $project_id Project ID (required)
* @param string $event_delivery_id event delivery id (required)
* @param bool|null $paginated Return a page of ten attempts and next_cursor (optional)
* @param string|null $before Exclusive attempt cursor from next_cursor; requires paginated=true (optional)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['getDeliveryAttempts'] to see the possible values for this operation
*
* @throws \Convoy\Client\ApiException on non-2xx response or if the response body is not in the expected format
* @throws \InvalidArgumentException
* @return array of \Convoy\Client\Model\GetDeliveryAttempts200Response|\Convoy\Client\Model\GetProjects400Response|\Convoy\Client\Model\GetProjects400Response|\Convoy\Client\Model\GetProjects400Response, HTTP status code, HTTP response headers (array of strings)
*/
public function getDeliveryAttemptsWithHttpInfo($project_id, $event_delivery_id, string $contentType = self::contentTypes['getDeliveryAttempts'][0])
public function getDeliveryAttemptsWithHttpInfo($project_id, $event_delivery_id, string $contentType = self::contentTypes['getDeliveryAttempts'][0], $paginated = null, $before = null)
{
$request = $this->getDeliveryAttemptsRequest($project_id, $event_delivery_id, $contentType);
$request = $this->getDeliveryAttemptsRequest($project_id, $event_delivery_id, $contentType, $paginated, $before);

try {
$options = $this->createHttpClientOption();
Expand Down Expand Up @@ -637,14 +641,16 @@ public function getDeliveryAttemptsWithHttpInfo($project_id, $event_delivery_id,
*
* @param string $project_id Project ID (required)
* @param string $event_delivery_id event delivery id (required)
* @param bool|null $paginated Return a page of ten attempts and next_cursor (optional)
* @param string|null $before Exclusive attempt cursor from next_cursor; requires paginated=true (optional)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['getDeliveryAttempts'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function getDeliveryAttemptsAsync($project_id, $event_delivery_id, string $contentType = self::contentTypes['getDeliveryAttempts'][0])
public function getDeliveryAttemptsAsync($project_id, $event_delivery_id, string $contentType = self::contentTypes['getDeliveryAttempts'][0], $paginated = null, $before = null)
{
return $this->getDeliveryAttemptsAsyncWithHttpInfo($project_id, $event_delivery_id, $contentType)
return $this->getDeliveryAttemptsAsyncWithHttpInfo($project_id, $event_delivery_id, $contentType, $paginated, $before)
->then(
function ($response) {
return $response[0];
Expand All @@ -659,15 +665,17 @@ function ($response) {
*
* @param string $project_id Project ID (required)
* @param string $event_delivery_id event delivery id (required)
* @param bool|null $paginated Return a page of ten attempts and next_cursor (optional)
* @param string|null $before Exclusive attempt cursor from next_cursor; requires paginated=true (optional)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['getDeliveryAttempts'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function getDeliveryAttemptsAsyncWithHttpInfo($project_id, $event_delivery_id, string $contentType = self::contentTypes['getDeliveryAttempts'][0])
public function getDeliveryAttemptsAsyncWithHttpInfo($project_id, $event_delivery_id, string $contentType = self::contentTypes['getDeliveryAttempts'][0], $paginated = null, $before = null)
{
$returnType = '\Convoy\Client\Model\GetDeliveryAttempts200Response';
$request = $this->getDeliveryAttemptsRequest($project_id, $event_delivery_id, $contentType);
$request = $this->getDeliveryAttemptsRequest($project_id, $event_delivery_id, $contentType, $paginated, $before);

return $this->client
->sendAsync($request, $this->createHttpClientOption())
Expand Down Expand Up @@ -710,12 +718,14 @@ function ($exception) {
*
* @param string $project_id Project ID (required)
* @param string $event_delivery_id event delivery id (required)
* @param bool|null $paginated Return a page of ten attempts and next_cursor (optional)
* @param string|null $before Exclusive attempt cursor from next_cursor; requires paginated=true (optional)
* @param string $contentType The value for the Content-Type header. Check self::contentTypes['getDeliveryAttempts'] to see the possible values for this operation
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Psr7\Request
*/
public function getDeliveryAttemptsRequest($project_id, $event_delivery_id, string $contentType = self::contentTypes['getDeliveryAttempts'][0])
public function getDeliveryAttemptsRequest($project_id, $event_delivery_id, string $contentType = self::contentTypes['getDeliveryAttempts'][0], $paginated = null, $before = null)
{

// verify the required parameter 'project_id' is set
Expand All @@ -733,13 +743,33 @@ public function getDeliveryAttemptsRequest($project_id, $event_delivery_id, stri
}




$resourcePath = '/v1/projects/{projectID}/eventdeliveries/{eventDeliveryID}/deliveryattempts';
$formParams = [];
$queryParams = [];
$headerParams = [];
$httpBody = '';
$multipart = false;

// query params
$queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
$paginated,
'paginated', // param base name
'boolean', // openApiType
'form', // style
true, // explode
false // required
) ?? []);
// query params
$queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
$before,
'before', // param base name
'string', // openApiType
'form', // style
true, // explode
false // required
) ?? []);


// path params
Expand Down
Loading