From e621ea3fb2513f9a51045a310fa053428442d990 Mon Sep 17 00:00:00 2001 From: burakaktna Date: Tue, 17 Dec 2024 13:42:09 +0300 Subject: [PATCH] fix: support both array and string inputs in parameter validation - Add getArraySize helper method - Maintain array handling in query parameters - Fix backwards compatibility from PR #700 Fixes #831 --- lib/Api/CatalogItemsV20220401Api.php | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/lib/Api/CatalogItemsV20220401Api.php b/lib/Api/CatalogItemsV20220401Api.php index 3024bf70e..1797eb55d 100644 --- a/lib/Api/CatalogItemsV20220401Api.php +++ b/lib/Api/CatalogItemsV20220401Api.php @@ -13,7 +13,7 @@ * The Selling Partner API for Catalog Items provides programmatic access to information about items in the Amazon catalog. For more information, refer to the [Catalog Items API Use Case Guide](https://developer-docs.amazon.com/sp-api/docs/catalog-items-api-v2022-04-01-use-case-guide). * * The version of the OpenAPI document: 2022-04-01 - * + * * Generated by: https://openapi-generator.tech * OpenAPI Generator version: 5.0.1 */ @@ -283,7 +283,7 @@ public function getCatalogItemWithHttpInfo($asin, $marketplace_ids, $included_da /** * Operation getCatalogItemAsync * - * + * * * @param string $asin The Amazon Standard Identification Number (ASIN) of the item. (required) * @param string[] $marketplace_ids A comma-delimited list of Amazon marketplace identifiers. Data sets in the response contain data only for the specified marketplaces. (required) @@ -301,7 +301,7 @@ public function getCatalogItemAsync($asin, $marketplace_ids, $included_data = nu /** * Operation getCatalogItemAsyncWithHttpInfo * - * + * * * @param string $asin The Amazon Standard Identification Number (ASIN) of the item. (required) * @param string[] $marketplace_ids A comma-delimited list of Amazon marketplace identifiers. Data sets in the response contain data only for the specified marketplaces. (required) @@ -737,7 +737,7 @@ public function searchCatalogItemsWithHttpInfo($marketplace_ids, $identifiers = /** * Operation searchCatalogItemsAsync * - * + * * * @param string[] $marketplace_ids A comma-delimited list of Amazon marketplace identifiers for the request. (required) * @param string[] $identifiers A comma-delimited list of product identifiers to search the Amazon catalog for. **Note:** Cannot be used with `keywords`. (optional) @@ -763,7 +763,7 @@ public function searchCatalogItemsAsync($marketplace_ids, $identifiers = null, $ /** * Operation searchCatalogItemsAsyncWithHttpInfo * - * + * * * @param string[] $marketplace_ids A comma-delimited list of Amazon marketplace identifiers for the request. (required) * @param string[] $identifiers A comma-delimited list of product identifiers to search the Amazon catalog for. **Note:** Cannot be used with `keywords`. (optional) @@ -853,15 +853,16 @@ public function searchCatalogItemsRequest($marketplace_ids, $identifiers = null, 'Missing the required parameter $marketplace_ids when calling searchCatalogItems' ); } - if (count( explode(",", $marketplace_ids) ) > 1) { + + if ($this->getMarketplaceCount($marketplace_ids) > 1) { throw new \InvalidArgumentException('invalid value for "$marketplace_ids" when calling CatalogItemsV20220401Api.searchCatalogItems, number of items must be less than or equal to 1.'); } - if ($identifiers !== null && count( explode(",", $identifiers) ) > 20) { + if ($identifiers !== null && $this->getMarketplaceCount($identifiers) > 20) { throw new \InvalidArgumentException('invalid value for "$identifiers" when calling CatalogItemsV20220401Api.searchCatalogItems, number of items must be less than or equal to 20.'); } - if ($keywords !== null && count( explode(",", $keywords) ) > 20) { + if ($keywords !== null && $this->getMarketplaceCount($keywords) > 20) { throw new \InvalidArgumentException('invalid value for "$keywords" when calling CatalogItemsV20220401Api.searchCatalogItems, number of items must be less than or equal to 20.'); } @@ -1029,4 +1030,14 @@ public function searchCatalogItemsRequest($marketplace_ids, $identifiers = null, ); } + /** + * Get the marketplace count demanded by the value type + * + * @param $value + * @return int + */ + private function getMarketplaceCount($value): int + { + return is_array($value) ? count($value) : count(explode(",", (string)$value)); + } }