Skip to content

Commit 57441da

Browse files
authored
fix: do not generate property when range is missing (#369)
1 parent 9a6d5c7 commit 57441da

File tree

6 files changed

+11
-7
lines changed

6 files changed

+11
-7
lines changed

src/ClassMutator/ClassPropertiesAppender.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ private function generateField(array $config, SchemaClass $class, RdfResource $t
129129
{
130130
$property = ($this->propertyGenerator)($typeProperty->localName(), $config, $class, ['type' => $type, 'typeConfig' => $typeConfig, 'property' => $typeProperty], $isCustom);
131131

132-
$class->addProperty($property);
132+
if ($property) {
133+
$class->addProperty($property);
134+
}
133135
}
134136

135137
/**

src/OpenApi/ClassGenerator.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,9 @@ private function buildClassFromSchema(Schema $schema, string $name, array $confi
227227
foreach ($schema->properties as $propertyName => $schemaProperty) {
228228
\assert($schemaProperty instanceof Schema);
229229
$property = ($this->propertyGenerator)($propertyName, $config, $class, ['schema' => $schema, 'property' => $schemaProperty]);
230-
$class->addProperty($property);
230+
if ($property) {
231+
$class->addProperty($property);
232+
}
231233
}
232234

233235
if ($config['doctrine']['useCollection']) {

src/OpenApi/PropertyGenerator/PropertyGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function __construct(?PropertyGeneratorInterface $propertyGenerator = nul
3434
* @param Configuration $config
3535
* @param array{schema: Schema, property: Schema} $context
3636
*/
37-
public function __invoke(string $name, array $config, Class_ $class, array $context, bool $isCustom = false, ?Property $property = null): Property
37+
public function __invoke(string $name, array $config, Class_ $class, array $context, bool $isCustom = false, ?Property $property = null): ?Property
3838
{
3939
$schema = $context['schema'];
4040
$schemaProperty = $context['property'];

src/PropertyGenerator/PropertyGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ final class PropertyGenerator implements PropertyGeneratorInterface
2222
* @param Configuration $config
2323
* @param array{} $context
2424
*/
25-
public function __invoke(string $name, array $config, Class_ $class, array $context, bool $isCustom = false, ?Property $property = null): Property
25+
public function __invoke(string $name, array $config, Class_ $class, array $context, bool $isCustom = false, ?Property $property = null): ?Property
2626
{
2727
if (!$property) {
2828
throw new \LogicException('A property must be given.');

src/PropertyGenerator/PropertyGeneratorInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ public function __invoke(
2929
array $context,
3030
bool $isCustom = false,
3131
?Property $property = null
32-
): Property;
32+
): ?Property;
3333
}

src/Schema/PropertyGenerator/PropertyGenerator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function __construct(GoodRelationsBridge $goodRelationsBridge, TypeConver
6262
* property: RdfResource
6363
* } $context
6464
*/
65-
public function __invoke(string $name, array $config, Class_ $class, array $context, bool $isCustom = false, ?Property $property = null): Property
65+
public function __invoke(string $name, array $config, Class_ $class, array $context, bool $isCustom = false, ?Property $property = null): ?Property
6666
{
6767
$type = $context['type'];
6868
$typeConfig = $context['typeConfig'];
@@ -136,7 +136,7 @@ public function __invoke(string $name, array $config, Class_ $class, array $cont
136136
}
137137

138138
if (!$ranges) {
139-
return $schemaProperty;
139+
return null;
140140
}
141141

142142
$isNullable = (bool) ($propertyConfig['nullable'] ?? !\in_array($cardinality, [

0 commit comments

Comments
 (0)