From 71a63c96effb33d2986bdf9565ea7f76b1af6b3f Mon Sep 17 00:00:00 2001 From: "WoutervanderLoop.nl" Date: Mon, 22 Jan 2024 15:47:52 +0100 Subject: [PATCH] Fix Enum not correctly serialized with \http_build_query in guzzle --- src/Client.php | 40 ++++++++++++++++----------------- src/OpenApi/ClientGenerator.php | 2 +- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/Client.php b/src/Client.php index 2560f46..aeedfca 100644 --- a/src/Client.php +++ b/src/Client.php @@ -53,7 +53,7 @@ public function getCommission(string $ean, float $unitPrice, ?Enum\GetCommission $options = [ 'query' => [ 'unit-price' => $unitPrice, - 'condition' => $condition, + 'condition' => $condition?->value, ], 'produces' => 'application/vnd.retailer.v10+json', ]; @@ -184,9 +184,9 @@ public function getOfferInsights(string $offerId, Enum\GetOfferInsightsPeriod $p $options = [ 'query' => [ 'offer-id' => $offerId, - 'period' => $period, + 'period' => $period->value, 'number-of-periods' => $numberOfPeriods, - 'name' => $name, + 'name' => $name->value, ], 'produces' => 'application/vnd.retailer.v10+json', ]; @@ -216,7 +216,7 @@ public function getPerformanceIndicators(Enum\GetPerformanceIndicatorsName $name $url = "retailer/insights/performance/indicator"; $options = [ 'query' => [ - 'name' => $name, + 'name' => $name->value, 'year' => $year, 'week' => $week, ], @@ -279,7 +279,7 @@ public function getSearchTerms(string $searchTerm, Enum\GetSearchTermsPeriod $pe $options = [ 'query' => [ 'search-term' => $searchTerm, - 'period' => $period, + 'period' => $period->value, 'number-of-periods' => $numberOfPeriods, 'related-search-terms' => $relatedSearchTerms, ], @@ -315,8 +315,8 @@ public function getInventory(?int $page = 1, array $quantity = [], ?Enum\GetInve 'query' => [ 'page' => $page, 'quantity' => $quantity, - 'stock' => $stock, - 'state' => $state, + 'stock' => $stock?->value, + 'state' => $state?->value, 'query' => $query, ], 'produces' => 'application/vnd.retailer.v10+json', @@ -689,8 +689,8 @@ public function getOrders(?int $page = 1, ?Enum\GetOrdersFulfilmentMethod $fulfi $options = [ 'query' => [ 'page' => $page, - 'fulfilment-method' => $fulfilmentMethod, - 'status' => $status, + 'fulfilment-method' => $fulfilmentMethod?->value, + 'status' => $status?->value, 'change-interval-minute' => $changeIntervalMinute, 'latest-change-date' => $latestChangeDate, ], @@ -800,7 +800,7 @@ public function getProductListFilters(?Enum\GetProductListFiltersCountryCode $co $url = "retailer/products/list-filters"; $options = [ 'query' => [ - 'country-code' => $countryCode, + 'country-code' => $countryCode?->value, 'search-term' => $searchTerm, 'category-id' => $categoryId, ], @@ -830,7 +830,7 @@ public function getProductAssets(string $ean, ?Enum\GetProductAssetsUsage $usage $url = "retailer/products/{$ean}/assets"; $options = [ 'query' => [ - 'usage' => $usage, + 'usage' => $usage?->value, ], 'produces' => 'application/vnd.retailer.v10+json', ]; @@ -864,9 +864,9 @@ public function getCompetingOffers(string $ean, ?int $page = 1, ?Enum\GetCompeti $options = [ 'query' => [ 'page' => $page, - 'country-code' => $countryCode, + 'country-code' => $countryCode?->value, 'best-offer-only' => $bestOfferOnly, - 'condition' => $condition, + 'condition' => $condition?->value, ], 'produces' => 'application/vnd.retailer.v10+json', ]; @@ -896,7 +896,7 @@ public function getProductPlacement(string $ean, ?Enum\GetProductPlacementCountr $url = "retailer/products/{$ean}/placement"; $options = [ 'query' => [ - 'country-code' => $countryCode, + 'country-code' => $countryCode?->value, ], 'produces' => 'application/vnd.retailer.v10+json', ]; @@ -997,7 +997,7 @@ public function getPromotions(Enum\GetPromotionsPromotionType $promotionType, ?i $url = "retailer/promotions"; $options = [ 'query' => [ - 'promotion-type' => $promotionType, + 'promotion-type' => $promotionType->value, 'page' => $page, ], 'produces' => 'application/vnd.retailer.v10+json', @@ -1310,7 +1310,7 @@ public function getLoadCarrierLabels(string $replenishmentId, ?Enum\GetLoadCarri $url = "retailer/replenishments/{$replenishmentId}/load-carrier-labels"; $options = [ 'query' => [ - 'label-type' => $labelType, + 'label-type' => $labelType?->value, ], 'produces' => 'application/vnd.retailer.v10+pdf', ]; @@ -1391,7 +1391,7 @@ public function getReturns(?int $page = 1, ?bool $handled = null, ?Enum\GetRetur 'query' => [ 'page' => $page, 'handled' => $handled, - 'fulfilment-method' => $fulfilmentMethod, + 'fulfilment-method' => $fulfilmentMethod?->value, ], 'produces' => 'application/vnd.retailer.v10+json', ]; @@ -1500,7 +1500,7 @@ public function getShipments(?int $page = 1, ?Enum\GetShipmentsFulfilmentMethod $options = [ 'query' => [ 'page' => $page, - 'fulfilment-method' => $fulfilmentMethod, + 'fulfilment-method' => $fulfilmentMethod?->value, 'order-id' => $orderId, ], 'produces' => 'application/vnd.retailer.v10+json', @@ -1561,7 +1561,7 @@ public function getInvoiceRequests(?string $shipmentId = null, ?int $page = 1, ? 'query' => [ 'shipment-id' => $shipmentId, 'page' => $page, - 'state' => $state, + 'state' => $state?->value, ], 'produces' => 'application/vnd.retailer.v10+json', ]; @@ -1934,7 +1934,7 @@ public function getProcessStatusEntityId(string $entityId, Enum\GetProcessStatus $options = [ 'query' => [ 'entity-id' => $entityId, - 'event-type' => $eventType, + 'event-type' => $eventType->value, 'page' => $page, ], 'produces' => 'application/vnd.retailer.v10+json', diff --git a/src/OpenApi/ClientGenerator.php b/src/OpenApi/ClientGenerator.php index 388a16f..7159276 100644 --- a/src/OpenApi/ClientGenerator.php +++ b/src/OpenApi/ClientGenerator.php @@ -409,7 +409,7 @@ protected function addQueryParams(array $arguments, array &$code): void if ($argument['in'] != 'query') { continue; } - $code[] = sprintf(' \'%s\' => $%s,', $argument['paramName'], $argument['name']); + $code[] = sprintf(' \'%s\' => $%s%s,', $argument['paramName'], $argument['name'], str_starts_with($argument['php'], 'Enum') ? '->value' : (str_starts_with($argument['php'], '?Enum') ? '?->value' : '')); } $code[] = ' ],'; }