Skip to content

Commit

Permalink
Merge pull request #32 from formancehq/speakeasy-sdk-regen-1724698337
Browse files Browse the repository at this point in the history
chore: 🐝 Update SDK - Generate
  • Loading branch information
gfyrag committed Aug 28, 2024
2 parents f076ff9 + 4a07f7e commit 6f1044f
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 75 deletions.
14 changes: 7 additions & 7 deletions .speakeasy/gen.lock
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
lockVersion: 2.0.0
id: 0b9e0548-6a63-426d-aa19-95795ea55543
management:
docChecksum: 36a0edca1ac6cc8ce47307d5bf152c5d
docVersion: v2.0.12
speakeasyVersion: 1.377.3
generationVersion: 2.404.2
releaseVersion: 2.2.2
configChecksum: 123fa0d8ccbfb91127717c9510c0b166
docChecksum: 5731933f0a0cf86c6725c3b2ac3a16e4
docVersion: v2.0.15
speakeasyVersion: 1.381.0
generationVersion: 2.404.9
releaseVersion: 2.2.5
configChecksum: b5c0df87c25f7af7b6e9abd1b78641e3
repoURL: https://github.com/formancehq/formance-sdk-php.git
repoSubDirectory: .
installationURL: https://github.com/formancehq/formance-sdk-php
published: true
features:
php:
core: 3.3.11
core: 3.3.14
deprecations: 2.81.1
errors: 0.1.1
getRequestBodies: 2.81.1
Expand Down
32 changes: 31 additions & 1 deletion RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,34 @@ Based on:
### Generated
- [php v2.2.2] .
### Releases
- [Composer v2.2.2] https://packagist.org/packages/formance/formance-sdk#v2.2.2 - .
- [Composer v2.2.2] https://packagist.org/packages/formance/formance-sdk#v2.2.2 - .

## 2024-08-26 18:52:14
### Changes
Based on:
- OpenAPI Doc v2.0.15
- Speakeasy CLI 1.379.0 (2.404.3) https://github.com/speakeasy-api/speakeasy
### Generated
- [php v2.2.3] .
### Releases
- [Composer v2.2.3] https://packagist.org/packages/formance/formance-sdk#v2.2.3 - .

## 2024-08-28 00:06:47
### Changes
Based on:
- OpenAPI Doc v2.0.15
- Speakeasy CLI 1.381.0 (2.404.9) https://github.com/speakeasy-api/speakeasy
### Generated
- [php v2.2.4] .
### Releases
- [Composer v2.2.4] https://packagist.org/packages/formance/formance-sdk#v2.2.4 - .

## 2024-08-28 08:02:17
### Changes
Based on:
- OpenAPI Doc v2.0.15
- Speakeasy CLI 1.381.0 (2.404.9) https://github.com/speakeasy-api/speakeasy
### Generated
- [php v2.2.5] .
### Releases
- [Composer v2.2.5] https://packagist.org/packages/formance/formance-sdk#v2.2.5 - .
8 changes: 1 addition & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,10 @@
}
},
"license": "MIT",
"repositories": [
{
"type": "git",
"url": "https://github.com/idbentley/serializer"
}
],
"require": {
"php": "^8.1",
"guzzlehttp/guzzle": "^7.0",
"jms/serializer": "dev-deserialize-unions",
"speakeasy/serializer": "^3.40.0",
"brick/date-time": "^0.7.0",
"phpdocumentor/type-resolver": "^1.8"
},
Expand Down
2 changes: 1 addition & 1 deletion gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ generation:
comments: {}
telemetryEnabled: false
php:
version: 2.2.2
version: 2.2.5
clientServerStatusCodesAsErrors: true
flattenGlobalSecurity: true
imports:
Expand Down
8 changes: 4 additions & 4 deletions src/SDKConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ class SDKConfiguration

public string $language = 'php';

public string $openapiDocVersion = 'v2.0.12';
public string $openapiDocVersion = 'v2.0.15';

public string $sdkVersion = '2.2.2';
public string $sdkVersion = '2.2.5';

public string $genVersion = '2.404.2';
public string $genVersion = '2.404.9';

public string $userAgent = 'speakeasy-sdk/php 2.2.2 2.404.2 v2.0.12 formance/formance-sdk';
public string $userAgent = 'speakeasy-sdk/php 2.2.5 2.404.9 v2.0.15 formance/formance-sdk';

