From 9b96ddbe1a9261484780946a952532deff97cbb7 Mon Sep 17 00:00:00 2001 From: ksvirkou-hubspot Date: Fri, 11 Apr 2025 11:13:14 +0300 Subject: [PATCH 1/2] Codegen: Events Send --- .../{CustomEventDataApi.php => BasicApi.php} | 14 +- codegen/Events/Send/Api/BatchApi.php | 383 ++++++++++++++++ ...edBehavioralEventHttpCompletionRequest.php | 412 ++++++++++++++++++ .../BehavioralEventHttpCompletionRequest.php | 14 +- 4 files changed, 809 insertions(+), 14 deletions(-) rename codegen/Events/Send/Api/{CustomEventDataApi.php => BasicApi.php} (98%) create mode 100644 codegen/Events/Send/Api/BatchApi.php create mode 100644 codegen/Events/Send/Model/BatchedBehavioralEventHttpCompletionRequest.php diff --git a/codegen/Events/Send/Api/CustomEventDataApi.php b/codegen/Events/Send/Api/BasicApi.php similarity index 98% rename from codegen/Events/Send/Api/CustomEventDataApi.php rename to codegen/Events/Send/Api/BasicApi.php index 984c96ac8..5711e7e9c 100644 --- a/codegen/Events/Send/Api/CustomEventDataApi.php +++ b/codegen/Events/Send/Api/BasicApi.php @@ -1,6 +1,6 @@ [ + 'application/json', + ], + ]; + + /** + * @param ClientInterface $client + * @param Configuration $config + * @param HeaderSelector $selector + * @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec + */ + public function __construct( + ClientInterface $client = null, + Configuration $config = null, + HeaderSelector $selector = null, + $hostIndex = 0 + ) { + $this->client = $client ?: new Client(); + $this->config = $config ?: new Configuration(); + $this->headerSelector = $selector ?: new HeaderSelector(); + $this->hostIndex = $hostIndex; + } + + /** + * Set the host index + * + * @param int $hostIndex Host index (required) + */ + public function setHostIndex($hostIndex): void + { + $this->hostIndex = $hostIndex; + } + + /** + * Get the host index + * + * @return int Host index + */ + public function getHostIndex() + { + return $this->hostIndex; + } + + /** + * @return Configuration + */ + public function getConfig() + { + return $this->config; + } + + /** + * Operation send + * + * Send a batch of event completions + * + * @param \HubSpot\Client\Events\Send\Model\BatchedBehavioralEventHttpCompletionRequest $batched_behavioral_event_http_completion_request batched_behavioral_event_http_completion_request (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['send'] to see the possible values for this operation + * + * @throws \HubSpot\Client\Events\Send\ApiException on non-2xx response or if the response body is not in the expected format + * @throws \InvalidArgumentException + * @return void + */ + public function send($batched_behavioral_event_http_completion_request, string $contentType = self::contentTypes['send'][0]) + { + $this->sendWithHttpInfo($batched_behavioral_event_http_completion_request, $contentType); + } + + /** + * Operation sendWithHttpInfo + * + * Send a batch of event completions + * + * @param \HubSpot\Client\Events\Send\Model\BatchedBehavioralEventHttpCompletionRequest $batched_behavioral_event_http_completion_request (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['send'] to see the possible values for this operation + * + * @throws \HubSpot\Client\Events\Send\ApiException on non-2xx response or if the response body is not in the expected format + * @throws \InvalidArgumentException + * @return array of null, HTTP status code, HTTP response headers (array of strings) + */ + public function sendWithHttpInfo($batched_behavioral_event_http_completion_request, string $contentType = self::contentTypes['send'][0]) + { + $request = $this->sendRequest($batched_behavioral_event_http_completion_request, $contentType); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + return [null, $statusCode, $response->getHeaders()]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + default: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\HubSpot\Client\Events\Send\Model\Error', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation sendAsync + * + * Send a batch of event completions + * + * @param \HubSpot\Client\Events\Send\Model\BatchedBehavioralEventHttpCompletionRequest $batched_behavioral_event_http_completion_request (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['send'] to see the possible values for this operation + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function sendAsync($batched_behavioral_event_http_completion_request, string $contentType = self::contentTypes['send'][0]) + { + return $this->sendAsyncWithHttpInfo($batched_behavioral_event_http_completion_request, $contentType) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation sendAsyncWithHttpInfo + * + * Send a batch of event completions + * + * @param \HubSpot\Client\Events\Send\Model\BatchedBehavioralEventHttpCompletionRequest $batched_behavioral_event_http_completion_request (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['send'] to see the possible values for this operation + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function sendAsyncWithHttpInfo($batched_behavioral_event_http_completion_request, string $contentType = self::contentTypes['send'][0]) + { + $returnType = ''; + $request = $this->sendRequest($batched_behavioral_event_http_completion_request, $contentType); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + return [null, $response->getStatusCode(), $response->getHeaders()]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'send' + * + * @param \HubSpot\Client\Events\Send\Model\BatchedBehavioralEventHttpCompletionRequest $batched_behavioral_event_http_completion_request (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['send'] to see the possible values for this operation + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function sendRequest($batched_behavioral_event_http_completion_request, string $contentType = self::contentTypes['send'][0]) + { + + // verify the required parameter 'batched_behavioral_event_http_completion_request' is set + if ($batched_behavioral_event_http_completion_request === null || (is_array($batched_behavioral_event_http_completion_request) && count($batched_behavioral_event_http_completion_request) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $batched_behavioral_event_http_completion_request when calling send' + ); + } + + + $resourcePath = '/events/v3/send/batch'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + + + + $headers = $this->headerSelector->selectHeaders( + ['*/*', ], + $contentType, + $multipart + ); + + // for model (json/xml) + if (isset($batched_behavioral_event_http_completion_request)) { + if (stripos($headers['Content-Type'], 'application/json') !== false) { + # if Content-Type contains "application/json", json_encode the body + $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($batched_behavioral_event_http_completion_request)); + } else { + $httpBody = $batched_behavioral_event_http_completion_request; + } + } elseif (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { + # if Content-Type contains "application/json", json_encode the form parameters + $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + } else { + // for HTTP post (form) + $httpBody = ObjectSerializer::buildQuery($formParams); + } + } + + // this endpoint requires OAuth (access token) + if (!empty($this->config->getAccessToken())) { + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $operationHost = $this->config->getHost(); + $query = ObjectSerializer::buildQuery($queryParams); + return new Request( + 'POST', + $operationHost . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Create http client option + * + * @throws \RuntimeException on file opening failure + * @return array of http client options + */ + protected function createHttpClientOption() + { + $options = []; + if ($this->config->getDebug()) { + $options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a'); + if (!$options[RequestOptions::DEBUG]) { + throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile()); + } + } + + return $options; + } +} diff --git a/codegen/Events/Send/Model/BatchedBehavioralEventHttpCompletionRequest.php b/codegen/Events/Send/Model/BatchedBehavioralEventHttpCompletionRequest.php new file mode 100644 index 000000000..001909cb4 --- /dev/null +++ b/codegen/Events/Send/Model/BatchedBehavioralEventHttpCompletionRequest.php @@ -0,0 +1,412 @@ + + */ +class BatchedBehavioralEventHttpCompletionRequest implements ModelInterface, ArrayAccess, \JsonSerializable +{ + public const DISCRIMINATOR = null; + + /** + * The original name of the model. + * + * @var string + */ + protected static $openAPIModelName = 'BatchedBehavioralEventHttpCompletionRequest'; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @var string[] + */ + protected static $openAPITypes = [ + 'inputs' => '\HubSpot\Client\Events\Send\Model\BehavioralEventHttpCompletionRequest[]' + ]; + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @var string[] + * @phpstan-var array + * @psalm-var array + */ + protected static $openAPIFormats = [ + 'inputs' => null + ]; + + /** + * Array of nullable properties. Used for (de)serialization + * + * @var boolean[] + */ + protected static array $openAPINullables = [ + 'inputs' => false + ]; + + /** + * If a nullable field gets set to null, insert it here + * + * @var boolean[] + */ + protected array $openAPINullablesSetToNull = []; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPITypes() + { + return self::$openAPITypes; + } + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPIFormats() + { + return self::$openAPIFormats; + } + + /** + * Array of nullable properties + * + * @return array + */ + protected static function openAPINullables(): array + { + return self::$openAPINullables; + } + + /** + * Array of nullable field names deliberately set to null + * + * @return boolean[] + */ + private function getOpenAPINullablesSetToNull(): array + { + return $this->openAPINullablesSetToNull; + } + + /** + * Setter - Array of nullable field names deliberately set to null + * + * @param boolean[] $openAPINullablesSetToNull + */ + private function setOpenAPINullablesSetToNull(array $openAPINullablesSetToNull): void + { + $this->openAPINullablesSetToNull = $openAPINullablesSetToNull; + } + + /** + * Checks if a property is nullable + * + * @param string $property + * @return bool + */ + public static function isNullable(string $property): bool + { + return self::openAPINullables()[$property] ?? false; + } + + /** + * Checks if a nullable property is set to null. + * + * @param string $property + * @return bool + */ + public function isNullableSetToNull(string $property): bool + { + return in_array($property, $this->getOpenAPINullablesSetToNull(), true); + } + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @var string[] + */ + protected static $attributeMap = [ + 'inputs' => 'inputs' + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @var string[] + */ + protected static $setters = [ + 'inputs' => 'setInputs' + ]; + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @var string[] + */ + protected static $getters = [ + 'inputs' => 'getInputs' + ]; + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @return array + */ + public static function attributeMap() + { + return self::$attributeMap; + } + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @return array + */ + public static function setters() + { + return self::$setters; + } + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @return array + */ + public static function getters() + { + return self::$getters; + } + + /** + * The original name of the model. + * + * @return string + */ + public function getModelName() + { + return self::$openAPIModelName; + } + + + /** + * Associative array for storing property values + * + * @var mixed[] + */ + protected $container = []; + + /** + * Constructor + * + * @param mixed[] $data Associated array of property values + * initializing the model + */ + public function __construct(array $data = null) + { + $this->setIfExists('inputs', $data ?? [], null); + } + + /** + * Sets $this->container[$variableName] to the given data or to the given default Value; if $variableName + * is nullable and its value is set to null in the $fields array, then mark it as "set to null" in the + * $this->openAPINullablesSetToNull array + * + * @param string $variableName + * @param array $fields + * @param mixed $defaultValue + */ + private function setIfExists(string $variableName, array $fields, $defaultValue): void + { + if (self::isNullable($variableName) && array_key_exists($variableName, $fields) && is_null($fields[$variableName])) { + $this->openAPINullablesSetToNull[] = $variableName; + } + + $this->container[$variableName] = $fields[$variableName] ?? $defaultValue; + } + + /** + * Show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $invalidProperties = []; + + if ($this->container['inputs'] === null) { + $invalidProperties[] = "'inputs' can't be null"; + } + return $invalidProperties; + } + + /** + * Validate all the properties in the model + * return true if all passed + * + * @return bool True if all properties are valid + */ + public function valid() + { + return count($this->listInvalidProperties()) === 0; + } + + + /** + * Gets inputs + * + * @return \HubSpot\Client\Events\Send\Model\BehavioralEventHttpCompletionRequest[] + */ + public function getInputs() + { + return $this->container['inputs']; + } + + /** + * Sets inputs + * + * @param \HubSpot\Client\Events\Send\Model\BehavioralEventHttpCompletionRequest[] $inputs inputs + * + * @return self + */ + public function setInputs($inputs) + { + if (is_null($inputs)) { + throw new \InvalidArgumentException('non-nullable inputs cannot be null'); + } + $this->container['inputs'] = $inputs; + + return $this; + } + /** + * Returns true if offset exists. False otherwise. + * + * @param integer $offset Offset + * + * @return boolean + */ + public function offsetExists($offset): bool + { + return isset($this->container[$offset]); + } + + /** + * Gets offset. + * + * @param integer $offset Offset + * + * @return mixed|null + */ + #[\ReturnTypeWillChange] + public function offsetGet($offset) + { + return $this->container[$offset] ?? null; + } + + /** + * Sets value based on offset. + * + * @param int|null $offset Offset + * @param mixed $value Value to be set + * + * @return void + */ + public function offsetSet($offset, $value): void + { + if (is_null($offset)) { + $this->container[] = $value; + } else { + $this->container[$offset] = $value; + } + } + + /** + * Unsets offset. + * + * @param integer $offset Offset + * + * @return void + */ + public function offsetUnset($offset): void + { + unset($this->container[$offset]); + } + + /** + * Serializes the object to a value that can be serialized natively by json_encode(). + * @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php + * + * @return mixed Returns data which can be serialized by json_encode(), which is a value + * of any type other than a resource. + */ + #[\ReturnTypeWillChange] + public function jsonSerialize() + { + return ObjectSerializer::sanitizeForSerialization($this); + } + + /** + * Gets the string presentation of the object + * + * @return string + */ + public function __toString() + { + return json_encode( + ObjectSerializer::sanitizeForSerialization($this), + JSON_PRETTY_PRINT + ); + } + + /** + * Gets a header-safe presentation of the object + * + * @return string + */ + public function toHeaderValue() + { + return json_encode(ObjectSerializer::sanitizeForSerialization($this)); + } +} + + diff --git a/codegen/Events/Send/Model/BehavioralEventHttpCompletionRequest.php b/codegen/Events/Send/Model/BehavioralEventHttpCompletionRequest.php index a413cae81..fcde6d23e 100644 --- a/codegen/Events/Send/Model/BehavioralEventHttpCompletionRequest.php +++ b/codegen/Events/Send/Model/BehavioralEventHttpCompletionRequest.php @@ -347,7 +347,7 @@ public function getOccurredAt() /** * Sets occurred_at * - * @param \DateTime|null $occurred_at The time when this event occurred (if any). If this isn't set, the current time will be used + * @param \DateTime|null $occurred_at The time when this event occurred. If this isn't set, the current time will be used. * * @return self */ @@ -374,7 +374,7 @@ public function getEventName() /** * Sets event_name * - * @param string $event_name Internal name of the event-type to trigger + * @param string $event_name The internal name of the event (`pe_eventName`). Can be retrieved through the [event definitions API](https://developers.hubspot.com/docs/reference/api/analytics-and-events/custom-events/custom-event-definitions#get-%2Fevents%2Fv3%2Fevent-definitions) or in [HubSpot's UI](https://knowledge.hubspot.com/reports/create-custom-behavioral-events-with-the-code-wizard#find-internal-name). * * @return self */ @@ -401,7 +401,7 @@ public function getUtk() /** * Sets utk * - * @param string|null $utk User token + * @param string|null $utk The visitor's usertoken. Used for associating the event data with a CRM record. * * @return self */ @@ -428,7 +428,7 @@ public function getUuid() /** * Sets uuid * - * @param string|null $uuid uuid + * @param string|null $uuid Include a universally unique identifier to assign a unique ID to the event completion. Can be useful for matching data between HubSpot and other external systems. * * @return self */ @@ -455,7 +455,7 @@ public function getEmail() /** * Sets email * - * @param string|null $email Email of visitor + * @param string|null $email The visitor's email address. Used for associating the event data with a CRM record. * * @return self */ @@ -482,7 +482,7 @@ public function getProperties() /** * Sets properties * - * @param array|null $properties Map of properties for the event in the format property internal name - property value + * @param array|null $properties The event properties to update. Takes the format of key-value pairs (property internal name and property value). Learn more about [HubSpot's default event properties](https://developers.hubspot.com/docs/guides/api/analytics-and-events/custom-events/custom-event-definitions#hubspot-s-default-event-properties). * * @return self */ @@ -509,7 +509,7 @@ public function getObjectId() /** * Sets object_id * - * @param string|null $object_id The object id that this event occurred on. Could be a contact id or a visitor id. + * @param string|null $object_id The ID of the object that completed the event (e.g., contact ID or visitor ID). * * @return self */ From 5e823bdf13e7a04a4a72cefe793ec2f43bc47bb5 Mon Sep 17 00:00:00 2001 From: ksvirkou-hubspot Date: Fri, 11 Apr 2025 11:25:12 +0300 Subject: [PATCH 2/2] Codegen: Events --- codegen/Events/Api/EventsApi.php | 190 +++++++++--------- codegen/Events/ApiException.php | 8 +- codegen/Events/Configuration.php | 4 +- codegen/Events/HeaderSelector.php | 32 ++- ...CollectionResponseExternalUnifiedEvent.php | 6 +- codegen/Events/Model/Error.php | 6 +- codegen/Events/Model/ErrorDetail.php | 6 +- codegen/Events/Model/ExternalUnifiedEvent.php | 6 +- codegen/Events/Model/ModelInterface.php | 2 +- codegen/Events/Model/NextPage.php | 6 +- codegen/Events/Model/Paging.php | 6 +- codegen/Events/Model/PreviousPage.php | 6 +- .../Model/VisibleExternalEventTypeNames.php | 6 +- codegen/Events/ObjectSerializer.php | 98 ++++++--- codegen/Events/Send/Api/BasicApi.php | 24 +-- codegen/Events/Send/Api/BatchApi.php | 24 +-- codegen/Events/Send/ApiException.php | 8 +- codegen/Events/Send/Configuration.php | 4 +- codegen/Events/Send/HeaderSelector.php | 32 ++- ...edBehavioralEventHttpCompletionRequest.php | 6 +- .../BehavioralEventHttpCompletionRequest.php | 6 +- codegen/Events/Send/Model/Error.php | 6 +- codegen/Events/Send/Model/ErrorDetail.php | 6 +- codegen/Events/Send/Model/ModelInterface.php | 2 +- codegen/Events/Send/ObjectSerializer.php | 98 ++++++--- 25 files changed, 366 insertions(+), 232 deletions(-) diff --git a/codegen/Events/Api/EventsApi.php b/codegen/Events/Api/EventsApi.php index 65b806758..bca8c288d 100644 --- a/codegen/Events/Api/EventsApi.php +++ b/codegen/Events/Api/EventsApi.php @@ -16,7 +16,7 @@ * * The version of the OpenAPI document: v3 * Generated by: https://openapi-generator.tech - * OpenAPI Generator version: 7.3.0 + * Generator version: 7.12.0 */ /** @@ -86,13 +86,13 @@ class EventsApi * @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec */ public function __construct( - ClientInterface $client = null, - Configuration $config = null, - HeaderSelector $selector = null, - $hostIndex = 0 + ?ClientInterface $client = null, + ?Configuration $config = null, + ?HeaderSelector $selector = null, + int $hostIndex = 0 ) { $this->client = $client ?: new Client(); - $this->config = $config ?: new Configuration(); + $this->config = $config ?: Configuration::getDefaultConfiguration(); $this->headerSelector = $selector ?: new HeaderSelector(); $this->hostIndex = $hostIndex; } @@ -128,20 +128,20 @@ public function getConfig() /** * Operation getPage * - * Event Instance Query + * Retrieve event data * - * @param string $object_type The CRM Object type name to filter event instances on. Optionally, you can also provide an objectId in another param to filter to a specific CRM Object instance. (optional) - * @param string $event_type The event type name. A list of available event type names can be obtained from another API call. (optional) - * @param string $after The paging cursor token of the last successfully read resource will be returned as the `paging.next.after` JSON property of a paged response containing more results. (optional) - * @param string $before before (optional) - * @param int $limit The maximum number of results to display per page. (optional) - * @param string[] $sort Sort direction based on the timestamp of the event instance, ASCENDING or DESCENDING. (optional) - * @param \DateTime $occurred_after occurred_after (optional) - * @param \DateTime $occurred_before occurred_before (optional) - * @param int $object_id The ID of the CRM Object to filter event instances on. If filtering on objectId, you must also provide an objectType. (optional) - * @param object $object_property_propname object_property_propname (optional) - * @param object $property_propname property_propname (optional) - * @param string[] $id ID of an event instance. IDs are 1:1 with event instances. If you. provide this filter and additional filters, the other filters must match the values on the event instance to yield results. (optional) + * @param string|null $object_type The type of CRM object to filter event instances on (e.g., `contact`). To retrieve event data for a specific CRM record, include the additional `objectId` query parameter (below). (optional) + * @param string|null $event_type The event type name. You can retrieve available event types using the [event types endpoint](#get-%2Fevents%2Fv3%2Fevents%2Fevent-types). (optional) + * @param string|null $after The paging cursor token of the last successfully read resource will be returned as the `paging.next.after` JSON property of a paged response containing more results. (optional) + * @param string|null $before before (optional) + * @param int|null $limit The maximum number of results to display per page. (optional) + * @param string[]|null $sort Sort direction based on the timestamp of the event instance, `ASCENDING` or `DESCENDING`. (optional) + * @param \DateTime|null $occurred_after Filter for event data that occurred after a specific datetime. (optional) + * @param \DateTime|null $occurred_before Filter for event data that occurred before a specific datetime. (optional) + * @param int|null $object_id The ID of the CRM Object to filter event instances on. When including this parameter, you must also include the `objectType` parameter. (optional) + * @param object|null $object_property_propname Instead of retrieving event data for a specific object by its ID, you can specify a unique identifier property. For contacts, you can use the `email` property. (e.g., `objectProperty.email=name@domain.com`). (optional) + * @param object|null $property_propname Filter for event completions that contain a specific value for an event property (e.g., `property.hs_city=portland`). For properties values with spaces, replaces spaces with `%20` or `+` (e.g., `property.hs_city=new+york`). (optional) + * @param string[]|null $id ID of an event instance. IDs are 1:1 with event instances. If you provide this filter and additional filters, the other filters must match the values on the event instance to yield results. (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getPage'] to see the possible values for this operation * * @throws \HubSpot\Client\Events\ApiException on non-2xx response or if the response body is not in the expected format @@ -157,20 +157,20 @@ public function getPage($object_type = null, $event_type = null, $after = null, /** * Operation getPageWithHttpInfo * - * Event Instance Query + * Retrieve event data * - * @param string $object_type The CRM Object type name to filter event instances on. Optionally, you can also provide an objectId in another param to filter to a specific CRM Object instance. (optional) - * @param string $event_type The event type name. A list of available event type names can be obtained from another API call. (optional) - * @param string $after The paging cursor token of the last successfully read resource will be returned as the `paging.next.after` JSON property of a paged response containing more results. (optional) - * @param string $before (optional) - * @param int $limit The maximum number of results to display per page. (optional) - * @param string[] $sort Sort direction based on the timestamp of the event instance, ASCENDING or DESCENDING. (optional) - * @param \DateTime $occurred_after (optional) - * @param \DateTime $occurred_before (optional) - * @param int $object_id The ID of the CRM Object to filter event instances on. If filtering on objectId, you must also provide an objectType. (optional) - * @param object $object_property_propname (optional) - * @param object $property_propname (optional) - * @param string[] $id ID of an event instance. IDs are 1:1 with event instances. If you. provide this filter and additional filters, the other filters must match the values on the event instance to yield results. (optional) + * @param string|null $object_type The type of CRM object to filter event instances on (e.g., `contact`). To retrieve event data for a specific CRM record, include the additional `objectId` query parameter (below). (optional) + * @param string|null $event_type The event type name. You can retrieve available event types using the [event types endpoint](#get-%2Fevents%2Fv3%2Fevents%2Fevent-types). (optional) + * @param string|null $after The paging cursor token of the last successfully read resource will be returned as the `paging.next.after` JSON property of a paged response containing more results. (optional) + * @param string|null $before (optional) + * @param int|null $limit The maximum number of results to display per page. (optional) + * @param string[]|null $sort Sort direction based on the timestamp of the event instance, `ASCENDING` or `DESCENDING`. (optional) + * @param \DateTime|null $occurred_after Filter for event data that occurred after a specific datetime. (optional) + * @param \DateTime|null $occurred_before Filter for event data that occurred before a specific datetime. (optional) + * @param int|null $object_id The ID of the CRM Object to filter event instances on. When including this parameter, you must also include the `objectType` parameter. (optional) + * @param object|null $object_property_propname Instead of retrieving event data for a specific object by its ID, you can specify a unique identifier property. For contacts, you can use the `email` property. (e.g., `objectProperty.email=name@domain.com`). (optional) + * @param object|null $property_propname Filter for event completions that contain a specific value for an event property (e.g., `property.hs_city=portland`). For properties values with spaces, replaces spaces with `%20` or `+` (e.g., `property.hs_city=new+york`). (optional) + * @param string[]|null $id ID of an event instance. IDs are 1:1 with event instances. If you provide this filter and additional filters, the other filters must match the values on the event instance to yield results. (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getPage'] to see the possible values for this operation * * @throws \HubSpot\Client\Events\ApiException on non-2xx response or if the response body is not in the expected format @@ -203,18 +203,6 @@ public function getPageWithHttpInfo($object_type = null, $event_type = null, $af $statusCode = $response->getStatusCode(); - if ($statusCode < 200 || $statusCode > 299) { - throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - (string) $request->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() - ); - } switch($statusCode) { case 200: @@ -273,6 +261,19 @@ public function getPageWithHttpInfo($object_type = null, $event_type = null, $af ]; } + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + $returnType = '\HubSpot\Client\Events\Model\CollectionResponseExternalUnifiedEvent'; if ($returnType === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer @@ -327,20 +328,20 @@ public function getPageWithHttpInfo($object_type = null, $event_type = null, $af /** * Operation getPageAsync * - * Event Instance Query + * Retrieve event data * - * @param string $object_type The CRM Object type name to filter event instances on. Optionally, you can also provide an objectId in another param to filter to a specific CRM Object instance. (optional) - * @param string $event_type The event type name. A list of available event type names can be obtained from another API call. (optional) - * @param string $after The paging cursor token of the last successfully read resource will be returned as the `paging.next.after` JSON property of a paged response containing more results. (optional) - * @param string $before (optional) - * @param int $limit The maximum number of results to display per page. (optional) - * @param string[] $sort Sort direction based on the timestamp of the event instance, ASCENDING or DESCENDING. (optional) - * @param \DateTime $occurred_after (optional) - * @param \DateTime $occurred_before (optional) - * @param int $object_id The ID of the CRM Object to filter event instances on. If filtering on objectId, you must also provide an objectType. (optional) - * @param object $object_property_propname (optional) - * @param object $property_propname (optional) - * @param string[] $id ID of an event instance. IDs are 1:1 with event instances. If you. provide this filter and additional filters, the other filters must match the values on the event instance to yield results. (optional) + * @param string|null $object_type The type of CRM object to filter event instances on (e.g., `contact`). To retrieve event data for a specific CRM record, include the additional `objectId` query parameter (below). (optional) + * @param string|null $event_type The event type name. You can retrieve available event types using the [event types endpoint](#get-%2Fevents%2Fv3%2Fevents%2Fevent-types). (optional) + * @param string|null $after The paging cursor token of the last successfully read resource will be returned as the `paging.next.after` JSON property of a paged response containing more results. (optional) + * @param string|null $before (optional) + * @param int|null $limit The maximum number of results to display per page. (optional) + * @param string[]|null $sort Sort direction based on the timestamp of the event instance, `ASCENDING` or `DESCENDING`. (optional) + * @param \DateTime|null $occurred_after Filter for event data that occurred after a specific datetime. (optional) + * @param \DateTime|null $occurred_before Filter for event data that occurred before a specific datetime. (optional) + * @param int|null $object_id The ID of the CRM Object to filter event instances on. When including this parameter, you must also include the `objectType` parameter. (optional) + * @param object|null $object_property_propname Instead of retrieving event data for a specific object by its ID, you can specify a unique identifier property. For contacts, you can use the `email` property. (e.g., `objectProperty.email=name@domain.com`). (optional) + * @param object|null $property_propname Filter for event completions that contain a specific value for an event property (e.g., `property.hs_city=portland`). For properties values with spaces, replaces spaces with `%20` or `+` (e.g., `property.hs_city=new+york`). (optional) + * @param string[]|null $id ID of an event instance. IDs are 1:1 with event instances. If you provide this filter and additional filters, the other filters must match the values on the event instance to yield results. (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getPage'] to see the possible values for this operation * * @throws \InvalidArgumentException @@ -359,20 +360,20 @@ function ($response) { /** * Operation getPageAsyncWithHttpInfo * - * Event Instance Query + * Retrieve event data * - * @param string $object_type The CRM Object type name to filter event instances on. Optionally, you can also provide an objectId in another param to filter to a specific CRM Object instance. (optional) - * @param string $event_type The event type name. A list of available event type names can be obtained from another API call. (optional) - * @param string $after The paging cursor token of the last successfully read resource will be returned as the `paging.next.after` JSON property of a paged response containing more results. (optional) - * @param string $before (optional) - * @param int $limit The maximum number of results to display per page. (optional) - * @param string[] $sort Sort direction based on the timestamp of the event instance, ASCENDING or DESCENDING. (optional) - * @param \DateTime $occurred_after (optional) - * @param \DateTime $occurred_before (optional) - * @param int $object_id The ID of the CRM Object to filter event instances on. If filtering on objectId, you must also provide an objectType. (optional) - * @param object $object_property_propname (optional) - * @param object $property_propname (optional) - * @param string[] $id ID of an event instance. IDs are 1:1 with event instances. If you. provide this filter and additional filters, the other filters must match the values on the event instance to yield results. (optional) + * @param string|null $object_type The type of CRM object to filter event instances on (e.g., `contact`). To retrieve event data for a specific CRM record, include the additional `objectId` query parameter (below). (optional) + * @param string|null $event_type The event type name. You can retrieve available event types using the [event types endpoint](#get-%2Fevents%2Fv3%2Fevents%2Fevent-types). (optional) + * @param string|null $after The paging cursor token of the last successfully read resource will be returned as the `paging.next.after` JSON property of a paged response containing more results. (optional) + * @param string|null $before (optional) + * @param int|null $limit The maximum number of results to display per page. (optional) + * @param string[]|null $sort Sort direction based on the timestamp of the event instance, `ASCENDING` or `DESCENDING`. (optional) + * @param \DateTime|null $occurred_after Filter for event data that occurred after a specific datetime. (optional) + * @param \DateTime|null $occurred_before Filter for event data that occurred before a specific datetime. (optional) + * @param int|null $object_id The ID of the CRM Object to filter event instances on. When including this parameter, you must also include the `objectType` parameter. (optional) + * @param object|null $object_property_propname Instead of retrieving event data for a specific object by its ID, you can specify a unique identifier property. For contacts, you can use the `email` property. (e.g., `objectProperty.email=name@domain.com`). (optional) + * @param object|null $property_propname Filter for event completions that contain a specific value for an event property (e.g., `property.hs_city=portland`). For properties values with spaces, replaces spaces with `%20` or `+` (e.g., `property.hs_city=new+york`). (optional) + * @param string[]|null $id ID of an event instance. IDs are 1:1 with event instances. If you provide this filter and additional filters, the other filters must match the values on the event instance to yield results. (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getPage'] to see the possible values for this operation * * @throws \InvalidArgumentException @@ -422,18 +423,18 @@ function ($exception) { /** * Create request for operation 'getPage' * - * @param string $object_type The CRM Object type name to filter event instances on. Optionally, you can also provide an objectId in another param to filter to a specific CRM Object instance. (optional) - * @param string $event_type The event type name. A list of available event type names can be obtained from another API call. (optional) - * @param string $after The paging cursor token of the last successfully read resource will be returned as the `paging.next.after` JSON property of a paged response containing more results. (optional) - * @param string $before (optional) - * @param int $limit The maximum number of results to display per page. (optional) - * @param string[] $sort Sort direction based on the timestamp of the event instance, ASCENDING or DESCENDING. (optional) - * @param \DateTime $occurred_after (optional) - * @param \DateTime $occurred_before (optional) - * @param int $object_id The ID of the CRM Object to filter event instances on. If filtering on objectId, you must also provide an objectType. (optional) - * @param object $object_property_propname (optional) - * @param object $property_propname (optional) - * @param string[] $id ID of an event instance. IDs are 1:1 with event instances. If you. provide this filter and additional filters, the other filters must match the values on the event instance to yield results. (optional) + * @param string|null $object_type The type of CRM object to filter event instances on (e.g., `contact`). To retrieve event data for a specific CRM record, include the additional `objectId` query parameter (below). (optional) + * @param string|null $event_type The event type name. You can retrieve available event types using the [event types endpoint](#get-%2Fevents%2Fv3%2Fevents%2Fevent-types). (optional) + * @param string|null $after The paging cursor token of the last successfully read resource will be returned as the `paging.next.after` JSON property of a paged response containing more results. (optional) + * @param string|null $before (optional) + * @param int|null $limit The maximum number of results to display per page. (optional) + * @param string[]|null $sort Sort direction based on the timestamp of the event instance, `ASCENDING` or `DESCENDING`. (optional) + * @param \DateTime|null $occurred_after Filter for event data that occurred after a specific datetime. (optional) + * @param \DateTime|null $occurred_before Filter for event data that occurred before a specific datetime. (optional) + * @param int|null $object_id The ID of the CRM Object to filter event instances on. When including this parameter, you must also include the `objectType` parameter. (optional) + * @param object|null $object_property_propname Instead of retrieving event data for a specific object by its ID, you can specify a unique identifier property. For contacts, you can use the `email` property. (e.g., `objectProperty.email=name@domain.com`). (optional) + * @param object|null $property_propname Filter for event completions that contain a specific value for an event property (e.g., `property.hs_city=portland`). For properties values with spaces, replaces spaces with `%20` or `+` (e.g., `property.hs_city=new+york`). (optional) + * @param string[]|null $id ID of an event instance. IDs are 1:1 with event instances. If you provide this filter and additional filters, the other filters must match the values on the event instance to yield results. (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getPage'] to see the possible values for this operation * * @throws \InvalidArgumentException @@ -685,18 +686,6 @@ public function getTypesWithHttpInfo(string $contentType = self::contentTypes['g $statusCode = $response->getStatusCode(); - if ($statusCode < 200 || $statusCode > 299) { - throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - (string) $request->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() - ); - } switch($statusCode) { case 200: @@ -755,6 +744,19 @@ public function getTypesWithHttpInfo(string $contentType = self::contentTypes['g ]; } + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + $returnType = '\HubSpot\Client\Events\Model\VisibleExternalEventTypeNames'; if ($returnType === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer diff --git a/codegen/Events/ApiException.php b/codegen/Events/ApiException.php index b56a76c9c..8c33b1876 100644 --- a/codegen/Events/ApiException.php +++ b/codegen/Events/ApiException.php @@ -16,7 +16,7 @@ * * The version of the OpenAPI document: v3 * Generated by: https://openapi-generator.tech - * OpenAPI Generator version: 7.3.0 + * Generator version: 7.12.0 */ /** @@ -49,7 +49,7 @@ class ApiException extends Exception /** * The HTTP header of the server response. * - * @var string[]|null + * @var string[][]|null */ protected $responseHeaders; @@ -65,7 +65,7 @@ class ApiException extends Exception * * @param string $message Error message * @param int $code HTTP status code - * @param string[]|null $responseHeaders HTTP response header + * @param string[][]|null $responseHeaders HTTP response header * @param \stdClass|string|null $responseBody HTTP decoded body of the server response either as \stdClass or string */ public function __construct($message = "", $code = 0, $responseHeaders = [], $responseBody = null) @@ -78,7 +78,7 @@ public function __construct($message = "", $code = 0, $responseHeaders = [], $re /** * Gets the HTTP response header * - * @return string[]|null HTTP response header + * @return string[][]|null HTTP response header */ public function getResponseHeaders() { diff --git a/codegen/Events/Configuration.php b/codegen/Events/Configuration.php index 4a3add48b..c0feffb09 100644 --- a/codegen/Events/Configuration.php +++ b/codegen/Events/Configuration.php @@ -16,7 +16,7 @@ * * The version of the OpenAPI document: v3 * Generated by: https://openapi-generator.tech - * OpenAPI Generator version: 7.3.0 + * Generator version: 7.12.0 */ /** @@ -486,7 +486,7 @@ public function getHostSettings() * @param array|null $variables hash of variable and the corresponding value (optional) * @return string URL based on host settings */ - public static function getHostString(array $hostSettings, $hostIndex, array $variables = null) + public static function getHostString(array $hostSettings, $hostIndex, ?array $variables = null) { if (null === $variables) { $variables = []; diff --git a/codegen/Events/HeaderSelector.php b/codegen/Events/HeaderSelector.php index 5e235ccca..5ecdd7e23 100644 --- a/codegen/Events/HeaderSelector.php +++ b/codegen/Events/HeaderSelector.php @@ -16,7 +16,7 @@ * * The version of the OpenAPI document: v3 * Generated by: https://openapi-generator.tech - * OpenAPI Generator version: 7.3.0 + * Generator version: 7.12.0 */ /** @@ -85,7 +85,7 @@ private function selectAcceptHeader(array $accept): ?string } # If none of the available Accept headers is of type "json", then just use all them - $headersWithJson = preg_grep('~(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$~', $accept); + $headersWithJson = $this->selectJsonMimeList($accept); if (count($headersWithJson) === 0) { return implode(',', $accept); } @@ -95,6 +95,34 @@ private function selectAcceptHeader(array $accept): ?string return $this->getAcceptHeaderWithAdjustedWeight($accept, $headersWithJson); } + /** + * Detects whether a string contains a valid JSON mime type + * + * @param string $searchString + * @return bool + */ + public function isJsonMime(string $searchString): bool + { + return preg_match('~^application/(json|[\w!#$&.+-^_]+\+json)\s*(;|$)~', $searchString) === 1; + } + + /** + * Select all items from a list containing a JSON mime type + * + * @param array $mimeList + * @return array + */ + private function selectJsonMimeList(array $mimeList): array { + $jsonMimeList = []; + foreach ($mimeList as $mime) { + if($this->isJsonMime($mime)) { + $jsonMimeList[] = $mime; + } + } + return $jsonMimeList; + } + + /** * Create an Accept header string from the given "Accept" headers array, recalculating all weights * diff --git a/codegen/Events/Model/CollectionResponseExternalUnifiedEvent.php b/codegen/Events/Model/CollectionResponseExternalUnifiedEvent.php index db71a36b6..7a27dccc2 100644 --- a/codegen/Events/Model/CollectionResponseExternalUnifiedEvent.php +++ b/codegen/Events/Model/CollectionResponseExternalUnifiedEvent.php @@ -17,7 +17,7 @@ * * The version of the OpenAPI document: v3 * Generated by: https://openapi-generator.tech - * OpenAPI Generator version: 7.3.0 + * Generator version: 7.12.0 */ /** @@ -245,10 +245,10 @@ public function getModelName() /** * Constructor * - * @param mixed[] $data Associated array of property values + * @param mixed[]|null $data Associated array of property values * initializing the model */ - public function __construct(array $data = null) + public function __construct(?array $data = null) { $this->setIfExists('paging', $data ?? [], null); $this->setIfExists('results', $data ?? [], null); diff --git a/codegen/Events/Model/Error.php b/codegen/Events/Model/Error.php index 831450082..897753cec 100644 --- a/codegen/Events/Model/Error.php +++ b/codegen/Events/Model/Error.php @@ -17,7 +17,7 @@ * * The version of the OpenAPI document: v3 * Generated by: https://openapi-generator.tech - * OpenAPI Generator version: 7.3.0 + * Generator version: 7.12.0 */ /** @@ -275,10 +275,10 @@ public function getModelName() /** * Constructor * - * @param mixed[] $data Associated array of property values + * @param mixed[]|null $data Associated array of property values * initializing the model */ - public function __construct(array $data = null) + public function __construct(?array $data = null) { $this->setIfExists('sub_category', $data ?? [], null); $this->setIfExists('context', $data ?? [], null); diff --git a/codegen/Events/Model/ErrorDetail.php b/codegen/Events/Model/ErrorDetail.php index 8fa88d454..1ece8c463 100644 --- a/codegen/Events/Model/ErrorDetail.php +++ b/codegen/Events/Model/ErrorDetail.php @@ -17,7 +17,7 @@ * * The version of the OpenAPI document: v3 * Generated by: https://openapi-generator.tech - * OpenAPI Generator version: 7.3.0 + * Generator version: 7.12.0 */ /** @@ -263,10 +263,10 @@ public function getModelName() /** * Constructor * - * @param mixed[] $data Associated array of property values + * @param mixed[]|null $data Associated array of property values * initializing the model */ - public function __construct(array $data = null) + public function __construct(?array $data = null) { $this->setIfExists('sub_category', $data ?? [], null); $this->setIfExists('code', $data ?? [], null); diff --git a/codegen/Events/Model/ExternalUnifiedEvent.php b/codegen/Events/Model/ExternalUnifiedEvent.php index af6bef09d..44f0e022a 100644 --- a/codegen/Events/Model/ExternalUnifiedEvent.php +++ b/codegen/Events/Model/ExternalUnifiedEvent.php @@ -17,7 +17,7 @@ * * The version of the OpenAPI document: v3 * Generated by: https://openapi-generator.tech - * OpenAPI Generator version: 7.3.0 + * Generator version: 7.12.0 */ /** @@ -269,10 +269,10 @@ public function getModelName() /** * Constructor * - * @param mixed[] $data Associated array of property values + * @param mixed[]|null $data Associated array of property values * initializing the model */ - public function __construct(array $data = null) + public function __construct(?array $data = null) { $this->setIfExists('occurred_at', $data ?? [], null); $this->setIfExists('event_type', $data ?? [], null); diff --git a/codegen/Events/Model/ModelInterface.php b/codegen/Events/Model/ModelInterface.php index 61bd97609..956030e8c 100644 --- a/codegen/Events/Model/ModelInterface.php +++ b/codegen/Events/Model/ModelInterface.php @@ -17,7 +17,7 @@ * * The version of the OpenAPI document: v3 * Generated by: https://openapi-generator.tech - * OpenAPI Generator version: 7.3.0 + * Generator version: 7.12.0 */ /** diff --git a/codegen/Events/Model/NextPage.php b/codegen/Events/Model/NextPage.php index d6d4e1677..cb6fef516 100644 --- a/codegen/Events/Model/NextPage.php +++ b/codegen/Events/Model/NextPage.php @@ -17,7 +17,7 @@ * * The version of the OpenAPI document: v3 * Generated by: https://openapi-generator.tech - * OpenAPI Generator version: 7.3.0 + * Generator version: 7.12.0 */ /** @@ -245,10 +245,10 @@ public function getModelName() /** * Constructor * - * @param mixed[] $data Associated array of property values + * @param mixed[]|null $data Associated array of property values * initializing the model */ - public function __construct(array $data = null) + public function __construct(?array $data = null) { $this->setIfExists('link', $data ?? [], null); $this->setIfExists('after', $data ?? [], null); diff --git a/codegen/Events/Model/Paging.php b/codegen/Events/Model/Paging.php index dfc89528d..0b7817ad5 100644 --- a/codegen/Events/Model/Paging.php +++ b/codegen/Events/Model/Paging.php @@ -17,7 +17,7 @@ * * The version of the OpenAPI document: v3 * Generated by: https://openapi-generator.tech - * OpenAPI Generator version: 7.3.0 + * Generator version: 7.12.0 */ /** @@ -245,10 +245,10 @@ public function getModelName() /** * Constructor * - * @param mixed[] $data Associated array of property values + * @param mixed[]|null $data Associated array of property values * initializing the model */ - public function __construct(array $data = null) + public function __construct(?array $data = null) { $this->setIfExists('next', $data ?? [], null); $this->setIfExists('prev', $data ?? [], null); diff --git a/codegen/Events/Model/PreviousPage.php b/codegen/Events/Model/PreviousPage.php index 498d11195..a74f0dbb5 100644 --- a/codegen/Events/Model/PreviousPage.php +++ b/codegen/Events/Model/PreviousPage.php @@ -17,7 +17,7 @@ * * The version of the OpenAPI document: v3 * Generated by: https://openapi-generator.tech - * OpenAPI Generator version: 7.3.0 + * Generator version: 7.12.0 */ /** @@ -245,10 +245,10 @@ public function getModelName() /** * Constructor * - * @param mixed[] $data Associated array of property values + * @param mixed[]|null $data Associated array of property values * initializing the model */ - public function __construct(array $data = null) + public function __construct(?array $data = null) { $this->setIfExists('before', $data ?? [], null); $this->setIfExists('link', $data ?? [], null); diff --git a/codegen/Events/Model/VisibleExternalEventTypeNames.php b/codegen/Events/Model/VisibleExternalEventTypeNames.php index 969221b04..3a8c20dc8 100644 --- a/codegen/Events/Model/VisibleExternalEventTypeNames.php +++ b/codegen/Events/Model/VisibleExternalEventTypeNames.php @@ -17,7 +17,7 @@ * * The version of the OpenAPI document: v3 * Generated by: https://openapi-generator.tech - * OpenAPI Generator version: 7.3.0 + * Generator version: 7.12.0 */ /** @@ -239,10 +239,10 @@ public function getModelName() /** * Constructor * - * @param mixed[] $data Associated array of property values + * @param mixed[]|null $data Associated array of property values * initializing the model */ - public function __construct(array $data = null) + public function __construct(?array $data = null) { $this->setIfExists('event_types', $data ?? [], null); } diff --git a/codegen/Events/ObjectSerializer.php b/codegen/Events/ObjectSerializer.php index 59dfe9f47..000cf5ee1 100644 --- a/codegen/Events/ObjectSerializer.php +++ b/codegen/Events/ObjectSerializer.php @@ -17,7 +17,7 @@ * * The version of the OpenAPI document: v3 * Generated by: https://openapi-generator.tech - * OpenAPI Generator version: 7.3.0 + * Generator version: 7.12.0 */ /** @@ -58,8 +58,8 @@ public static function setDateTimeFormat($format) * Serialize data * * @param mixed $data the data to serialize - * @param string $type the OpenAPIToolsType of the data - * @param string $format the format of the OpenAPITools type of the data + * @param string|null $type the OpenAPIToolsType of the data + * @param string|null $format the format of the OpenAPITools type of the data * * @return scalar|object|array|null serialized form of $data */ @@ -194,6 +194,10 @@ private static function isEmptyValue($value, string $openApiType): bool case 'boolean': return !in_array($value, [false, 0], true); + # For string values, '' is considered empty. + case 'string': + return $value === ''; + # For all the other types, any value at this point can be considered empty. default: return true; @@ -265,6 +269,11 @@ public static function toQueryValue( $value = $flattenArray($value, $paramName); + // https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#style-values + if ($openApiType === 'array' && $style === 'deepObject' && $explode) { + return $value; + } + if ($openApiType === 'object' && ($style === 'deepObject' || $explode)) { return $value; } @@ -338,7 +347,7 @@ public static function toFormValue($value) * If it's a datetime object, format it in ISO8601 * If it's a boolean, convert it to "true" or "false". * - * @param string|bool|\DateTime $value the value of the parameter + * @param float|int|bool|\DateTime $value the value of the parameter * * @return string the header string */ @@ -395,8 +404,7 @@ public static function serializeCollection(array $collection, $style, $allowColl * * @param mixed $data object or primitive to be deserialized * @param string $class class name is passed as a string - * @param string[] $httpHeaders HTTP headers - * @param string $discriminator discriminator if polymorphism is used + * @param string[]|null $httpHeaders HTTP headers * * @return object|array|null a single or an array of $class instances */ @@ -473,7 +481,7 @@ public static function deserialize($data, $class, $httpHeaders = null) // determine file name if ( is_array($httpHeaders) - && array_key_exists('Content-Disposition', $httpHeaders) + && array_key_exists('Content-Disposition', $httpHeaders) && preg_match('/inline; filename=[\'"]?([^\'"\s]+)[\'"]?$/i', $httpHeaders['Content-Disposition'], $match) ) { $filename = Configuration::getDefaultConfiguration()->getTempFolderPath() . DIRECTORY_SEPARATOR . self::sanitizeFilename($match[1]); @@ -546,22 +554,64 @@ public static function deserialize($data, $class, $httpHeaders = null) } /** - * Native `http_build_query` wrapper. - * @see https://www.php.net/manual/en/function.http-build-query - * - * @param array|object $data May be an array or object containing properties. - * @param string $numeric_prefix If numeric indices are used in the base array and this parameter is provided, it will be prepended to the numeric index for elements in the base array only. - * @param string|null $arg_separator arg_separator.output is used to separate arguments but may be overridden by specifying this parameter. - * @param int $encoding_type Encoding type. By default, PHP_QUERY_RFC1738. - * - * @return string - */ - public static function buildQuery( - $data, - string $numeric_prefix = '', - ?string $arg_separator = null, - int $encoding_type = \PHP_QUERY_RFC3986 - ): string { - return \GuzzleHttp\Psr7\Query::build($data, $encoding_type); + * Build a query string from an array of key value pairs. + * + * This function can use the return value of `parse()` to build a query + * string. This function does not modify the provided keys when an array is + * encountered (like `http_build_query()` would). + * + * The function is copied from https://github.com/guzzle/psr7/blob/a243f80a1ca7fe8ceed4deee17f12c1930efe662/src/Query.php#L59-L112 + * with a modification which is described in https://github.com/guzzle/psr7/pull/603 + * + * @param array $params Query string parameters. + * @param int|false $encoding Set to false to not encode, PHP_QUERY_RFC3986 + * to encode using RFC3986, or PHP_QUERY_RFC1738 + * to encode using RFC1738. + */ + public static function buildQuery(array $params, $encoding = PHP_QUERY_RFC3986): string + { + if (!$params) { + return ''; + } + + if ($encoding === false) { + $encoder = function (string $str): string { + return $str; + }; + } elseif ($encoding === PHP_QUERY_RFC3986) { + $encoder = 'rawurlencode'; + } elseif ($encoding === PHP_QUERY_RFC1738) { + $encoder = 'urlencode'; + } else { + throw new \InvalidArgumentException('Invalid type'); + } + + $castBool = Configuration::BOOLEAN_FORMAT_INT == Configuration::getDefaultConfiguration()->getBooleanFormatForQueryString() + ? function ($v) { return (int) $v; } + : function ($v) { return $v ? 'true' : 'false'; }; + + $qs = ''; + foreach ($params as $k => $v) { + $k = $encoder((string) $k); + if (!is_array($v)) { + $qs .= $k; + $v = is_bool($v) ? $castBool($v) : $v; + if ($v !== null) { + $qs .= '='.$encoder((string) $v); + } + $qs .= '&'; + } else { + foreach ($v as $vv) { + $qs .= $k; + $vv = is_bool($vv) ? $castBool($vv) : $vv; + if ($vv !== null) { + $qs .= '='.$encoder((string) $vv); + } + $qs .= '&'; + } + } + } + + return $qs ? (string) substr($qs, 0, -1) : ''; } } diff --git a/codegen/Events/Send/Api/BasicApi.php b/codegen/Events/Send/Api/BasicApi.php index 5711e7e9c..d5ee60a86 100644 --- a/codegen/Events/Send/Api/BasicApi.php +++ b/codegen/Events/Send/Api/BasicApi.php @@ -16,7 +16,7 @@ * * The version of the OpenAPI document: v3 * Generated by: https://openapi-generator.tech - * OpenAPI Generator version: 7.3.0 + * Generator version: 7.12.0 */ /** @@ -83,13 +83,13 @@ class BasicApi * @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec */ public function __construct( - ClientInterface $client = null, - Configuration $config = null, - HeaderSelector $selector = null, - $hostIndex = 0 + ?ClientInterface $client = null, + ?Configuration $config = null, + ?HeaderSelector $selector = null, + int $hostIndex = 0 ) { $this->client = $client ?: new Client(); - $this->config = $config ?: new Configuration(); + $this->config = $config ?: Configuration::getDefaultConfiguration(); $this->headerSelector = $selector ?: new HeaderSelector(); $this->hostIndex = $hostIndex; } @@ -177,18 +177,6 @@ public function sendWithHttpInfo($behavioral_event_http_completion_request, stri $statusCode = $response->getStatusCode(); - if ($statusCode < 200 || $statusCode > 299) { - throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - (string) $request->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() - ); - } return [null, $statusCode, $response->getHeaders()]; diff --git a/codegen/Events/Send/Api/BatchApi.php b/codegen/Events/Send/Api/BatchApi.php index cb79cd5f8..321f6e887 100644 --- a/codegen/Events/Send/Api/BatchApi.php +++ b/codegen/Events/Send/Api/BatchApi.php @@ -16,7 +16,7 @@ * * The version of the OpenAPI document: v3 * Generated by: https://openapi-generator.tech - * OpenAPI Generator version: 7.3.0 + * Generator version: 7.12.0 */ /** @@ -83,13 +83,13 @@ class BatchApi * @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec */ public function __construct( - ClientInterface $client = null, - Configuration $config = null, - HeaderSelector $selector = null, - $hostIndex = 0 + ?ClientInterface $client = null, + ?Configuration $config = null, + ?HeaderSelector $selector = null, + int $hostIndex = 0 ) { $this->client = $client ?: new Client(); - $this->config = $config ?: new Configuration(); + $this->config = $config ?: Configuration::getDefaultConfiguration(); $this->headerSelector = $selector ?: new HeaderSelector(); $this->hostIndex = $hostIndex; } @@ -177,18 +177,6 @@ public function sendWithHttpInfo($batched_behavioral_event_http_completion_reque $statusCode = $response->getStatusCode(); - if ($statusCode < 200 || $statusCode > 299) { - throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - (string) $request->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() - ); - } return [null, $statusCode, $response->getHeaders()]; diff --git a/codegen/Events/Send/ApiException.php b/codegen/Events/Send/ApiException.php index 546f0223e..54995f53a 100644 --- a/codegen/Events/Send/ApiException.php +++ b/codegen/Events/Send/ApiException.php @@ -16,7 +16,7 @@ * * The version of the OpenAPI document: v3 * Generated by: https://openapi-generator.tech - * OpenAPI Generator version: 7.3.0 + * Generator version: 7.12.0 */ /** @@ -49,7 +49,7 @@ class ApiException extends Exception /** * The HTTP header of the server response. * - * @var string[]|null + * @var string[][]|null */ protected $responseHeaders; @@ -65,7 +65,7 @@ class ApiException extends Exception * * @param string $message Error message * @param int $code HTTP status code - * @param string[]|null $responseHeaders HTTP response header + * @param string[][]|null $responseHeaders HTTP response header * @param \stdClass|string|null $responseBody HTTP decoded body of the server response either as \stdClass or string */ public function __construct($message = "", $code = 0, $responseHeaders = [], $responseBody = null) @@ -78,7 +78,7 @@ public function __construct($message = "", $code = 0, $responseHeaders = [], $re /** * Gets the HTTP response header * - * @return string[]|null HTTP response header + * @return string[][]|null HTTP response header */ public function getResponseHeaders() { diff --git a/codegen/Events/Send/Configuration.php b/codegen/Events/Send/Configuration.php index ea6b73539..9e89fa6df 100644 --- a/codegen/Events/Send/Configuration.php +++ b/codegen/Events/Send/Configuration.php @@ -16,7 +16,7 @@ * * The version of the OpenAPI document: v3 * Generated by: https://openapi-generator.tech - * OpenAPI Generator version: 7.3.0 + * Generator version: 7.12.0 */ /** @@ -486,7 +486,7 @@ public function getHostSettings() * @param array|null $variables hash of variable and the corresponding value (optional) * @return string URL based on host settings */ - public static function getHostString(array $hostSettings, $hostIndex, array $variables = null) + public static function getHostString(array $hostSettings, $hostIndex, ?array $variables = null) { if (null === $variables) { $variables = []; diff --git a/codegen/Events/Send/HeaderSelector.php b/codegen/Events/Send/HeaderSelector.php index ce963eddf..89a6000e8 100644 --- a/codegen/Events/Send/HeaderSelector.php +++ b/codegen/Events/Send/HeaderSelector.php @@ -16,7 +16,7 @@ * * The version of the OpenAPI document: v3 * Generated by: https://openapi-generator.tech - * OpenAPI Generator version: 7.3.0 + * Generator version: 7.12.0 */ /** @@ -85,7 +85,7 @@ private function selectAcceptHeader(array $accept): ?string } # If none of the available Accept headers is of type "json", then just use all them - $headersWithJson = preg_grep('~(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$~', $accept); + $headersWithJson = $this->selectJsonMimeList($accept); if (count($headersWithJson) === 0) { return implode(',', $accept); } @@ -95,6 +95,34 @@ private function selectAcceptHeader(array $accept): ?string return $this->getAcceptHeaderWithAdjustedWeight($accept, $headersWithJson); } + /** + * Detects whether a string contains a valid JSON mime type + * + * @param string $searchString + * @return bool + */ + public function isJsonMime(string $searchString): bool + { + return preg_match('~^application/(json|[\w!#$&.+-^_]+\+json)\s*(;|$)~', $searchString) === 1; + } + + /** + * Select all items from a list containing a JSON mime type + * + * @param array $mimeList + * @return array + */ + private function selectJsonMimeList(array $mimeList): array { + $jsonMimeList = []; + foreach ($mimeList as $mime) { + if($this->isJsonMime($mime)) { + $jsonMimeList[] = $mime; + } + } + return $jsonMimeList; + } + + /** * Create an Accept header string from the given "Accept" headers array, recalculating all weights * diff --git a/codegen/Events/Send/Model/BatchedBehavioralEventHttpCompletionRequest.php b/codegen/Events/Send/Model/BatchedBehavioralEventHttpCompletionRequest.php index 001909cb4..4342d7254 100644 --- a/codegen/Events/Send/Model/BatchedBehavioralEventHttpCompletionRequest.php +++ b/codegen/Events/Send/Model/BatchedBehavioralEventHttpCompletionRequest.php @@ -17,7 +17,7 @@ * * The version of the OpenAPI document: v3 * Generated by: https://openapi-generator.tech - * OpenAPI Generator version: 7.3.0 + * Generator version: 7.12.0 */ /** @@ -239,10 +239,10 @@ public function getModelName() /** * Constructor * - * @param mixed[] $data Associated array of property values + * @param mixed[]|null $data Associated array of property values * initializing the model */ - public function __construct(array $data = null) + public function __construct(?array $data = null) { $this->setIfExists('inputs', $data ?? [], null); } diff --git a/codegen/Events/Send/Model/BehavioralEventHttpCompletionRequest.php b/codegen/Events/Send/Model/BehavioralEventHttpCompletionRequest.php index fcde6d23e..e9e62d995 100644 --- a/codegen/Events/Send/Model/BehavioralEventHttpCompletionRequest.php +++ b/codegen/Events/Send/Model/BehavioralEventHttpCompletionRequest.php @@ -17,7 +17,7 @@ * * The version of the OpenAPI document: v3 * Generated by: https://openapi-generator.tech - * OpenAPI Generator version: 7.3.0 + * Generator version: 7.12.0 */ /** @@ -275,10 +275,10 @@ public function getModelName() /** * Constructor * - * @param mixed[] $data Associated array of property values + * @param mixed[]|null $data Associated array of property values * initializing the model */ - public function __construct(array $data = null) + public function __construct(?array $data = null) { $this->setIfExists('occurred_at', $data ?? [], null); $this->setIfExists('event_name', $data ?? [], null); diff --git a/codegen/Events/Send/Model/Error.php b/codegen/Events/Send/Model/Error.php index 3b6aa5abd..95f0407a1 100644 --- a/codegen/Events/Send/Model/Error.php +++ b/codegen/Events/Send/Model/Error.php @@ -17,7 +17,7 @@ * * The version of the OpenAPI document: v3 * Generated by: https://openapi-generator.tech - * OpenAPI Generator version: 7.3.0 + * Generator version: 7.12.0 */ /** @@ -275,10 +275,10 @@ public function getModelName() /** * Constructor * - * @param mixed[] $data Associated array of property values + * @param mixed[]|null $data Associated array of property values * initializing the model */ - public function __construct(array $data = null) + public function __construct(?array $data = null) { $this->setIfExists('sub_category', $data ?? [], null); $this->setIfExists('context', $data ?? [], null); diff --git a/codegen/Events/Send/Model/ErrorDetail.php b/codegen/Events/Send/Model/ErrorDetail.php index 7925b09e9..2751ca405 100644 --- a/codegen/Events/Send/Model/ErrorDetail.php +++ b/codegen/Events/Send/Model/ErrorDetail.php @@ -17,7 +17,7 @@ * * The version of the OpenAPI document: v3 * Generated by: https://openapi-generator.tech - * OpenAPI Generator version: 7.3.0 + * Generator version: 7.12.0 */ /** @@ -263,10 +263,10 @@ public function getModelName() /** * Constructor * - * @param mixed[] $data Associated array of property values + * @param mixed[]|null $data Associated array of property values * initializing the model */ - public function __construct(array $data = null) + public function __construct(?array $data = null) { $this->setIfExists('sub_category', $data ?? [], null); $this->setIfExists('code', $data ?? [], null); diff --git a/codegen/Events/Send/Model/ModelInterface.php b/codegen/Events/Send/Model/ModelInterface.php index a9c080373..a74b8eba9 100644 --- a/codegen/Events/Send/Model/ModelInterface.php +++ b/codegen/Events/Send/Model/ModelInterface.php @@ -17,7 +17,7 @@ * * The version of the OpenAPI document: v3 * Generated by: https://openapi-generator.tech - * OpenAPI Generator version: 7.3.0 + * Generator version: 7.12.0 */ /** diff --git a/codegen/Events/Send/ObjectSerializer.php b/codegen/Events/Send/ObjectSerializer.php index b89a3f1d5..784f89cf9 100644 --- a/codegen/Events/Send/ObjectSerializer.php +++ b/codegen/Events/Send/ObjectSerializer.php @@ -17,7 +17,7 @@ * * The version of the OpenAPI document: v3 * Generated by: https://openapi-generator.tech - * OpenAPI Generator version: 7.3.0 + * Generator version: 7.12.0 */ /** @@ -58,8 +58,8 @@ public static function setDateTimeFormat($format) * Serialize data * * @param mixed $data the data to serialize - * @param string $type the OpenAPIToolsType of the data - * @param string $format the format of the OpenAPITools type of the data + * @param string|null $type the OpenAPIToolsType of the data + * @param string|null $format the format of the OpenAPITools type of the data * * @return scalar|object|array|null serialized form of $data */ @@ -194,6 +194,10 @@ private static function isEmptyValue($value, string $openApiType): bool case 'boolean': return !in_array($value, [false, 0], true); + # For string values, '' is considered empty. + case 'string': + return $value === ''; + # For all the other types, any value at this point can be considered empty. default: return true; @@ -265,6 +269,11 @@ public static function toQueryValue( $value = $flattenArray($value, $paramName); + // https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#style-values + if ($openApiType === 'array' && $style === 'deepObject' && $explode) { + return $value; + } + if ($openApiType === 'object' && ($style === 'deepObject' || $explode)) { return $value; } @@ -338,7 +347,7 @@ public static function toFormValue($value) * If it's a datetime object, format it in ISO8601 * If it's a boolean, convert it to "true" or "false". * - * @param string|bool|\DateTime $value the value of the parameter + * @param float|int|bool|\DateTime $value the value of the parameter * * @return string the header string */ @@ -395,8 +404,7 @@ public static function serializeCollection(array $collection, $style, $allowColl * * @param mixed $data object or primitive to be deserialized * @param string $class class name is passed as a string - * @param string[] $httpHeaders HTTP headers - * @param string $discriminator discriminator if polymorphism is used + * @param string[]|null $httpHeaders HTTP headers * * @return object|array|null a single or an array of $class instances */ @@ -473,7 +481,7 @@ public static function deserialize($data, $class, $httpHeaders = null) // determine file name if ( is_array($httpHeaders) - && array_key_exists('Content-Disposition', $httpHeaders) + && array_key_exists('Content-Disposition', $httpHeaders) && preg_match('/inline; filename=[\'"]?([^\'"\s]+)[\'"]?$/i', $httpHeaders['Content-Disposition'], $match) ) { $filename = Configuration::getDefaultConfiguration()->getTempFolderPath() . DIRECTORY_SEPARATOR . self::sanitizeFilename($match[1]); @@ -546,22 +554,64 @@ public static function deserialize($data, $class, $httpHeaders = null) } /** - * Native `http_build_query` wrapper. - * @see https://www.php.net/manual/en/function.http-build-query - * - * @param array|object $data May be an array or object containing properties. - * @param string $numeric_prefix If numeric indices are used in the base array and this parameter is provided, it will be prepended to the numeric index for elements in the base array only. - * @param string|null $arg_separator arg_separator.output is used to separate arguments but may be overridden by specifying this parameter. - * @param int $encoding_type Encoding type. By default, PHP_QUERY_RFC1738. - * - * @return string - */ - public static function buildQuery( - $data, - string $numeric_prefix = '', - ?string $arg_separator = null, - int $encoding_type = \PHP_QUERY_RFC3986 - ): string { - return \GuzzleHttp\Psr7\Query::build($data, $encoding_type); + * Build a query string from an array of key value pairs. + * + * This function can use the return value of `parse()` to build a query + * string. This function does not modify the provided keys when an array is + * encountered (like `http_build_query()` would). + * + * The function is copied from https://github.com/guzzle/psr7/blob/a243f80a1ca7fe8ceed4deee17f12c1930efe662/src/Query.php#L59-L112 + * with a modification which is described in https://github.com/guzzle/psr7/pull/603 + * + * @param array $params Query string parameters. + * @param int|false $encoding Set to false to not encode, PHP_QUERY_RFC3986 + * to encode using RFC3986, or PHP_QUERY_RFC1738 + * to encode using RFC1738. + */ + public static function buildQuery(array $params, $encoding = PHP_QUERY_RFC3986): string + { + if (!$params) { + return ''; + } + + if ($encoding === false) { + $encoder = function (string $str): string { + return $str; + }; + } elseif ($encoding === PHP_QUERY_RFC3986) { + $encoder = 'rawurlencode'; + } elseif ($encoding === PHP_QUERY_RFC1738) { + $encoder = 'urlencode'; + } else { + throw new \InvalidArgumentException('Invalid type'); + } + + $castBool = Configuration::BOOLEAN_FORMAT_INT == Configuration::getDefaultConfiguration()->getBooleanFormatForQueryString() + ? function ($v) { return (int) $v; } + : function ($v) { return $v ? 'true' : 'false'; }; + + $qs = ''; + foreach ($params as $k => $v) { + $k = $encoder((string) $k); + if (!is_array($v)) { + $qs .= $k; + $v = is_bool($v) ? $castBool($v) : $v; + if ($v !== null) { + $qs .= '='.$encoder((string) $v); + } + $qs .= '&'; + } else { + foreach ($v as $vv) { + $qs .= $k; + $vv = is_bool($vv) ? $castBool($vv) : $vv; + if ($vv !== null) { + $qs .= '='.$encoder((string) $vv); + } + $qs .= '&'; + } + } + } + + return $qs ? (string) substr($qs, 0, -1) : ''; } }