-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix schema.nullable * Add implicit nullable test
- Loading branch information
Showing
4 changed files
with
136 additions
and
2 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,72 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace League\OpenAPIValidation\Tests\FromCommunity; | ||
|
||
use GuzzleHttp\Psr7\Response; | ||
use League\OpenAPIValidation\PSR7\OperationAddress; | ||
use League\OpenAPIValidation\PSR7\ValidatorBuilder; | ||
use League\OpenAPIValidation\Tests\PSR7\BaseValidatorTest; | ||
|
||
final class IssueWithNullableMergeTest extends BaseValidatorTest | ||
{ | ||
public function testNullableMergeOneOf(): void | ||
{ | ||
$yaml = /** @lang yaml */ | ||
<<<'YAML' | ||
openapi: 3.0.0 | ||
paths: | ||
/api/nullable-merge: | ||
get: | ||
description: 'Test' | ||
responses: | ||
'200': | ||
description: 'ok' | ||
content: | ||
application/json: | ||
schema: | ||
$ref: "#/components/schemas/Thing" | ||
components: | ||
schemas: | ||
FooResult: | ||
type: object | ||
properties: | ||
id: | ||
type: integer | ||
foo: | ||
type: string | ||
BarResult: | ||
type: object | ||
nullable: true | ||
properties: | ||
id: | ||
type: integer | ||
bar: | ||
type: string | ||
Thing: | ||
type: object | ||
properties: | ||
result: | ||
oneOf: | ||
- $ref: "#/components/schemas/FooResult" | ||
- $ref: "#/components/schemas/BarResult" | ||
YAML; | ||
|
||
$validator = (new ValidatorBuilder())->fromYaml($yaml)->getResponseValidator(); | ||
$operation = new OperationAddress('/api/nullable-merge', 'get'); | ||
|
||
$responseContent = /** @lang JSON */ | ||
' | ||
{ | ||
"result": null | ||
} | ||
'; | ||
|
||
$response = new Response(200, ['Content-Type' => 'application/json'], $responseContent); | ||
|
||
$validator->validate($operation, $response); | ||
|
||
$this->addToAssertionCount(1); | ||
} | ||
} |
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,62 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace League\OpenAPIValidation\Tests\FromCommunity; | ||
|
||
use GuzzleHttp\Psr7\Response; | ||
use League\OpenAPIValidation\PSR7\OperationAddress; | ||
use League\OpenAPIValidation\PSR7\ValidatorBuilder; | ||
use League\OpenAPIValidation\Tests\PSR7\BaseValidatorTest; | ||
|
||
final class NullableSchemaTest extends BaseValidatorTest | ||
{ | ||
public function testNullableImplicitResult(): void | ||
{ | ||
$yaml = /** @lang yaml */ | ||
<<<'YAML' | ||
openapi: 3.0.0 | ||
paths: | ||
/api/nullable: | ||
get: | ||
description: 'Test' | ||
responses: | ||
'200': | ||
description: 'ok' | ||
content: | ||
application/json: | ||
schema: | ||
$ref: "#/components/schemas/Thing" | ||
components: | ||
schemas: | ||
FooResult: | ||
properties: | ||
id: | ||
type: integer | ||
foo: | ||
type: string | ||
Thing: | ||
type: object | ||
properties: | ||
result: | ||
schema: | ||
- $ref: "#/components/schemas/FooResult" | ||
YAML; | ||
|
||
$validator = (new ValidatorBuilder())->fromYaml($yaml)->getResponseValidator(); | ||
$operation = new OperationAddress('/api/nullable', 'get'); | ||
|
||
$responseContent = /** @lang JSON */ | ||
' | ||
{ | ||
"result": null | ||
} | ||
'; | ||
|
||
$response = new Response(200, ['Content-Type' => 'application/json'], $responseContent); | ||
|
||
$validator->validate($operation, $response); | ||
|
||
$this->addToAssertionCount(1); | ||
} | ||
} |