Skip to content
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

Fix codegen for nullable types #131

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/hip-experts-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"fingerprint-pro-server-api-php-sdk": patch
---

Mark nullable types as an optional, will fix #123
8 changes: 4 additions & 4 deletions src/Model/SeenAt.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public function valid(): bool
/**
* Gets global.
*/
public function getGlobal(): \DateTime
public function getGlobal(): ?\DateTime
{
return $this->container['global'];
}
Expand All @@ -214,7 +214,7 @@ public function getGlobal(): \DateTime
*
* @return $this
*/
public function setGlobal(\DateTime $global): self
public function setGlobal(?\DateTime $global): self
{
$this->container['global'] = $global;

Expand All @@ -224,7 +224,7 @@ public function setGlobal(\DateTime $global): self
/**
* Gets subscription.
*/
public function getSubscription(): \DateTime
public function getSubscription(): ?\DateTime
{
return $this->container['subscription'];
}
Expand All @@ -236,7 +236,7 @@ public function getSubscription(): \DateTime
*
* @return $this
*/
public function setSubscription(\DateTime $subscription): self
public function setSubscription(?\DateTime $subscription): self
{
$this->container['subscription'] = $subscription;

Expand Down
4 changes: 2 additions & 2 deletions template/model_generic.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}{{^pa
* Gets {{name}}
* @return {{^required}}?{{/required}}{{datatype}}
*/
public function {{getter}}(): {{^required}}?{{/required}}{{^isListContainer}}{{^isMapContainer}}{{^isDouble}}{{datatype}}{{/isDouble}}{{/isMapContainer}}{{/isListContainer}}{{#isListContainer}}array{{/isListContainer}}{{#isMapContainer}}array{{/isMapContainer}}{{#isDouble}}float{{/isDouble}}
public function {{getter}}(): {{^required}}?{{/required}}{{#required}}{{#nullable}}?{{/nullable}}{{/required}}{{^isListContainer}}{{^isMapContainer}}{{^isDouble}}{{datatype}}{{/isDouble}}{{/isMapContainer}}{{/isListContainer}}{{#isListContainer}}array{{/isListContainer}}{{#isMapContainer}}array{{/isMapContainer}}{{#isDouble}}float{{/isDouble}}
{
return $this->container['{{name}}'];
}
Expand All @@ -260,7 +260,7 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}{{^pa
*
* @return $this
*/
public function {{setter}}({{^required}}?{{/required}}{{^isListContainer}}{{^isMapContainer}}{{^isDouble}}{{datatype}}{{/isDouble}}{{/isMapContainer}}{{/isListContainer}}{{#isListContainer}}array{{/isListContainer}}{{#isMapContainer}}array{{/isMapContainer}}{{#isDouble}}float{{/isDouble}} ${{name}}): self
public function {{setter}}({{^required}}?{{/required}}{{#required}}{{#nullable}}?{{/nullable}}{{/required}}{{^isListContainer}}{{^isMapContainer}}{{^isDouble}}{{datatype}}{{/isDouble}}{{/isMapContainer}}{{/isListContainer}}{{#isListContainer}}array{{/isListContainer}}{{#isMapContainer}}array{{/isMapContainer}}{{#isDouble}}float{{/isDouble}} ${{name}}): self
{
{{#isEnum}}
$allowedValues = $this->{{getter}}AllowableValues();
Expand Down
11 changes: 11 additions & 0 deletions test/FingerprintApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,17 @@ public function testGetEventRawResponse()
$this->assertEquals($mockedResult, \GuzzleHttp\json_decode($response->getBody()->getContents()));
}

public function testGetEventNullableSeenAt()
{
$this->mockHandler->reset();
$this->mockHandler->append($this->getMockResponse(self::MOCK_REQUEST_ID));

list($event, $response) = $this->fingerprint_api->getEvent(self::MOCK_REQUEST_ID);
$products = $event->getProducts();
$seenAt = $products->getIdentification()->getData()->getLastSeenAt();
$this->assertEquals(null, $seenAt->getGlobal());
}

public function testGetVisitsRawResponse()
{
$this->mockHandler->reset();
Expand Down
Loading