Skip to content

Commit 7abdf98

Browse files
committed
Several bug fixes
1 parent a60503a commit 7abdf98

File tree

3 files changed

+33
-20
lines changed

3 files changed

+33
-20
lines changed

src/Generator.php

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function __construct(
8484
$this->forceGeneration = is_string(getenv('FORCE_GENERATION')) && strlen(getenv('FORCE_GENERATION')) > 0;
8585

8686
$this->statusOutput = new StatusOutput(
87-
! (new CiDetector())->isCiDetected(),
87+
false,//! (new CiDetector())->isCiDetected(),
8888
new Step('hash_current_spec', 'Hashing current spec', false),
8989
new Step('loading_state', 'Loading state', false),
9090
new Step('loading_spec', 'Loading spec', false),
@@ -284,10 +284,8 @@ private function all(string $configurationLocation): iterable
284284
{
285285
$schemaRegistry = new SchemaRegistry(
286286
$this->configuration->namespace,
287-
false,
288-
false,
289-
// $this->configuration->schemas->allowDuplication ?? false,
290-
// $this->configuration->schemas->useAliasesForDuplication ?? false,
287+
$this->configuration->schemas->allowDuplication ?? false,
288+
$this->configuration->schemas->useAliasesForDuplication ?? false,
291289
);
292290
$schemas = [];
293291
$throwableSchemaRegistry = new ThrowableSchema();
@@ -726,6 +724,12 @@ private function subSplitClient(
726724

727725
$this->statusOutput->itemForStep('generating_schemas', count($schemas));
728726
foreach ($schemas as $schema) {
727+
yield from Schema::generate(
728+
$this->configuration->subSplit->subSplitsDestination . DIRECTORY_SEPARATOR . $this->splitPathPrefix($this->configuration->subSplit->sectionPackage, 'common') . $this->configuration->destination->source,
729+
$schema,
730+
[...$schemaRegistry->aliasesForClassName($schema->className->relative)],
731+
);
732+
729733
if ($throwableSchemaRegistry->has($schema->className->relative)) {
730734
yield from Schema::generate(
731735
$this->configuration->subSplit->subSplitsDestination . DIRECTORY_SEPARATOR . $this->splitPathPrefix($this->configuration->subSplit->sectionPackage, 'common') . $this->configuration->destination->source,
@@ -737,14 +741,6 @@ private function subSplitClient(
737741
$this->configuration->subSplit->subSplitsDestination . DIRECTORY_SEPARATOR . $this->splitPathPrefix($this->configuration->subSplit->sectionPackage, 'common') . $this->configuration->destination->source,
738742
$schema,
739743
);
740-
} else {
741-
$aliases = [...$schemaRegistry->aliasesForClassName($schema->className->relative)];
742-
743-
yield from Schema::generate(
744-
$this->configuration->subSplit->subSplitsDestination . DIRECTORY_SEPARATOR . $this->splitPathPrefix($this->configuration->subSplit->sectionPackage, count($aliases) > 0 ? 'common' : $sortedSchemas[$schema->className->relative]['section']) . $this->configuration->destination->source,
745-
$schema,
746-
$aliases,
747-
);
748744
}
749745

750746
$this->statusOutput->advanceStep('generating_schemas');

src/Generator/Schema.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ public static function generate(string $pathPrefix, Representation\Schema $schem
4444
$className = $schema->className;
4545
if (count($aliases) > 0) {
4646
$className = ClassString::factory(
47-
$className->namespace,
48-
'Schema\\AliasAbstract\\Abstract' . md5(json_encode($schema->schema->getSerializableData())),
47+
$className->baseNamespaces,
48+
'Schema\\AliasAbstract\\Tiet' . implode('\\Tiet', str_split(strtoupper(md5(json_encode($schema->schema->getSerializableData()))), 8)),
4949
);
5050
$aliases[] = $schema->className;
5151
}
@@ -133,6 +133,19 @@ public static function generate(string $pathPrefix, Representation\Schema $schem
133133
$types = [];
134134
if ($property->type->type === 'union' && is_array($property->type->payload)) {
135135
$types[] = self::buildUnionType($property->type);
136+
$schemaClasses = [...self::getUnionTypeSchemas($property->type)];
137+
138+
if (count($schemaClasses) > 0) {
139+
$castToUnionToType = ClassString::factory($schema->className->baseNamespaces, Utils::className('Attribute\\CastUnionToType\\' . $schema->className->relative . '\\' . $property->name));
140+
141+
yield from CastUnionToType::generate($pathPrefix, $castToUnionToType, ...$schemaClasses);
142+
143+
$constructorParam->addAttribute(
144+
new Node\Attribute(
145+
new Node\Name($castToUnionToType->fullyQualified->source),
146+
),
147+
);
148+
}
136149
}
137150

138151
if ($property->type->type === 'array' && ! is_string($property->type->payload)) {
@@ -196,7 +209,11 @@ public static function generate(string $pathPrefix, Representation\Schema $schem
196209
$nullable = count($types) > 1 || count(explode('|', implode('|', $types))) > 1 ? 'null|' : '?';
197210
}
198211

199-
$constructor->addParam($constructorParam->setType($nullable . implode('|', $types)));
212+
if (count($types) > 0) {
213+
$constructorParam->setType($nullable . implode('|', $types));
214+
}
215+
216+
$constructor->addParam($constructorParam);
200217
}
201218

202219
if (count($constructDocBlock) > 0) {
@@ -211,7 +228,7 @@ public static function generate(string $pathPrefix, Representation\Schema $schem
211228
$aliasTms = $factory->namespace($alias->namespace->source);
212229
$aliasClass = $factory->class($alias->className)->makeFinal()->makeReadonly()->extend($className->relative);
213230

214-
yield new File($pathPrefix, $alias->className, $aliasTms->addStmt($aliasClass)->getNode());
231+
yield new File($pathPrefix, $alias->relative, $aliasTms->addStmt($aliasClass)->getNode());
215232
}
216233
}
217234

src/Registry/Schema.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@ public function get(openAPISchema $schema, string $fallbackName): string
8585
$className = Utils::fixKeyword($fallbackName);
8686

8787
if ($this->allowDuplicatedSchemas && $this->useAliasesForDuplication && array_key_exists($json, $this->json)) {
88-
$this->aliasses[$this->json[$json]][] = ClassString::factory($this->baseNamespaces, 'Schema\\' . $className);
88+
$this->aliasses['Schema\\' . $this->json[$json]][] = ClassString::factory($this->baseNamespaces, 'Schema\\' . $className);
8989

9090
return $className;
9191
}
9292

9393
if ($this->allowDuplicatedSchemas && $this->useAliasesForDuplication && array_key_exists($json, $this->unknownSchemasJson)) {
94-
$this->aliasses[$this->unknownSchemasJson[$json]][] = ClassString::factory($this->baseNamespaces, 'Schema\\' . $className);
94+
$this->aliasses['Schema\\' . $this->unknownSchemasJson[$json]][] = ClassString::factory($this->baseNamespaces, 'Schema\\' . $className);
9595

9696
return $className;
9797
}
@@ -133,6 +133,6 @@ public function aliasesForClassName(string $classname): iterable
133133
return;
134134
}
135135

136-
yield from array_unique($this->aliasses[$classname]);
136+
yield from $this->aliasses[$classname];
137137
}
138138
}

0 commit comments

Comments
 (0)