public function getServerUrl(): string
{
Expand Down
112 changes: 57 additions & 55 deletions src/Utils/UnionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,82 +94,84 @@ public function deserializeUnion(DeserializationVisitorInterface $visitor, mixed
throw new RuntimeException('XML deserialisation into union types is not supported yet.');
}

// if three params exist, it may mean that there was a union discriminator set for this type.
// It also may mean that there are three possible types.
if (count($type['params']) == 3 && $this->paramsLookLikeUnionDiscriminator($type)) {
$lookupField = $type['params'][1];
if (empty($data[$lookupField])) {
throw new NonVisitableTypeException(sprintf('Union Discriminator Field "%s" not found in data', $lookupField));
}

$unionMap = $type['params'][2];
$lookupValue = $data[$lookupField];
if (empty($unionMap[$lookupValue])) {
throw new NonVisitableTypeException(sprintf('Union Discriminator Map does not contain key "%s"', $lookupValue));
}

$finalType = [
'name' => $unionMap[$lookupValue],
'params' => [],
];

$alternativeName = null;
return $context->getNavigator()->accept($data, $finalType);
}

foreach ($this->reorderTypes($type)['params'] as $possibleType) {
$propertyMetadata = $context->getMetadataStack()->top();
$finalType = null;
if ($propertyMetadata->unionDiscriminatorField !== null) {
if (! array_key_exists($propertyMetadata->unionDiscriminatorField, $data)) {
throw new NonVisitableTypeException('Union Discriminator Field \''.$propertyMetadata->unionDiscriminatorField.'\' not found in data');
}

$lkup = $data[$propertyMetadata->unionDiscriminatorField];
if (! empty($propertyMetadata->unionDiscriminatorMap)) {
if (array_key_exists($lkup, $propertyMetadata->unionDiscriminatorMap)) {
$finalType = [
'name' => $propertyMetadata->unionDiscriminatorMap[$lkup],
'params' => [],
];
} else {
throw new NonVisitableTypeException('Union Discriminator Map does not contain key \''.$lkup.'\'');
}
} else {
$finalType = [
'name' => $lkup,
'params' => [],
];
}
$typeToTry = $possibleType['name'];
if ($typeToTry === 'array') {
$typeNames = array_map(fn ($t) => $t['name'], $possibleType['params']);
$typeToTry = 'array<'.implode(', ', $typeNames).'>';
}

if ($finalType !== null && $finalType['name'] !== null) {
return $context->getNavigator()->accept($data, $finalType);
} else {
$typeToTry = $possibleType['name'];
if ($typeToTry === 'array') {
$typeNames = array_map(fn ($t) => $t['name'], $possibleType['params']);
$typeToTry = 'array<'.implode(', ', $typeNames).'>';
$serializer = JSON::createSerializer();
try {
if ($this->isPrimitiveType($possibleType['name']) && (is_array($data) || ! $this->testPrimitive($data, $possibleType['name']))) {
continue;
}
$serializer = JSON::createSerializer();
try {
if ($this->isPrimitiveType($possibleType['name']) && (is_array($data) || ! $this->testPrimitive($data, $possibleType['name']))) {
continue;
}

$json_encoded_data = json_encode($data);
if ($json_encoded_data === false) {
throw new RuntimeException('Failed to encode data to JSON: '.json_last_error_msg());
}
$accept = $serializer->deserialize($json_encoded_data, $typeToTry, 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true));

return $accept;
} catch (NonVisitableTypeException $e) {
continue;
} catch (PropertyMissingException $e) {
continue;
} catch (NonStringCastableTypeException $e) {
continue;
} catch (NonIntCastableTypeException $e) {
continue;
} catch (NonFloatCastableTypeException $e) {
continue;
$json_encoded_data = json_encode($data);
if ($json_encoded_data === false) {
throw new RuntimeException('Failed to encode data to JSON: '.json_last_error_msg());
}
$accept = $serializer->deserialize($json_encoded_data, $typeToTry, 'json', DeserializationContext::create()->setRequireAllRequiredProperties(true));

return $accept;
} catch (NonVisitableTypeException $e) {
continue;
} catch (PropertyMissingException $e) {
continue;
} catch (NonStringCastableTypeException $e) {
continue;
} catch (NonIntCastableTypeException $e) {
continue;
} catch (NonFloatCastableTypeException $e) {
continue;
}
}

return null;
}

/**
* @param array<string, mixed> $type
* @return bool
*/
private function paramsLookLikeUnionDiscriminator(array $type): bool
{
// if the first param is null, then the second and third parameters
// will contain the discriminator details.
$first = $type['params'][0];

return $first === null;
}

/**
* @param mixed $data
* @param array<string, mixed> $type
* @param Context $context
*/
private function matchSimpleType(mixed $data, array $type, Context $context): mixed
{
$alternativeName = null;

foreach ($type['params'] as $possibleType) {
if ($this->isPrimitiveType($possibleType['name']) && ! $this->testPrimitive($data, $possibleType['name'])) {
continue;
Expand Down

0 comments on commit 6f1044f

Please sign in to comment.