Skip to content
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
24 changes: 2 additions & 22 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -473,19 +473,7 @@
"CommitTransaction",
"ExecuteStatement",
"RollbackTransaction"
],
"patches": {
"source": [
{
"op": "remove",
"path": "/shapes/ArrayValue/union"
},
{
"op": "remove",
"path": "/shapes/Field/union"
}
]
}
]
},
"Rekognition": {
"source": "https://raw.githubusercontent.com/aws/aws-sdk-php/${LATEST}/src/data/rekognition/2016-06-27/api-2.json",
Expand Down Expand Up @@ -611,15 +599,7 @@
"GetVectors",
"DeleteVectors",
"QueryVectors"
],
"patches": {
"source": [
{
"op": "remove",
"path": "/shapes/VectorData/union"
}
]
}
]
},
"Scheduler": {
"source": "https://raw.githubusercontent.com/aws/aws-sdk-php/${LATEST}/src/data/scheduler/2021-06-30/api-2.json",
Expand Down
12 changes: 12 additions & 0 deletions src/CodeGenerator/src/Definition/ObjectShape.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace AsyncAws\CodeGenerator\Definition;

/**
* @internal
*/
abstract class ObjectShape extends Shape
{
}
2 changes: 1 addition & 1 deletion src/CodeGenerator/src/Definition/Shape.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static function create(string $name, array $data, \Closure $shapeLocator,
} elseif ($data['document'] ?? false) {
$shape = new DocumentShape();
} elseif ($data['union'] ?? false) {
throw new \UnexpectedValueException(\sprintf('Union shapes are not supported yet by the code generator. The shape "%s" is a union shape.', $name));
$shape = new UnionShape();
} else {
$shape = new StructureShape();
}
Expand Down
2 changes: 1 addition & 1 deletion src/CodeGenerator/src/Definition/StructureMember.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function getName(): string
return $this->data['_name'];
}

