Skip to content

Commit

Permalink
Map property type for promoted properties (#1074)
Browse files Browse the repository at this point in the history
  • Loading branch information
DerManoMann authored Jan 19, 2022
1 parent 36f0b62 commit 27422d1
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 10 deletions.
5 changes: 2 additions & 3 deletions src/Processors/AugmentProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public function __invoke(Analysis $analysis)

if (Generator::isDefault($property->type)) {
$this->augmentType($analysis, $property, $context, $refs, $varMatches);
} else {
Util::mapNativeType($property, $property->type);
}

if (Generator::isDefault($property->description) && isset($varMatches['description'])) {
Expand Down Expand Up @@ -156,9 +158,6 @@ protected function augmentType(Analysis $analysis, Property $property, Context $
$refKey = $this->toRefKey($context, $type);
if (Generator::isDefault($property->ref) && array_key_exists($refKey, $refs)) {
$this->applyRef($property, $refs[$refKey]);

// cannot get more specific
return;
} else {
if ($typeSchema = $analysis->getSchemaForSource($context->type)) {
if (Generator::isDefault($property->format)) {
Expand Down
2 changes: 1 addition & 1 deletion tests/Analysers/TokenScannerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function scanCases()
'traits' => ['OpenApi\\Tests\\Fixtures\\Apis\\DocBlocks\\NameTrait'],
'enums' => [],
'methods' => [],
'properties' => ['id', 'brand', 'colour'],
'properties' => ['quantity', 'brand', 'colour', 'id'],
],
'OpenApi\\Tests\\Fixtures\\Apis\\DocBlocks\\ProductController' => [
'uses' => ['OA' => 'OpenApi\\Annotations'],
Expand Down
2 changes: 2 additions & 0 deletions tests/Fixtures/Apis/Attributes/basic.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class Product implements ProductInterface
public $id;

public function __construct(
#[OAT\Property()]
public int $quantity,
#[OAT\Property()]
public string $brand,
#[OAT\Property()]
Expand Down
15 changes: 9 additions & 6 deletions tests/Fixtures/Apis/DocBlocks/basic.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,22 @@ class Product implements ProductInterface
{
use NameTrait;

/** @OA\Property() */
public int $quantity;

/** @OA\Property() */
public string $brand;

/** @OA\Property() */
public Colour $colour;

/**
* The id.
*
* @OA\Property(format="int64", example=1)
*/
public $id;


/** @OA\Property() */
public string $brand;

/** @OA\Property() */
public Colour $colour;
}

class ProductController
Expand Down
3 changes: 3 additions & 0 deletions tests/Fixtures/Apis/Mixed/basic.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class Product implements ProductInterface
*/
public $id;

#[OAT\Property()]
public int $quantity;

#[OAT\Property()]
public string $brand;

Expand Down
2 changes: 2 additions & 0 deletions tests/Fixtures/Apis/basic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ components:
$ref: '#/components/schemas/NameTrait'
-
properties:
quantity:
type: integer
brand:
type: string
colour:
Expand Down

0 comments on commit 27422d1

Please sign in to comment.