Skip to content

Commit

Permalink
feat: introduce rawResponse for getVisits and getEvent methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Orkuncakilkaya committed Jul 16, 2024
1 parent d62eac6 commit 9b01ba6
Show file tree
Hide file tree
Showing 9 changed files with 877 additions and 64 deletions.
4 changes: 3 additions & 1 deletion .swagger-codegen-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ src/.php_cs
src/git_push.sh
src/test/**
src/Api/FingerprintApi.php
src/HeaderSelector.php
src/HeaderSelector.php
src/Model/EventResponse.php
src/Model/Response.php
18 changes: 14 additions & 4 deletions run_checks.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,32 @@

try {
$result = $client->getVisits($visitor_id);
fwrite(STDOUT, sprintf("Got visits: %s \n", $result));
$rawResponseDecoded = json_decode($result->getRawResponse(), true);
if ($rawResponseDecoded['visitorId'] !== $visitor_id) {
fwrite(STDERR, sprintf("Raw response for getVisits not working"));
exit(1);
}
fwrite(STDOUT, sprintf("Got visits: %s \n", $result->getRawResponse()));
} catch (Exception $e) {
fwrite(STDERR, sprintf("Exception when calling FingerprintApi->getVisits: %s\n", $e->getMessage()));
exit(1);
}

try {
$result = $client->getEvent($request_id);
fwrite(STDOUT, sprintf("Got event: %s \n", $result));
$rawResponseDecoded = json_decode($result->getRawResponse(), true);
if ($rawResponseDecoded['products']['identification']['data']['requestId'] !== $request_id) {
fwrite(STDERR, sprintf("Raw response for getEvent not working"));
exit(1);
}
fwrite(STDOUT, sprintf("\n\nGot event: %s \n", $result->getRawResponse()));
} catch (Exception $e) {
fwrite(STDERR, sprintf("Exception when calling FingerprintApi->getVisits: %s\n", $e->getMessage()));
fwrite(STDERR, sprintf("\n\nException when calling FingerprintApi->getVisits: %s\n", $e->getMessage()));
exit(1);
}

// Enable the deprecated ArrayAccess return type warning again if needed
error_reporting(error_reporting() | E_DEPRECATED);

fwrite(STDOUT, "Checks passed\n");
fwrite(STDOUT, "\n\nChecks passed\n");
exit(0);
2 changes: 2 additions & 0 deletions scripts/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,5 @@ mv -f src/composer.json composer.json
find ./docs -type f ! -name "DecryptionKey.md" ! -name "Sealed.md" -exec rm {} +
mv -f src/docs/* ./docs
cp template/docs/FingerprintApi.md docs/Api
cp template/Model/Response.php.template src/Model/Response.php
cp template/Model/EventResponse.php.template src/Model/EventResponse.php
2 changes: 2 additions & 0 deletions src/Api/FingerprintApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public function getEvent(string $request_id): EventResponse
$content = $response->getBody()->getContents();
/** @var EventResponse $serialized */
$serialized = ObjectSerializer::deserialize($content, EventResponse::class, []);
$serialized->setRawResponse($content);

return $serialized;
}
Expand Down Expand Up @@ -134,6 +135,7 @@ public function getVisits(string $visitor_id, string|null $request_id = null, st
$content = $response->getBody()->getContents();
/** @var Response $serialized */
$serialized = ObjectSerializer::deserialize($content, Response::class, []);
$serialized->setRawResponse($content);

return $serialized;
}
Expand Down
55 changes: 34 additions & 21 deletions src/Model/EventResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* Generated by: https://github.com/swagger-api/swagger-codegen.git
* Swagger Codegen version: 3.0.34
*/

/**
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen
Expand All @@ -28,8 +29,9 @@

namespace Fingerprint\ServerAPI\Model;

use \ArrayAccess;
use \Fingerprint\ServerAPI\ObjectSerializer;
use ArrayAccess;
use Fingerprint\ServerAPI\Model\ModelInterface;
use Fingerprint\ServerAPI\ObjectSerializer;

/**
* EventResponse Class Doc Comment
Expand All @@ -43,31 +45,32 @@
class EventResponse implements ModelInterface, ArrayAccess
{
const DISCRIMINATOR = null;
protected mixed $rawResponse = null;

/**
* The original name of the model.
*
* @var string
*/
* The original name of the model.
*
* @var string
*/
protected static $swaggerModelName = 'EventResponse';

/**
* Array of property to type mappings. Used for (de)serialization
*
* @var string[]
*/
* Array of property to type mappings. Used for (de)serialization
*
* @var string[]
*/
protected static $swaggerTypes = [
'products' => '\Fingerprint\ServerAPI\Model\ProductsResponse',
'error' => '\Fingerprint\ServerAPI\Model\ProductError' ];
'error' => '\Fingerprint\ServerAPI\Model\ProductError'];

/**
* Array of property to format mappings. Used for (de)serialization
*
* @var string[]
*/
* Array of property to format mappings. Used for (de)serialization
*
* @var string[]
*/
protected static $swaggerFormats = [
'products' => null,
'error' => null ];
'error' => null];

/**
* Array of property to type mappings. Used for (de)serialization
Expand Down Expand Up @@ -97,7 +100,7 @@ public static function swaggerFormats()
*/
protected static $attributeMap = [
'products' => 'products',
'error' => 'error' ];
'error' => 'error'];

/**
* Array of attributes to setter functions (for deserialization of responses)
Expand All @@ -106,7 +109,7 @@ public static function swaggerFormats()
*/
protected static $setters = [
'products' => 'setProducts',
'error' => 'setError' ];
'error' => 'setError'];

