Skip to content

Commit

Permalink
fix: support both array and string inputs in parameter validation
Browse files Browse the repository at this point in the history
- Add getArraySize helper method
- Maintain array handling in query parameters
- Fix backwards compatibility from PR jlevers#700

Fixes jlevers#831
  • Loading branch information
burakaktna committed Dec 17, 2024
1 parent 1ae7a24 commit e621ea3
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions lib/Api/CatalogItemsV20220401Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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.');
}

Expand Down Expand Up @@ -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));
}
}

0 comments on commit e621ea3

Please sign in to comment.