Skip to content

Commit

Permalink
refactor: change return type from result class to bool (#2358)
Browse files Browse the repository at this point in the history
Cleans up the return value while determining if a class needs to be
described.

Taken from #2349
  • Loading branch information
DjordyKoert authored Oct 17, 2024
1 parent 3d05e0e commit 0f81820
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 51 deletions.
15 changes: 8 additions & 7 deletions src/ModelDescriber/Annotations/AnnotationsReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,12 @@ public function __construct(
);
}

public function updateDefinition(\ReflectionClass $reflectionClass, OA\Schema $schema): UpdateClassDefinitionResult
public function updateDefinition(\ReflectionClass $reflectionClass, OA\Schema $schema): bool
{
$this->openApiAnnotationsReader->updateSchema($reflectionClass, $schema);
$this->symfonyConstraintAnnotationReader->setSchema($schema);

return new UpdateClassDefinitionResult(
$this->shouldDescribeModelProperties($schema)
);
return $this->shouldDescribeModelProperties($schema);
}

/**
Expand All @@ -72,9 +70,12 @@ public function updateProperty($reflection, OA\Property $property, ?array $seria
}

/**
* if an objects schema type and ref are undefined OR the object was manually
* defined as an object, then we're good to do the normal describe flow of
* class properties.
* Whether the model describer should continue reading class properties
* after updating the open api schema from an `OA\Schema` definition.
*
* Users may manually define a `type` or `ref` on a schema, and if that's the case
* model describers should _probably_ not describe any additional properties or try
* to merge in properties.
*/
private function shouldDescribeModelProperties(OA\Schema $schema): bool
{
Expand Down
41 changes: 0 additions & 41 deletions src/ModelDescriber/Annotations/UpdateClassDefinitionResult.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/ModelDescriber/FormModelDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function describe(Model $model, OA\Schema $schema): void
);
$classResult = $annotationsReader->updateDefinition(new \ReflectionClass($class), $schema);

if (!$classResult->shouldDescribeModelProperties()) {
if (!$classResult) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/ModelDescriber/JMSModelDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function describe(Model $model, OA\Schema $schema)
);
$classResult = $annotationsReader->updateDefinition(new \ReflectionClass($className), $schema);

if (!$classResult->shouldDescribeModelProperties()) {
if (!$classResult) {
return;
}
$schema->type = 'object';
Expand Down
2 changes: 1 addition & 1 deletion src/ModelDescriber/ObjectModelDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function describe(Model $model, OA\Schema $schema)
);
$classResult = $annotationsReader->updateDefinition($reflClass, $schema);

if (!$classResult->shouldDescribeModelProperties()) {
if (!$classResult) {
return;
}

Expand Down

0 comments on commit 0f81820

Please sign in to comment.