Skip to content

Commit

Permalink
Add validate schema tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DjordyKoert committed Nov 17, 2023
1 parent ebb0c87 commit b5022e2
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/Annotations/NullableTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php declare(strict_types=1);

/**
* @license Apache 2.0
*/

namespace OpenApi\Tests\Annotations;

use OpenApi\Tests\OpenApiTestCase;
use OpenApi\Annotations as OA;

class NullableTest extends OpenApiTestCase
{
public function testTypeNullableDefined(): void
{
$annotations = $this->annotationsFromDocBlockParser('@OA\Schema(type="string", nullable=true)');
$annotations[0]->validate();

$annotations = $this->annotationsFromDocBlockParser('@OA\Schema(type="string", nullable=true)');
$annotations[0]->_context = $this->getContext([], OA\OpenApi::VERSION_3_1_0);
$this->assertOpenApiLogEntryContains('@OA\Schema() must not have the "nullable" property when using OpenApi version 3.1.0 in ');
$annotations[0]->validate();
}
}
34 changes: 34 additions & 0 deletions tests/Annotations/TypeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php declare(strict_types=1);

/**
* @license Apache 2.0
*/

namespace OpenApi\Tests\Annotations;

use OpenApi\Tests\OpenApiTestCase;
use OpenApi\Annotations as OA;

class TypeTest extends OpenApiTestCase
{
public function testTypeOfString(): void
{
$annotations = $this->annotationsFromDocBlockParser('@OA\Schema(type="string")');
$annotations[0]->validate();

$annotations = $this->annotationsFromDocBlockParser('@OA\Schema(type="string")');
$annotations[0]->_context = $this->getContext([], OA\OpenApi::VERSION_3_1_0);
$annotations[0]->validate();
}

public function testTypeOfArray(): void
{
$annotations = $this->annotationsFromDocBlockParser('@OA\Schema(type={"string", "null"})');
$this->assertOpenApiLogEntryContains('@OA\Schema() "type" must be of type string in OpenApi version 3.0.0, array given in ');
$annotations[0]->validate();

$annotations = $this->annotationsFromDocBlockParser('@OA\Schema(type={"string", "null"})');
$annotations[0]->_context = $this->getContext([], OA\OpenApi::VERSION_3_1_0);
$annotations[0]->validate();
}
}

0 comments on commit b5022e2

Please sign in to comment.