Skip to content

Commit 71a63c9

Browse files
Fix Enum not correctly serialized with \http_build_query in guzzle
1 parent 2305bf1 commit 71a63c9

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

src/Client.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function getCommission(string $ean, float $unitPrice, ?Enum\GetCommission
5353
$options = [
5454
'query' => [
5555
'unit-price' => $unitPrice,
56-
'condition' => $condition,
56+
'condition' => $condition?->value,
5757
],
5858
'produces' => 'application/vnd.retailer.v10+json',
5959
];
@@ -184,9 +184,9 @@ public function getOfferInsights(string $offerId, Enum\GetOfferInsightsPeriod $p
184184
$options = [
185185
'query' => [
186186
'offer-id' => $offerId,
187-
'period' => $period,
187+
'period' => $period->value,
188188
'number-of-periods' => $numberOfPeriods,
189-
'name' => $name,
189+
'name' => $name->value,
190190
],
191191
'produces' => 'application/vnd.retailer.v10+json',
192192
];
@@ -216,7 +216,7 @@ public function getPerformanceIndicators(Enum\GetPerformanceIndicatorsName $name
216216
$url = "retailer/insights/performance/indicator";
217217
$options = [
218218
'query' => [
219-
'name' => $name,
219+
'name' => $name->value,
220220
'year' => $year,
221221
'week' => $week,
222222
],
@@ -279,7 +279,7 @@ public function getSearchTerms(string $searchTerm, Enum\GetSearchTermsPeriod $pe
279279
$options = [
280280
'query' => [
281281
'search-term' => $searchTerm,
282-
'period' => $period,
282+
'period' => $period->value,
283283
'number-of-periods' => $numberOfPeriods,
284284
'related-search-terms' => $relatedSearchTerms,
285285
],
@@ -315,8 +315,8 @@ public function getInventory(?int $page = 1, array $quantity = [], ?Enum\GetInve
315315
'query' => [
316316
'page' => $page,
317317
'quantity' => $quantity,
318-
'stock' => $stock,
319-
'state' => $state,
318+
'stock' => $stock?->value,
319+
'state' => $state?->value,
320320
'query' => $query,
321321
],
322322
'produces' => 'application/vnd.retailer.v10+json',
@@ -689,8 +689,8 @@ public function getOrders(?int $page = 1, ?Enum\GetOrdersFulfilmentMethod $fulfi
689689
$options = [
690690
'query' => [
691691
'page' => $page,
692-
'fulfilment-method' => $fulfilmentMethod,
693-
'status' => $status,
692+
'fulfilment-method' => $fulfilmentMethod?->value,
693+
'status' => $status?->value,
694694
'change-interval-minute' => $changeIntervalMinute,
695695
'latest-change-date' => $latestChangeDate,
696696
],
@@ -800,7 +800,7 @@ public function getProductListFilters(?Enum\GetProductListFiltersCountryCode $co
800800
$url = "retailer/products/list-filters";
801801
$options = [
802802
'query' => [
803-
'country-code' => $countryCode,
803+
'country-code' => $countryCode?->value,
804804
'search-term' => $searchTerm,
805805
'category-id' => $categoryId,
806806
],
@@ -830,7 +830,7 @@ public function getProductAssets(string $ean, ?Enum\GetProductAssetsUsage $usage
830830
$url = "retailer/products/{$ean}/assets";
831831
$options = [
832832
'query' => [
833-
'usage' => $usage,
833+
'usage' => $usage?->value,
834834
],
835835
'produces' => 'application/vnd.retailer.v10+json',
836836
];
@@ -864,9 +864,9 @@ public function getCompetingOffers(string $ean, ?int $page = 1, ?Enum\GetCompeti
864864
$options = [
865865
'query' => [
866866
'page' => $page,
867-
'country-code' => $countryCode,
867+
'country-code' => $countryCode?->value,
868868
'best-offer-only' => $bestOfferOnly,
869-
'condition' => $condition,
869+
'condition' => $condition?->value,
870870
],
871871
'produces' => 'application/vnd.retailer.v10+json',
872872
];
@@ -896,7 +896,7 @@ public function getProductPlacement(string $ean, ?Enum\GetProductPlacementCountr
896896
$url = "retailer/products/{$ean}/placement";
897897
$options = [
898898
'query' => [
899-
'country-code' => $countryCode,
899+
'country-code' => $countryCode?->value,
900900
],
901901
'produces' => 'application/vnd.retailer.v10+json',
902902
];
@@ -997,7 +997,7 @@ public function getPromotions(Enum\GetPromotionsPromotionType $promotionType, ?i
997997
$url = "retailer/promotions";
998998
$options = [
999999
'query' => [
1000-
'promotion-type' => $promotionType,
1000+
'promotion-type' => $promotionType->value,
10011001
'page' => $page,
10021002
],
10031003
'produces' => 'application/vnd.retailer.v10+json',
@@ -1310,7 +1310,7 @@ public function getLoadCarrierLabels(string $replenishmentId, ?Enum\GetLoadCarri
13101310
$url = "retailer/replenishments/{$replenishmentId}/load-carrier-labels";
13111311
$options = [
13121312
'query' => [
1313-
'label-type' => $labelType,
1313+
'label-type' => $labelType?->value,
13141314
],
13151315
'produces' => 'application/vnd.retailer.v10+pdf',
13161316
];
@@ -1391,7 +1391,7 @@ public function getReturns(?int $page = 1, ?bool $handled = null, ?Enum\GetRetur
13911391
'query' => [
13921392
'page' => $page,
13931393
'handled' => $handled,
1394-
'fulfilment-method' => $fulfilmentMethod,
1394+
'fulfilment-method' => $fulfilmentMethod?->value,
13951395
],
13961396
'produces' => 'application/vnd.retailer.v10+json',
13971397
];
@@ -1500,7 +1500,7 @@ public function getShipments(?int $page = 1, ?Enum\GetShipmentsFulfilmentMethod
15001500
$options = [
15011501
'query' => [
15021502
'page' => $page,
1503-
'fulfilment-method' => $fulfilmentMethod,
1503+
'fulfilment-method' => $fulfilmentMethod?->value,
15041504
'order-id' => $orderId,
15051505
],
15061506
'produces' => 'application/vnd.retailer.v10+json',
@@ -1561,7 +1561,7 @@ public function getInvoiceRequests(?string $shipmentId = null, ?int $page = 1, ?
15611561
'query' => [
15621562
'shipment-id' => $shipmentId,
15631563
'page' => $page,
1564-
'state' => $state,
1564+
'state' => $state?->value,
15651565
],
15661566
'produces' => 'application/vnd.retailer.v10+json',
15671567
];
@@ -1934,7 +1934,7 @@ public function getProcessStatusEntityId(string $entityId, Enum\GetProcessStatus
19341934
$options = [
19351935
'query' => [
19361936
'entity-id' => $entityId,
1937-
'event-type' => $eventType,
1937+
'event-type' => $eventType->value,
19381938
'page' => $page,
19391939
],
19401940
'produces' => 'application/vnd.retailer.v10+json',

src/OpenApi/ClientGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ protected function addQueryParams(array $arguments, array &$code): void
409409
if ($argument['in'] != 'query') {
410410
continue;
411411
}
412-
$code[] = sprintf(' \'%s\' => $%s,', $argument['paramName'], $argument['name']);
412+
$code[] = sprintf(' \'%s\' => $%s%s,', $argument['paramName'], $argument['name'], str_starts_with($argument['php'], 'Enum') ? '->value' : (str_starts_with($argument['php'], '?Enum') ? '?->value' : ''));
413413
}
414414
$code[] = ' ],';
415415
}

0 commit comments

Comments
 (0)