Skip to content

Commit a367392

Browse files
authored
Merge pull request #163 from php-api-clients/fix-bugs-in-abstractions
Fix bugs in abstractions
2 parents f190e95 + a237b67 commit a367392

File tree

31 files changed

+743
-54
lines changed

31 files changed

+743
-54
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
etc/qa/.phpcs.cache
2+
etc/qa/.phpunit.result.cache
23
bin/openapi-client-generator
34
example/etc
45
example/generated-github

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,6 @@ generate-example-client-subsplit:
7474

7575
generate-example-client-miele:
7676
$(DOCKER_RUN) php ./bin/openapi-client-generator ./example/openapi-client-miele.yaml
77+
78+
generate-test-client:
79+
$(DOCKER_RUN) php ./bin/openapi-client-generator ./tests/openapi-client-petstore.yaml

src/Gatherer/Property.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,6 @@ static function ($matches) {
8181
$required,
8282
$schemaRegistry,
8383
);
84-
if ($type->payload instanceof Representation\Schema) {
85-
if (count($type->payload->properties) === 0) {
86-
$type = new Representation\PropertyType('scalar', null, null, 'string', false);
87-
}
88-
} elseif ($type->payload instanceof Representation\PropertyType && $type->payload->payload instanceof Representation\Schema) {
89-
if (count($type->payload->payload->properties) === 0) {
90-
$type = new Representation\PropertyType('scalar', null, null, 'string', false);
91-
}
92-
}
9384

9485
if ($property->type === 'array' && is_array($type->payload)) {
9586
$arrayItemsRaw = [];

src/Generator.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,10 +300,24 @@ private function all(string $configurationLocation): iterable
300300
if (count($this->spec->components->schemas ?? []) > 0) {
301301
/** @phpstan-ignore-next-line */
302302
$this->statusOutput->itemForStep('gathering_schemas', count($this->spec->components->schemas));
303-
/** @phpstan-ignore-next-line */
303+
/**
304+
* Do this loop twice to ensure we added all schemas to the schema registry BEFORE we start to gather them
305+
* which will trigger looking up schemas as properties and end up with weird naming.
306+
*
307+
* @phpstan-ignore-next-line
308+
*/
304309
foreach ($this->spec->components->schemas as $name => $schema) {
305310
assert($schema instanceof \cebe\openapi\spec\Schema);
306311
$schemaRegistry->addClassName(Utils::className($name), $schema);
312+
}
313+
314+
/**
315+
* Gather all the schemas now that we've added all of them to the schema registry.
316+
*
317+
* @phpstan-ignore-next-line
318+
*/
319+
foreach ($this->spec->components->schemas as $name => $schema) {
320+
assert($schema instanceof \cebe\openapi\spec\Schema);
307321
$schemas[] = Gatherer\Schema::gather($this->configuration->namespace, Utils::className($name), $schema, $schemaRegistry);
308322
$this->statusOutput->advanceStep('gathering_schemas');
309323
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"specHash":"3c7554a486c24f245f9719c34ea626d6","generatedFiles":{"files":[{"name":".\/tests\/app\/src\/\/Operation\/ListPets.php","hash":"9665866b6a2bc4319602f483df07da0a"},{"name":".\/tests\/app\/src\/\/Operator\/ListPets.php","hash":"e45ae1f18117ff22d7f2e181ebaa33b4"},{"name":".\/tests\/app\/tests\/\/Operation\/ListPetsTest.php","hash":"1a69a3dbe5fa57f23e6c3903e2ee1466"},{"name":".\/tests\/app\/src\/\/Operation\/CreatePets.php","hash":"09b0a4db052acf5770eefef5f99cdb1e"},{"name":".\/tests\/app\/src\/\/Operator\/CreatePets.php","hash":"ed0f9aef989011ca02c334d1c82458b6"},{"name":".\/tests\/app\/tests\/\/Operation\/CreatePetsTest.php","hash":"167c901d84419d8414b83fe25c4b8180"},{"name":".\/tests\/app\/src\/\/Operation\/ShowPetById.php","hash":"ee7fd99d534864e5f61564402ba045a1"},{"name":".\/tests\/app\/src\/\/Operator\/ShowPetById.php","hash":"8160552bcb97d414deb82596e0b9de59"},{"name":".\/tests\/app\/tests\/\/Operation\/ShowPetByIdTest.php","hash":"57247dfe62086528b74633a61ff924bd"},{"name":".\/tests\/app\/src\/\/Schema\/Cat.php","hash":"bf15a87926c1ac209e1f57f1e983a46c"},{"name":".\/tests\/app\/src\/\/Schema\/Dog.php","hash":"6cdde38b49def17458c7f61ab3c8b1f9"},{"name":".\/tests\/app\/src\/\/Schema\/Bird.php","hash":"2fbd8ed5566456b734f17792da47cfe0"},{"name":".\/tests\/app\/src\/\/Schema\/Fish.php","hash":"f0c6b8afc61bc6f19970ed3b8c201132"},{"name":".\/tests\/app\/src\/\/Schema\/Pets.php","hash":"41a18bbb55cd7efca6d48f913cb15f11"},{"name":".\/tests\/app\/src\/\/Schema\/Error.php","hash":"71c7f411eb38324a6a3f4b3e59c3a88a"},{"name":".\/tests\/app\/src\/\/Error\/Error.php","hash":"f0d0ba9484e1e17337da019e786a537b"},{"name":".\/tests\/app\/src\/\/Schema\/Operations\/ListPets\/Response\/ApplicationJson\/Ok.php","hash":"f0e4ffe1b265a68bf2c750e3e2f2e128"},{"name":".\/tests\/app\/src\/\/Schema\/AliasAbstract\/TietD65BC5E9\/Tiet6F251EDA\/Tiet699DECD9\/TietD8B901F6.php","hash":"ab3ce2fba8383c3983ae8bc8ff106092"},{"name":".\/tests\/app\/src\/\/Schema\/Operations\/ShowPetById\/Response\/ApplicationJson\/Ok.php","hash":"ad27d7f6ddd2024bbf7ec66d45222fe4"},{"name":".\/tests\/app\/src\/\/Schema\/CreatePets\/Request\/ApplicationJson.php","hash":"3c476af789ae0ae6d1616cf8ce03c644"},{"name":".\/tests\/app\/src\/\/ClientInterface.php","hash":"13065e8b46e5e3b67723c5c4fb9ea8b6"},{"name":".\/tests\/app\/src\/\/Client.php","hash":"4348da6756cbe4a09dc12b78def30640"},{"name":".\/tests\/app\/src\/\/Router\/Get\/Fallback.php","hash":"6400f8d46d379f78a7a1e20346ff9c26"},{"name":".\/tests\/app\/src\/\/Router\/Post\/Fallback.php","hash":"a877a125080a4947c2f7f3f4ba2e630e"},{"name":".\/tests\/app\/src\/\/Router\/Get\/Two.php","hash":"03ace8fb8dea7aaac3b935dc9e8c57da"},{"name":".\/tests\/app\/src\/\/Router\/Get\/Three.php","hash":"85e966e7545a05b28925fc9689ff0b38"},{"name":".\/tests\/app\/src\/\/Router\/Post\/Two.php","hash":"69e0ceb70f4f9f07ff81cbbfe69b41e0"},{"name":".\/tests\/app\/src\/\/OperationsInterface.php","hash":"cf810f09fc1a2b3d3a453621e15ca0c2"},{"name":".\/tests\/app\/src\/\/Operation\/Fallback.php","hash":"5578baa8a41c810d03d076b08c79231d"},{"name":".\/tests\/app\/src\/\/Operations.php","hash":"e00eb37b140f6f895d30545b0e2ef531"},{"name":".\/tests\/app\/src\/\/Hydrator\/Operation\/Pets.php","hash":"9c2613fb27ab467b3a3c82e77b309a19"},{"name":".\/tests\/app\/src\/\/Hydrator\/Operation\/Pets\/PetId.php","hash":"301ab81fbf3f746b4f512cd6951da22a"},{"name":".\/tests\/app\/src\/\/Hydrators.php","hash":"535390fc20bf47b19234407b6131a0ca"}]},"additionalFiles":{"files":[{"name":"composer.json","hash":""},{"name":"composer.lock","hash":""}]}}
1+
{"specHash":"b0f93294b26f2cda2a0da27e29dee741","generatedFiles":{"files":[{"name":".\/tests\/app\/src\/\/Operation\/ListPets.php","hash":"9665866b6a2bc4319602f483df07da0a"},{"name":".\/tests\/app\/src\/\/Operator\/ListPets.php","hash":"e45ae1f18117ff22d7f2e181ebaa33b4"},{"name":".\/tests\/app\/tests\/\/Operation\/ListPetsTest.php","hash":"1a69a3dbe5fa57f23e6c3903e2ee1466"},{"name":".\/tests\/app\/src\/\/Operation\/CreatePets.php","hash":"09b0a4db052acf5770eefef5f99cdb1e"},{"name":".\/tests\/app\/src\/\/Operator\/CreatePets.php","hash":"ed0f9aef989011ca02c334d1c82458b6"},{"name":".\/tests\/app\/tests\/\/Operation\/CreatePetsTest.php","hash":"167c901d84419d8414b83fe25c4b8180"},{"name":".\/tests\/app\/src\/\/Operation\/ShowPetById.php","hash":"ee7fd99d534864e5f61564402ba045a1"},{"name":".\/tests\/app\/src\/\/Operator\/ShowPetById.php","hash":"8160552bcb97d414deb82596e0b9de59"},{"name":".\/tests\/app\/tests\/\/Operation\/ShowPetByIdTest.php","hash":"57247dfe62086528b74633a61ff924bd"},{"name":".\/tests\/app\/src\/\/Attribute\/CastUnionToType\/Schema\/Cat\/Eyes.php","hash":"f7f128f7b72a4c27fb860551785996d1"},{"name":".\/tests\/app\/src\/\/Schema\/Cat.php","hash":"5f342d75dd04a664f2ba4342d696f765"},{"name":".\/tests\/app\/src\/\/Attribute\/CastUnionToType\/Schema\/Dog\/Eyes.php","hash":"a89f3f7937e507564e2886d72848e264"},{"name":".\/tests\/app\/src\/\/Schema\/Dog.php","hash":"fe05f99bb471fab8018f1ccea7c92b42"},{"name":".\/tests\/app\/src\/\/Attribute\/CastUnionToType\/Schema\/Bird\/Eyes.php","hash":"8bd73cc44affd30c97993108a09f1d86"},{"name":".\/tests\/app\/src\/\/Schema\/Bird.php","hash":"fa5209862011a04106ec698723d47589"},{"name":".\/tests\/app\/src\/\/Attribute\/CastUnionToType\/Schema\/Fish\/Eyes.php","hash":"c5fb5b08f19f1e8c69469b9760bd830e"},{"name":".\/tests\/app\/src\/\/Schema\/Fish.php","hash":"1814c81a0daf83f2cbd36c4298cf97b2"},{"name":".\/tests\/app\/src\/\/Attribute\/CastUnionToType\/Schema\/Pets\/Eyes.php","hash":"ff37f9f8fc5f7c73ff07a524ab0d80c5"},{"name":".\/tests\/app\/src\/\/Schema\/Pets.php","hash":"399cda8f112f5a59089935909a6e286b"},{"name":".\/tests\/app\/src\/\/Schema\/Error.php","hash":"71c7f411eb38324a6a3f4b3e59c3a88a"},{"name":".\/tests\/app\/src\/\/Error\/Error.php","hash":"f0d0ba9484e1e17337da019e786a537b"},{"name":".\/tests\/app\/src\/\/Schema\/Legs.php","hash":"85de135cb89bf380197d0575038ae761"},{"name":".\/tests\/app\/src\/\/Schema\/Tails.php","hash":"7fdd92e0e6e6f066c595e43348e94221"},{"name":".\/tests\/app\/src\/\/Schema\/Fins.php","hash":"28ddfc922a46532fff8feb35b804acd9"},{"name":".\/tests\/app\/src\/\/Schema\/Wings.php","hash":"e166cb172986e751699578ac578156ab"},{"name":".\/tests\/app\/src\/\/Schema\/RedEyes.php","hash":"3f9cd127c35753338d7f9c10e6c5c552"},{"name":".\/tests\/app\/src\/\/Schema\/GreenEyes.php","hash":"76a86f54b24d35b057c2c29bd44ef989"},{"name":".\/tests\/app\/src\/\/Schema\/YellowEyes.php","hash":"3fbe281a0d6e3b65cc740c41ec7347e1"},{"name":".\/tests\/app\/src\/\/Schema\/BlackEyes.php","hash":"fef5f10316f9602f7c56752da21f4896"},{"name":".\/tests\/app\/src\/\/Schema\/BlueEyes.php","hash":"b7448f4b26c40c9b4e2aa19abe2680d0"},{"name":".\/tests\/app\/src\/\/Schema\/Cat\/Features.php","hash":"19ca44111fa924d94b67e0eb6a8503be"},{"name":".\/tests\/app\/src\/\/Schema\/Operations\/ListPets\/Response\/ApplicationJson\/Ok.php","hash":"170adbddfb79e68d38aff7682e2ca2cd"},{"name":".\/tests\/app\/src\/\/Schema\/AliasAbstract\/Tiet3079EDA6\/TietC8A57480\/TietAA436E3B\/Tiet0E7D3D03.php","hash":"ffcdc455af1f82e9587f9d1fbe06a61a"},{"name":".\/tests\/app\/src\/\/Schema\/Operations\/ShowPetById\/Response\/ApplicationJson\/Ok.php","hash":"112874072ea0b6b0303c5215488a86c7"},{"name":".\/tests\/app\/src\/\/Schema\/CreatePets\/Request\/ApplicationJson.php","hash":"26323723911b7feeed065f15f7c05493"},{"name":".\/tests\/app\/src\/\/ClientInterface.php","hash":"13065e8b46e5e3b67723c5c4fb9ea8b6"},{"name":".\/tests\/app\/src\/\/Client.php","hash":"4348da6756cbe4a09dc12b78def30640"},{"name":".\/tests\/app\/src\/\/Router\/Get\/Fallback.php","hash":"6400f8d46d379f78a7a1e20346ff9c26"},{"name":".\/tests\/app\/src\/\/Router\/Post\/Fallback.php","hash":"a877a125080a4947c2f7f3f4ba2e630e"},{"name":".\/tests\/app\/src\/\/Router\/Get\/Two.php","hash":"03ace8fb8dea7aaac3b935dc9e8c57da"},{"name":".\/tests\/app\/src\/\/Router\/Get\/Three.php","hash":"85e966e7545a05b28925fc9689ff0b38"},{"name":".\/tests\/app\/src\/\/Router\/Post\/Two.php","hash":"69e0ceb70f4f9f07ff81cbbfe69b41e0"},{"name":".\/tests\/app\/src\/\/OperationsInterface.php","hash":"cf810f09fc1a2b3d3a453621e15ca0c2"},{"name":".\/tests\/app\/src\/\/Operation\/Fallback.php","hash":"5578baa8a41c810d03d076b08c79231d"},{"name":".\/tests\/app\/src\/\/Operations.php","hash":"e00eb37b140f6f895d30545b0e2ef531"},{"name":".\/tests\/app\/src\/\/Hydrator\/Operation\/Pets.php","hash":"9c2613fb27ab467b3a3c82e77b309a19"},{"name":".\/tests\/app\/src\/\/Hydrator\/Operation\/Pets\/PetId.php","hash":"301ab81fbf3f746b4f512cd6951da22a"},{"name":".\/tests\/app\/src\/\/Hydrators.php","hash":"535390fc20bf47b19234407b6131a0ca"}]},"additionalFiles":{"files":[{"name":"composer.json","hash":""},{"name":"composer.lock","hash":""}]}}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
declare (strict_types=1);
4+
namespace ApiClients\Client\PetStore\Attribute\CastUnionToType\Schema\Bird;
5+
6+
use ApiClients\Client\PetStore\Error as ErrorSchemas;
7+
use ApiClients\Client\PetStore\Hydrator;
8+
use ApiClients\Client\PetStore\Operation;
9+
use ApiClients\Client\PetStore\Operator;
10+
use ApiClients\Client\PetStore\Schema;
11+
use ApiClients\Client\PetStore\WebHook;
12+
use ApiClients\Client\PetStore\Router;
13+
use League\OpenAPIValidation;
14+
use React\Http;
15+
use ApiClients\Contracts;
16+
#[\Attribute(\Attribute::TARGET_PARAMETER)]
17+
final class Eyes implements \EventSauce\ObjectHydrator\PropertyCaster
18+
{
19+
public function cast(mixed $value, \EventSauce\ObjectHydrator\ObjectMapper $hydrator) : mixed
20+
{
21+
if (\is_array($value)) {
22+
$signatureChunks = \array_unique(\array_keys($value));
23+
\sort($signatureChunks);
24+
$signature = \implode('|', $signatureChunks);
25+
if ($signature === 'count|type' && ($value['type'] === 'blood' || $value['type'] === 'wine' || $value['type'] === 'stale')) {
26+
try {
27+
return $hydrator->hydrateObject(Schema\RedEyes::class, $value);
28+
} catch (\Throwable) {
29+
}
30+
}
31+
if ($signature === 'count|type' && ($value['type'] === 'sky' || $value['type'] === 'boobies')) {
32+
try {
33+
return $hydrator->hydrateObject(Schema\BlueEyes::class, $value);
34+
} catch (\Throwable) {
35+
}
36+
}
37+
if ($signature === 'count|type' && ($value['type'] === 'hulk' || $value['type'] === 'forest' || $value['type'] === 'feral')) {
38+
try {
39+
return $hydrator->hydrateObject(Schema\GreenEyes::class, $value);
40+
} catch (\Throwable) {
41+
}
42+
}
43+
if ($signature === 'count|type' && $value['type'] === 'snake') {
44+
try {
45+
return $hydrator->hydrateObject(Schema\YellowEyes::class, $value);
46+
} catch (\Throwable) {
47+
}
48+
}
49+
if ($signature === 'count|type' && $value['type'] === 'rage') {
50+
try {
51+
return $hydrator->hydrateObject(Schema\BlackEyes::class, $value);
52+
} catch (\Throwable) {
53+
}
54+
}
55+
}
56+
return $value;
57+
}
58+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
declare (strict_types=1);
4+
namespace ApiClients\Client\PetStore\Attribute\CastUnionToType\Schema\Cat;
5+
6+
use ApiClients\Client\PetStore\Error as ErrorSchemas;
7+
use ApiClients\Client\PetStore\Hydrator;
8+
use ApiClients\Client\PetStore\Operation;
9+
use ApiClients\Client\PetStore\Operator;
10+
use ApiClients\Client\PetStore\Schema;
11+
use ApiClients\Client\PetStore\WebHook;
12+
use ApiClients\Client\PetStore\Router;
13+
use League\OpenAPIValidation;
14+
use React\Http;
15+
use ApiClients\Contracts;
16+
#[\Attribute(\Attribute::TARGET_PARAMETER)]
17+
final class Eyes implements \EventSauce\ObjectHydrator\PropertyCaster
18+
{
19+
public function cast(mixed $value, \EventSauce\ObjectHydrator\ObjectMapper $hydrator) : mixed
20+
{
21+
if (\is_array($value)) {
22+
$signatureChunks = \array_unique(\array_keys($value));
23+
\sort($signatureChunks);
24+
$signature = \implode('|', $signatureChunks);
25+
if ($signature === 'count|type' && ($value['type'] === 'blood' || $value['type'] === 'wine' || $value['type'] === 'stale')) {
26+
try {
27+
return $hydrator->hydrateObject(Schema\RedEyes::class, $value);
28+
} catch (\Throwable) {
29+
}
30+
}
31+
if ($signature === 'count|type' && ($value['type'] === 'sky' || $value['type'] === 'boobies')) {
32+
try {
33+
return $hydrator->hydrateObject(Schema\BlueEyes::class, $value);
34+
} catch (\Throwable) {
35+
}
36+
}
37+
if ($signature === 'count|type' && ($value['type'] === 'hulk' || $value['type'] === 'forest' || $value['type'] === 'feral')) {
38+
try {
39+
return $hydrator->hydrateObject(Schema\GreenEyes::class, $value);
40+
} catch (\Throwable) {
41+
}
42+
}
43+
if ($signature === 'count|type' && $value['type'] === 'snake') {
44+
try {
45+
return $hydrator->hydrateObject(Schema\YellowEyes::class, $value);
46+
} catch (\Throwable) {
47+
}
48+
}
49+
if ($signature === 'count|type' && $value['type'] === 'rage') {
50+
try {
51+
return $hydrator->hydrateObject(Schema\BlackEyes::class, $value);
52+
} catch (\Throwable) {
53+
}
54+
}
55+
}
56+
return $value;
57+
}
58+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
declare (strict_types=1);
4+
namespace ApiClients\Client\PetStore\Attribute\CastUnionToType\Schema\Dog;
5+
6+
use ApiClients\Client\PetStore\Error as ErrorSchemas;
7+
use ApiClients\Client\PetStore\Hydrator;
8+
use ApiClients\Client\PetStore\Operation;
9+
use ApiClients\Client\PetStore\Operator;
10+
use ApiClients\Client\PetStore\Schema;
11+
use ApiClients\Client\PetStore\WebHook;
12+
use ApiClients\Client\PetStore\Router;
13+
use League\OpenAPIValidation;
14+
use React\Http;
15+
use ApiClients\Contracts;
16+
#[\Attribute(\Attribute::TARGET_PARAMETER)]
17+
final class Eyes implements \EventSauce\ObjectHydrator\PropertyCaster
18+
{
19+
public function cast(mixed $value, \EventSauce\ObjectHydrator\ObjectMapper $hydrator) : mixed
20+
{
21+
if (\is_array($value)) {
22+
$signatureChunks = \array_unique(\array_keys($value));
23+
\sort($signatureChunks);
24+
$signature = \implode('|', $signatureChunks);
25+
if ($signature === 'count|type' && ($value['type'] === 'blood' || $value['type'] === 'wine' || $value['type'] === 'stale')) {
26+
try {
27+
return $hydrator->hydrateObject(Schema\RedEyes::class, $value);
28+
} catch (\Throwable) {
29+
}
30+
}
31+
if ($signature === 'count|type' && ($value['type'] === 'sky' || $value['type'] === 'boobies')) {
32+
try {
33+
return $hydrator->hydrateObject(Schema\BlueEyes::class, $value);
34+
} catch (\Throwable) {
35+
}
36+
}
37+
if ($signature === 'count|type' && ($value['type'] === 'hulk' || $value['type'] === 'forest' || $value['type'] === 'feral')) {
38+
try {
39+
return $hydrator->hydrateObject(Schema\GreenEyes::class, $value);
40+
} catch (\Throwable) {
41+
}
42+
}
43+
if ($signature === 'count|type' && $value['type'] === 'snake') {
44+
try {
45+
return $hydrator->hydrateObject(Schema\YellowEyes::class, $value);
46+
} catch (\Throwable) {
47+
}
48+
}
49+
if ($signature === 'count|type' && $value['type'] === 'rage') {
50+
try {
51+
return $hydrator->hydrateObject(Schema\BlackEyes::class, $value);
52+
} catch (\Throwable) {
53+
}
54+
}
55+
}
56+
return $value;
57+
}
58+
}

0 commit comments

Comments
 (0)