public function getOwnerShape(): StructureShape
public function getOwnerShape(): ObjectShape
{
return $this->data['_owner'];
}
Expand Down
4 changes: 2 additions & 2 deletions src/CodeGenerator/src/Definition/StructureShape.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* @internal
*/
class StructureShape extends Shape
class StructureShape extends ObjectShape
{
/**
* @return StructureMember[]
Expand All @@ -18,7 +18,7 @@ public function getMembers(): array
$members = [];
foreach ($this->data['members'] as $name => $member) {
$members[] = new StructureMember(
$member + ['_name' => $name, '_owner' => $this, '_required' => \in_array($name, $required)],
$member + ['_name' => $name, '_owner' => $this->data['_members_owner'] ?? $this, '_required' => \in_array($name, $required)],
$this->shapeLocator
);
}
Expand Down
53 changes: 53 additions & 0 deletions src/CodeGenerator/src/Definition/UnionShape.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

declare(strict_types=1);

namespace AsyncAws\CodeGenerator\Definition;

/**
* @internal
*/
class UnionShape extends ObjectShape
{
public function getChildren(): array
{
$children = [];
foreach ($this->data['members'] as $name => $member) {
$locationName = $member['locationName'] ?? $name;
$children[$locationName] = Shape::create(
$this->getChildName($name),
[
'type' => 'structure',
'_members_owner' => $this,
'required' => [$name],
'members' => [$name => $member],
],
$this->shapeLocator,
$this->serviceLocator,
);
}

return $children;
}

public function getChildForUnknown(): StructureShape
{
/** @phpstan-ignore return.type */
return Shape::create(
$this->getChildName('UnknownToSdk'),
[
'type' => 'structure',
'_members_owner' => $this,
'required' => [],
'members' => [],
],
$this->shapeLocator,
$this->serviceLocator,
);
}

private function getChildName(string $name): string
{
return $this->getName() . 'Member' . ucfirst($name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use AsyncAws\CodeGenerator\Definition\DocumentShape;
use AsyncAws\CodeGenerator\Definition\ListShape;
use AsyncAws\CodeGenerator\Definition\MapShape;
use AsyncAws\CodeGenerator\Definition\ObjectShape;
use AsyncAws\CodeGenerator\Definition\Operation;
use AsyncAws\CodeGenerator\Definition\Shape;
use AsyncAws\CodeGenerator\Definition\StructureShape;
Expand All @@ -18,6 +19,7 @@
use AsyncAws\CodeGenerator\Generator\PhpGenerator\ClassBuilder;
use AsyncAws\CodeGenerator\Generator\PhpGenerator\ClassRegistry;
use AsyncAws\CodeGenerator\Generator\ResponseParser\ParserProvider;
use AsyncAws\CodeGenerator\Generator\ShapeUsageHelper;
use AsyncAws\Core\Response;
use AsyncAws\Core\Stream\ResponseBodyStream;
use AsyncAws\Core\Stream\ResultStream;
Expand Down Expand Up @@ -58,12 +60,12 @@ class PopulatorGenerator
*/
private $parserProvider;

public function __construct(ClassRegistry $classRegistry, NamespaceRegistry $namespaceRegistry, RequirementsRegistry $requirementsRegistry, ObjectGenerator $objectGenerator, array $managedMethods, ?TypeGenerator $typeGenerator = null, ?EnumGenerator $enumGenerator = null, ?ParserProvider $parserProvider = null)
public function __construct(ClassRegistry $classRegistry, NamespaceRegistry $namespaceRegistry, RequirementsRegistry $requirementsRegistry, ObjectGenerator $objectGenerator, ShapeUsageHelper $shapeUsageHelper, ?TypeGenerator $typeGenerator = null, ?EnumGenerator $enumGenerator = null, ?ParserProvider $parserProvider = null)
{
$this->objectGenerator = $objectGenerator;
$this->requirementsRegistry = $requirementsRegistry;
$this->typeGenerator = $typeGenerator ?? new TypeGenerator($namespaceRegistry);
$this->enumGenerator = $enumGenerator ?? new EnumGenerator($classRegistry, $namespaceRegistry, $managedMethods);
$this->enumGenerator = $enumGenerator ?? new EnumGenerator($classRegistry, $namespaceRegistry, $shapeUsageHelper);
$this->parserProvider = $parserProvider ?? new ParserProvider($namespaceRegistry, $requirementsRegistry, $this->typeGenerator);
}

Expand Down Expand Up @@ -100,7 +102,7 @@ private function generateProperties(StructureShape $shape, ClassBuilder $classBu
$this->enumGenerator->generate($memberShape);
}

if ($memberShape instanceof StructureShape) {
if ($memberShape instanceof ObjectShape) {
$this->objectGenerator->generate($memberShape);
} elseif ($memberShape instanceof MapShape) {
$mapKeyShape = $memberShape->getKey()->getShape();
Expand All @@ -111,7 +113,7 @@ private function generateProperties(StructureShape $shape, ClassBuilder $classBu
$this->enumGenerator->generate($mapKeyShape);
}

if (($valueShape = $memberShape->getValue()->getShape()) instanceof StructureShape) {
if (($valueShape = $memberShape->getValue()->getShape()) instanceof ObjectShape) {
$this->objectGenerator->generate($valueShape);
}
if (!empty($valueShape->getEnum())) {
Expand Down Expand Up @@ -300,7 +302,7 @@ private function generatePopulator(Operation $operation, StructureShape $shape,

private function generateListShapeMemberShape(Shape $memberShape, bool $forEndpoint): void
{
if ($memberShape instanceof StructureShape) {
if ($memberShape instanceof ObjectShape) {
$this->objectGenerator->generate($memberShape, $forEndpoint);
} elseif ($memberShape instanceof ListShape) {
$this->generateListShapeMemberShape($memberShape->getMember()->getShape(), $forEndpoint);
Expand Down
Loading