Skip to content

Commit

Permalink
Add scratch test around property inheritance (#1353)
Browse files Browse the repository at this point in the history
  • Loading branch information
DerManoMann authored Dec 13, 2022
1 parent 020a6f4 commit 7bd76a0
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 17 deletions.
15 changes: 15 additions & 0 deletions tests/Fixtures/Scratch/AbstractBaseClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php declare(strict_types=1);

/**
* @license Apache 2.0
*/

namespace OpenApi\Tests\Fixtures\Scratch;

use OpenApi\Annotations as OA;

abstract class AbstractBaseClass
{
/** @OA\Property(property="basefilter") */
public string $filters;
}
8 changes: 4 additions & 4 deletions tests/Fixtures/Scratch/MergeTraits.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ components:
required:
- street
properties:
id:
type: integer
format: int64
readOnly: true
created_at:
type: string
format: date-time
Expand All @@ -30,6 +26,10 @@ components:
type: string
format: date-time
readOnly: true
id:
type: integer
format: int64
readOnly: true
street:
type: string
type: object
Expand Down
21 changes: 10 additions & 11 deletions tests/Fixtures/Scratch/MergeTraitsExtended.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
* @license Apache 2.0
*/

namespace App\Models;
namespace OpenApi\Tests\Fixtures\Scratch;

use App\Models\Product as ProductModel;
use OpenApi\Annotations as OA;

trait HasId
trait HasIdExtended
{
/**
* @OA\Property(
Expand All @@ -20,7 +19,7 @@ trait HasId
public int $id;
}

trait HasTimestamps
trait HasTimestampsExtended
{
/**
* @OA\Property(
Expand All @@ -41,7 +40,7 @@ trait HasTimestamps
public \DateTime $updated_at;
}

trait HasSoftDelete
trait HasSoftDeleteExtended
{
/**
* @OA\Property(
Expand All @@ -60,10 +59,10 @@ trait HasSoftDelete
*
* @see BaseModel
*/
abstract class Model
abstract class ModelExtended
{
use HasId;
use HasTimestamps;
use HasIdExtended;
use HasTimestampsExtended;
}

/**
Expand All @@ -80,9 +79,9 @@ abstract class Model
*
* @see ProductModel
*/
class Product extends Model
class Product extends ModelExtended
{
use HasSoftDelete;
use HasSoftDeleteExtended;

/** @OA\Property */
public string $number;
Expand All @@ -102,6 +101,6 @@ class Product extends Model
* )
* )
*/
class Endpoint
class EndpointExtended
{
}
4 changes: 2 additions & 2 deletions tests/Fixtures/Scratch/MergeTraitsExtended.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ paths:
$ref: '#/components/schemas/Product'
components:
schemas:
Model:
ModelExtended:
description: 'This model can be ignored, it is just used for inheritance.'
properties:
id:
Expand All @@ -40,7 +40,7 @@ components:
name: Product
allOf:
-
$ref: '#/components/schemas/Model'
$ref: '#/components/schemas/ModelExtended'
-
properties:
deleted_at:
Expand Down
33 changes: 33 additions & 0 deletions tests/Fixtures/Scratch/PropertyInheritance.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php declare(strict_types=1);

/**
* @license Apache 2.0
*/

namespace OpenApi\Tests\Fixtures\Scratch;

use OpenApi\Annotations as OA;

/**
* @OA\Schema
*/
class PropertyInheritance extends AbstractBaseClass
{
/** @OA\Property(property="inheritedfilter") */
public string $filters;
}

/**
* @OA\Info(title="API", version="1.0")
* @OA\Get(
* path="/api/endpoint",
* @OA\Response(
* response=200,
* description="successful operation",
* @OA\JsonContent(ref="#/components/schemas/PropertyInheritance")
* )
* )
*/
class PropertyInheritanceEndpoint
{
}
21 changes: 21 additions & 0 deletions tests/Fixtures/Scratch/PropertyInheritance.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
openapi: 3.0.0
info:
title: API
version: '1.0'
paths:
/api/endpoint:
get:
responses:
'200':
description: 'successful operation'
content:
application/json:
schema:
$ref: '#/components/schemas/PropertyInheritance'
components:
schemas:
PropertyInheritance:
properties:
inheritedfilter:
type: string
type: object
5 changes: 5 additions & 0 deletions tests/ScratchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ public function scratchTests(): iterable
{
foreach (glob($this->fixture('Scratch/*.php')) as $fixture) {
$name = pathinfo($fixture, PATHINFO_FILENAME);

if (0 === strpos($name, 'Abstract')) {
continue;
}

yield $name => [
OpenApi::VERSION_3_0_0,
$this->fixture("Scratch/$name.php"),
Expand Down

0 comments on commit 7bd76a0

Please sign in to comment.