-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Find suitable value for oneOf property in parameters. Fix #166 #168
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace League\OpenAPIValidation\Tests\FromCommunity; | ||
|
||
use GuzzleHttp\Psr7\ServerRequest; | ||
use League\OpenAPIValidation\PSR7\Exception\Validation\InvalidQueryArgs; | ||
use League\OpenAPIValidation\PSR7\ValidatorBuilder; | ||
use League\OpenAPIValidation\Tests\PSR7\BaseValidatorTest; | ||
|
||
use function parse_str; | ||
|
||
/** | ||
* @see https://github.com/thephpleague/openapi-psr7-validator/issues/166 | ||
*/ | ||
final class Issue166Test extends BaseValidatorTest | ||
{ | ||
public function testIssue166(): void | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. some negative cases required |
||
{ | ||
$yaml = /** @lang yaml */ | ||
<<<YAML | ||
openapi: 3.0.0 | ||
servers: | ||
- url: 'http://localhost:8000/api' | ||
paths: | ||
/list: | ||
get: | ||
parameters: | ||
- in: query | ||
name: filter | ||
style: deepObject | ||
allowReserved: true | ||
schema: | ||
type: object | ||
properties: | ||
filters: | ||
oneOf: | ||
- | ||
type: object | ||
required: | ||
- max | ||
properties: | ||
max: | ||
type: number | ||
- | ||
type: object | ||
required: | ||
- min | ||
properties: | ||
min: | ||
type: number | ||
YAML; | ||
|
||
$validator = (new ValidatorBuilder())->fromYaml($yaml)->getServerRequestValidator(); | ||
|
||
$queryString = 'filter[filters][min]=1'; | ||
$query = null; | ||
parse_str($queryString, $query); | ||
|
||
$psrRequest = (new ServerRequest('get', 'http://localhost:8000/api/list')) | ||
->withHeader('Content-Type', 'application/json') | ||
->withQueryParams($query); | ||
|
||
try { | ||
$validator->validate($psrRequest); | ||
$this->assertTrue(true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is not proper way how to deal with exceptions and zero assertions. proper way would be (without any try..catch)
any exception thrown here should break the test and if |
||
} catch (InvalidQueryArgs $e) { | ||
self::fail('Should not throw an exception'); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like in this case we should immediately stop validation if we have filled oneOf and none of the schemas matched in
findSuitableOneOf
.