/**
* Array of attributes to getter functions (for serialization of requests)
Expand All @@ -115,7 +118,7 @@ public static function swaggerFormats()
*/
protected static $getters = [
'products' => 'getProducts',
'error' => 'getError' ];
'error' => 'getError'];

/**
* Array of attributes where the key is the local name,
Expand Down Expand Up @@ -158,7 +161,6 @@ public function getModelName()
return self::$swaggerModelName;
}



/**
* Associative array for storing property values
Expand Down Expand Up @@ -253,6 +255,7 @@ public function setError($error)

return $this;
}

/**
* Returns true if offset exists. False otherwise.
*
Expand Down Expand Up @@ -283,7 +286,7 @@ public function offsetGet($offset)
* Sets value based on offset.
*
* @param integer $offset Offset
* @param mixed $value Value to be set
* @param mixed $value Value to be set
*
* @return void
*/
Expand Down Expand Up @@ -326,4 +329,14 @@ public function __toString()

return json_encode(ObjectSerializer::sanitizeForSerialization($this));
}

public function getRawResponse(): mixed
{
return $this->rawResponse;
}

public function setRawResponse(mixed $rawResponse): void
{
$this->rawResponse = $rawResponse;
}
}
77 changes: 46 additions & 31 deletions src/Model/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,19 @@
* Generated by: https://github.com/swagger-api/swagger-codegen.git
* Swagger Codegen version: 3.0.34
*/

/**
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen
* Do not edit the class manually.
*/


namespace Fingerprint\ServerAPI\Model;

use \ArrayAccess;
use \Fingerprint\ServerAPI\ObjectSerializer;
use ArrayAccess;
use Fingerprint\ServerAPI\Model\ModelInterface;
use Fingerprint\ServerAPI\ObjectSerializer;

/**
* Response Class Doc Comment
Expand All @@ -44,34 +47,36 @@ class Response implements ModelInterface, ArrayAccess
{
const DISCRIMINATOR = null;

protected mixed $rawResponse = null;

/**
* The original name of the model.
*
* @var string
*/
* The original name of the model.
*
* @var string
*/
protected static $swaggerModelName = 'Response';

/**
* Array of property to type mappings. Used for (de)serialization
*
* @var string[]
*/
* Array of property to type mappings. Used for (de)serialization
*
* @var string[]
*/
protected static $swaggerTypes = [
'visitor_id' => 'string',
'visits' => '\Fingerprint\ServerAPI\Model\ResponseVisits[]',
'last_timestamp' => 'int',
'pagination_key' => 'string' ];
'visits' => '\Fingerprint\ServerAPI\Model\ResponseVisits[]',
'last_timestamp' => 'int',
'pagination_key' => 'string'];

/**
* Array of property to format mappings. Used for (de)serialization
*
* @var string[]
*/
* Array of property to format mappings. Used for (de)serialization
*
* @var string[]
*/
protected static $swaggerFormats = [
'visitor_id' => null,
'visits' => null,
'last_timestamp' => 'int64',
'pagination_key' => null ];
'visits' => null,
'last_timestamp' => 'int64',
'pagination_key' => null];

/**
* Array of property to type mappings. Used for (de)serialization
Expand Down Expand Up @@ -101,9 +106,9 @@ public static function swaggerFormats()
*/
protected static $attributeMap = [
'visitor_id' => 'visitorId',
'visits' => 'visits',
'last_timestamp' => 'lastTimestamp',
'pagination_key' => 'paginationKey' ];
'visits' => 'visits',
'last_timestamp' => 'lastTimestamp',
'pagination_key' => 'paginationKey'];

/**
* Array of attributes to setter functions (for deserialization of responses)
Expand All @@ -112,9 +117,9 @@ public static function swaggerFormats()
*/
protected static $setters = [
'visitor_id' => 'setVisitorId',
'visits' => 'setVisits',
'last_timestamp' => 'setLastTimestamp',
'pagination_key' => 'setPaginationKey' ];
'visits' => 'setVisits',
'last_timestamp' => 'setLastTimestamp',
'pagination_key' => 'setPaginationKey'];

/**
* Array of attributes to getter functions (for serialization of requests)
Expand All @@ -123,9 +128,9 @@ public static function swaggerFormats()
*/
protected static $getters = [
'visitor_id' => 'getVisitorId',
'visits' => 'getVisits',
'last_timestamp' => 'getLastTimestamp',
'pagination_key' => 'getPaginationKey' ];
'visits' => 'getVisits',
'last_timestamp' => 'getLastTimestamp',
'pagination_key' => 'getPaginationKey'];

/**
* Array of attributes where the key is the local name,
Expand Down Expand Up @@ -168,7 +173,6 @@ public function getModelName()
return self::$swaggerModelName;
}



/**
* Associative array for storing property values
Expand Down Expand Up @@ -316,6 +320,7 @@ public function setPaginationKey($pagination_key)

return $this;
}

/**
* Returns true if offset exists. False otherwise.
*
Expand Down Expand Up @@ -346,7 +351,7 @@ public function offsetGet($offset)
* Sets value based on offset.
*
* @param integer $offset Offset
* @param mixed $value Value to be set
* @param mixed $value Value to be set
*
* @return void
*/
Expand Down Expand Up @@ -389,4 +394,14 @@ public function __toString()

return json_encode(ObjectSerializer::sanitizeForSerialization($this));
}

public function getRawResponse(): mixed
{
return $this->rawResponse;
}

public function setRawResponse(mixed $rawResponse): void
{
$this->rawResponse = $rawResponse;
}
}
Loading

0 comments on commit 9b01ba6

Please sign in to comment.