Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
chriskapp committed Nov 1, 2024
1 parent cf55de6 commit a5391cb
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 11 additions & 3 deletions src/Generator.php
Original file line number Diff line number Diff line change
@@ -40,6 +40,8 @@ class Generator
{
/**
* Generates a TypeSchema specification based on the document
*
* @throws GeneratorException
*/
public function generate(Document $document, ?string $baseUrl = null): string
{
@@ -73,7 +75,12 @@ public function generate(Document $document, ?string $baseUrl = null): string
$definitions = new Record();
$types = $document->getTypes();
foreach ($types as $type) {
$definitions->put($type->getName(), $this->generateDefinitionType($type));
$typeName = $type->getName();
if (empty($typeName)) {
continue;
}

$definitions->put($typeName, $this->generateDefinitionType($type));
}
$schema->setDefinitions($definitions);

@@ -97,6 +104,7 @@ private function generateImport(?array $imports): ?Record
return null;
}

/** @var Record<string> $result */
$result = new Record();
foreach ($imports as $import) {
$alias = $import->getAlias() ?? null;
@@ -303,11 +311,11 @@ private function generateDefinitionType(Type $type): Model\DefinitionType
if ($type->getType() === Type::TYPE_MAP) {
$result = new Model\MapDefinitionType();
$result->setType('map');
$result->setSchema($this->resolveReferenceType($type->getReference(), $type->getTemplate()));
$result->setSchema($this->resolveReferenceType($type->getReference()));
} elseif ($type->getType() === Type::TYPE_ARRAY) {
$result = new Model\ArrayDefinitionType();
$result->setType('array');
$result->setSchema($this->resolveReferenceType($type->getReference(), $type->getTemplate()));
$result->setSchema($this->resolveReferenceType($type->getReference()));
} else {
$result = new Model\StructDefinitionType();
$result->setType('struct');
2 changes: 1 addition & 1 deletion tests/Model/DocumentTest.php
Original file line number Diff line number Diff line change
@@ -67,7 +67,7 @@ protected function assertDocument(Document $document): void
$type = $document->getType($document->indexOfType('Product'));
$this->assertInstanceOf(Type::class, $type);
$this->assertEquals('Product', $type->getName());
$this->assertEquals('object', $type->getType());
$this->assertEquals('struct', $type->getType());
$this->assertEquals(3, count($type->getProperties()));
}
}

0 comments on commit a5391cb

Please sign in to comment.