-
Notifications
You must be signed in to change notification settings - Fork 7
Feature/new request handling logic inter 767 #96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/new request handling logic inter 767 #96
Conversation
b5f338d
to
26e984f
Compare
BREAKING CHANGE: Request logic is rewritten, Upgraded minimum php version to 8.1
Question: when exception is thrown, do we include a HTTP Response in it (if it is available)? |
Hey @TheUnderScorer For your question:
Yes, you can use an optional method called |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for these changes @Orkuncakilkaya! It looks a lot better now.
We can still improve the request handling code by a bit. I have couple of suggestions:
fingerprint-pro-server-api-php-sdk/src/Api/FingerprintApi.php
Lines 141 to 149 in 91c550e
$responseBody = $response->getBody(); if ($returnType === '\SplFileObject') { $content = $responseBody; //stream goes to serializer } else { $content = $responseBody->getContents(); if (!in_array($returnType, ['string','integer','bool'])) { $content = json_decode($content); } } fingerprint-pro-server-api-php-sdk/src/Api/FingerprintApi.php
Lines 255 to 269 in 91c550e
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(), $response->getBody() ); } ); fingerprint-pro-server-api-php-sdk/src/Api/FingerprintApi.php
Lines 309 to 318 in 91c550e
if ($multipart) { $headers = $this->headerSelector->selectHeadersForMultipart( ['application/json'] ); } else { $headers = $this->headerSelector->selectHeaders( ['application/json'], [] ); } HeaderSelector
all togetherfingerprint-pro-server-api-php-sdk/src/Api/FingerprintApi.php
Lines 321 to 347 in 91c550e
if (isset($_tempBody)) { // $_tempBody is the method argument, if present $httpBody = $_tempBody; // \stdClass has no __toString(), so we should encode it manually if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode($httpBody); } } elseif (count($formParams) > 0) { if ($multipart) { $multipartContents = []; foreach ($formParams as $formParamName => $formParamValue) { $multipartContents[] = [ 'name' => $formParamName, 'contents' => $formParamValue ]; } // for HTTP post (form) $httpBody = new MultipartStream($multipartContents); } elseif ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode($formParams); } else { // for HTTP post (form) $httpBody = http_build_query($formParams); } } \stdClass
that is not needed.
These code snippets are from getEvent
operation, but this applies to all other request as well. Overall, please double-check if there is more code that we can simplify/remove 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for these changes @Orkuncakilkaya. The code looks much better now!
I have couple of more suggestions/notes:
fingerprint-pro-server-api-php-sdk/src/Api/FingerprintApi.php
Lines 275 to 281 in 5daa81c
if ($request_id !== null) { | |
$resourcePath = str_replace( | |
'{' . 'request_id' . '}', | |
ObjectSerializer::toPathValue($request_id), | |
$resourcePath | |
); | |
} |
This check is reduntant, because we perform the same check couple of lines above. Applies to all API methods.
Also, pls take a look at the async methods. It seems we still don't map status code to correct error response there as we do in the sync methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more suggestion:
fingerprint-pro-server-api-php-sdk/src/ObjectSerializer.php
Lines 320 to 339 in 66d9015
$discriminator = $class::DISCRIMINATOR; | |
if (!empty($discriminator) && isset($data->{$discriminator}) && is_string($data->{$discriminator})) { | |
$subclass = 'Fingerprint\ServerAPI\Model\\' . $data->{$discriminator}; | |
if (is_subclass_of($subclass, $class)) { | |
$class = $subclass; | |
} | |
} | |
$instance = new $class(); | |
foreach ($instance::swaggerTypes() as $property => $type) { | |
$propertySetter = $instance::setters()[$property]; | |
if (!isset($propertySetter) || !isset($data->{$instance::attributeMap()[$property]})) { | |
continue; | |
} | |
$propertyValue = $data->{$instance::attributeMap()[$property]}; | |
if (isset($propertyValue)) { | |
$instance->$propertySetter(self::deserialize($propertyValue, $type, null)); | |
} | |
} |
From what I see, in all models
DISCRIMINATOR
is set to null, can we remove it from models and from here?
BREAKING CHANGE: API Methods returns tuple instead of models BREAKING CHANGE: API Methods removed other than `getModel`
0037c70
to
62e4ad3
Compare
BREAKING CHANGE: API Methods now throws `SerializationException`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lots of great changes, thanks @Orkuncakilkaya! We're getting close to the finish 🙂
Co-authored-by: Przemysław Żydek <przemyslawzydek@gmail.com>
This PR will create a major release 🚀5.0.0 (2024-07-26)⚠ BREAKING CHANGES
Features
|
No description provided.