forked from thephpleague/openapi-psr7-validator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not perform further validation on nullable null data
- Loading branch information
Pavel.Batanov
committed
May 13, 2019
1 parent
f805092
commit ab8f04a
Showing
5 changed files
with
101 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
/** | ||
* @author Pavel Batanov <[email protected]> | ||
* Date: 13 May 2019 | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace OpenAPIValidationTests\FromCommunity; | ||
|
||
use GuzzleHttp\Psr7\ServerRequest; | ||
use OpenAPIValidation\PSR7\ServerRequestValidator; | ||
use PHPUnit\Framework\TestCase; | ||
use function GuzzleHttp\Psr7\stream_for; | ||
|
||
final class Issue12Test extends TestCase | ||
{ | ||
/** | ||
* https://github.com/lezhnev74/openapi-psr7-validator/issues/12 | ||
* | ||
* @dataProvider getNullableTypeExamples | ||
* | ||
* @param $example | ||
*/ | ||
public function test_issue12($example): void | ||
{ | ||
$yaml = /** @lang yaml */ | ||
<<<YAML | ||
openapi: 3.0.0 | ||
info: | ||
title: Product import API | ||
version: '1.0' | ||
servers: | ||
- url: 'http://localhost:8000/api/v1' | ||
paths: | ||
/products.create: | ||
post: | ||
requestBody: | ||
required: true | ||
content: | ||
application/json: | ||
schema: | ||
properties: | ||
test: | ||
nullable: true | ||
type: array | ||
items: | ||
type: integer | ||
minItems: 1 | ||
responses: | ||
'200': | ||
description: OK | ||
content: | ||
application/json: | ||
schema: | ||
properties: | ||
result: | ||
type: string | ||
YAML; | ||
|
||
$validator = ServerRequestValidator::fromYaml($yaml); | ||
|
||
$psrRequest = (new ServerRequest('post', 'http://localhost:8000/api/v1/products.create')) | ||
->withHeader('Content-Type', 'application/json') | ||
->withBody(stream_for(json_encode(['test' => $example]))); | ||
|
||
$validator->validate($psrRequest); | ||
|
||
$this->addToAssertionCount(1); | ||
} | ||
|
||
public function getNullableTypeExamples(): array | ||
{ | ||
return [ | ||
'nullable null' => [null], | ||
'nullable array' => [[123]], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters