Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request represents the first iteration of upgrading the OpenAPI Generator. It introduces new code alongside the old version, which will be refined in subsequent iterations. The changes include adding and customizing Mustache templates, incorporating shared code, generating Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a significant upgrade to the OpenAPI generator, adding new shared classes like Configuration and BaseService, and generating the BinLookup API client. The changes are extensive and bring in modern PHP features. My review focuses on improving the new shared components and fixing some bugs in the generated code. I've identified a critical issue in the error handling within the new BinLookupApi client, along with some design concerns in the Configuration class and other bugs. The feedback provided aims to enhance the robustness, maintainability, and correctness of the new code.
Note: Security Review did not run due to the size of the PR.
|
| */ | ||
| public function __construct(Configuration $configuration) | ||
| { | ||
| if (!$configuration->getAdyenApiKey()) { |
There was a problem hiding this comment.
Are we making this change intentional ?
Because in the older version, we have
elseif ($service->requiresApiKey()) { $msg = "Please provide a valid Checkout API Key"; throw new AdyenException($msg);
in client where we depend on the flag passed by service to determine wether we need to validate API key
There was a problem hiding this comment.
Interesting. I don't think we should allow the option to skip API key validation. All our APIs are behind authentication.
I notice though that we don't have support for Basic Authentication, which is a legacy authentication but still relevant (according to the Docs).
We should introduce it, either here or create a new ticket for later.
| } | ||
| {{/isNullable}} | ||
| {{^isNullable}} | ||
| if (is_null(${{name}})) { |
There was a problem hiding this comment.
Is this stricter setter behavior an intentional breaking SDK change? Previously, setters accepted null, and the SDK did not automatically call valid() before sending a request
There was a problem hiding this comment.
Good point. In theory we shouldn't accept null unless the attribute is nullable, but this is a significant breaking change (as you point out 👍). The other important aspect is that we want to avoid validation in the SDKs (when possible) so we avoid drifting from the API (for example the API changes a property to be nullable but the merchants don't upgrade the SDK version).
This is the same reason why we don't call valid() before sending a request.
To summarise:
- remove validation of nullability (no longer throw the exception): we rely on the validation of the API
valid: consider if it is better to remove or make a comment
There was a problem hiding this comment.
Removed all the validation from SDK
b46c9fb to
2c4096c
Compare
| strategy: | ||
| matrix: | ||
| php-version: [ '7.3', '8.2', '8.4', '8.5' ] | ||
| php-version: [ '8.1', '8.2', '8.4' ] |
There was a problem hiding this comment.
Adds PHP 8.1 to the test matrix because it is the minimum PHP version declared by this branch.
| $headers | ||
| ); | ||
|
|
||
| $operationHost = $this->config->getHost() ?: $this->baseURL; |
There was a problem hiding this comment.
When no custom host was configured, getHost() returned an empty value and the generated request contains only a relative path. Guzzle cannot send this because it has no Adyen server address. Fall back to the BinLookup base URL to build a complete request URL while preserving any merchant-provided custom host.
There was a problem hiding this comment.
We need to revise this since custom hosts are not a supported merchant feature. API URLs are defined in createBaseUrl, and they support:
testandlivehost- for payments only we support a merchant prefix i.e.
https://abcdef-pal-live.adyenpayments.com
We should maybe cleanup the code to avoid even providing a custom host, to be investigated
| $operationHost = Configuration::getHostString($hostSettings, $hostIndex, $variables); | ||
| {{/servers.0}} | ||
| {{^servers.0}} | ||
| $operationHost = $this->config->getHost() ?: $this->baseURL; |
There was a problem hiding this comment.
Explanation here - https://github.com/Adyen/adyen-php-api-library/pull/897/changes#r3979488839
There was a problem hiding this comment.
See comment about custom host
| $headers | ||
| ); | ||
|
|
||
| $operationHost = $this->config->getHost() ?: $this->baseURL; |
There was a problem hiding this comment.
Explanation here - https://github.com/Adyen/adyen-php-api-library/pull/897/changes#r3979488839
There was a problem hiding this comment.
See comment about custom host
| if ($this->container['currency'] === null) { | ||
| $invalidProperties[] = "'currency' can't be null"; | ||
| } | ||
| if ($this->container['currency'] !== null && mb_strlen($this->container['currency']) > 3) { |
There was a problem hiding this comment.
A required property can still be null while a model is being validated. The validation method adds the correct “can’t be null” error but continues to the length checks. Calling mb_strlen(null) is deprecated in PHP 8.1+, so check that the value is not null before checking its length. Here
There was a problem hiding this comment.
Good work. The null guard is applied to maxLength/minLength, but the same issue appears in the template for pattern (preg_match(pattern, null), deprecated in PHP 8.1+) and maxItems/minItems (count(null), TypeError) when a required property is null.
Note that valid() and listInvalidProperties() are never called by the SDK itself, we should assess what's best:
- remove them (code is clearer and cleaner)
- leave them optional for merchants to use (to be mentioned in the README maybe)
If decide to go for option 2, we may need to revise all validations scenario, I suggest to create a new ticket for this step.
There was a problem hiding this comment.
Validation Removed
| {{/isEnum}} | ||
| {{#hasValidation}} | ||
| {{#maxLength}} | ||
| if ($this->container['{{name}}'] !== null && mb_strlen($this->container['{{name}}']) > {{maxLength}}) { |
There was a problem hiding this comment.
Explanation Here - https://github.com/Adyen/adyen-php-api-library/pull/897/changes#r3979377529
There was a problem hiding this comment.
See comment about validation above
There was a problem hiding this comment.
Validation Removed
| } | ||
| {{/maxLength}} | ||
| {{#minLength}} | ||
| if ($this->container['{{name}}'] !== null && mb_strlen($this->container['{{name}}']) < {{minLength}}) { |
There was a problem hiding this comment.
Explanation Here - https://github.com/Adyen/adyen-php-api-library/pull/897/changes#r3979377529
There was a problem hiding this comment.
See comment about validation above
There was a problem hiding this comment.
Validation Removed
| $this->assertEmpty($headers); | ||
| } | ||
|
|
||
| public function testRequestUsesBaseUrl() |
There was a problem hiding this comment.
Added a regression test for the missing-host case. It verifies that BinLookup creates a complete URL using its default base URL, rather than a relative endpoint path that Guzzle cannot send.
| * @throws \InvalidArgumentException | ||
| * @return \Adyen\Model\BinLookup\ThreeDSAvailabilityResponse | ||
| */ | ||
| public function get3dsAvailability(\Adyen\Model\BinLookup\ThreeDSAvailabilityRequest$threeDSAvailabilityRequest, ?\Adyen\RequestOptions $requestOptions = null): \Adyen\Model\BinLookup\ThreeDSAvailabilityResponse |
There was a problem hiding this comment.
There is an inconsistency across similar methods:
get3dsAvailability: main method, body requiredget3dsAvailabilityWithHttpInfo: WithHttpInfo variant, body optional and nullableget3dsAvailabilityRequest: request builder, body required and non-nullable
Methods could be aligned to define the body as required and non-nullable.
Unfortunately our specs don't mark the request body as required: true, so we cannot rely on the OpenAPI contract. We don't have a use case of a request with an empty body (for POST and PATCH), so we can assume here that we always need one.
There was a problem hiding this comment.
gcatanese
left a comment
There was a problem hiding this comment.
Great work @ashwaniarya-adyen, I left some comments, we need to iterate over few points, but overall it looks really good!
82a3216 to
8172c38
Compare
|



First iteration of the OpenAPI Generator upgrade:
Configuration,BaseService, etc...)BinlookUpservices and modelsBinlookUpto verify main use cases: initialise objects, send requests, add custom headers, throw exceptions upon4xx/5xxerrorsAt the moment the new code co-exist with the old version, therefore there is a bit of mix of approaches and code, I also had to disable few tests (to verify/refactor later). This will improve as we progress this migration.