1
0
Fork 0
mirror of synced 2024-05-20 12:42:39 +12:00

Added Open API 3 validation test

This commit is contained in:
Eldad Fux 2020-11-14 15:05:18 +02:00
parent 977965f46d
commit 3bb7a93e0e
2 changed files with 38 additions and 10 deletions

View file

@ -277,10 +277,13 @@ class OpenAPI3 extends Format
$body['content'][$consumes[0]]['schema']['properties'][$name] = [
'type' => $node['schema']['type'],
'description' => $node['description'],
'default' => $node['default'] ?? null,
'x-example' => $node['x-example'] ?? null,
];
if(!\is_null($node['default'])) {
$body['content'][$consumes[0]]['schema']['properties'][$name]['default'] = $node['default'];
}
if(\array_key_exists('items', $node['schema'])) {
$body['content'][$consumes[0]]['schema']['properties'][$name]['items'] = $node['schema']['items'];
}
@ -289,15 +292,12 @@ class OpenAPI3 extends Format
$url = \str_replace(':'.$name, '{'.$name.'}', $url);
}
var_dump($body);
var_dump('-------');
if(!empty($body['content'][$consumes[0]]['schema']['properties'])) {
$temp['requestBody'] = $body;
if(!empty($bodyRequired)) {
$body['content'][$consumes[0]]['schema']['required'] = $bodyRequired;
}
if(!empty($bodyRequired)) {
$body['schema']['required'] = $bodyRequired;
if(!empty($body['content'][$consumes[0]]['schema']['properties'])) {
$temp['requestBody'] = $body;
}
//$temp['consumes'] = $consumes;

View file

@ -96,7 +96,7 @@ class HTTPTest extends Scope
$this->assertStringContainsString('# robotstxt.org/', $response['body']);
}
public function testSpecSwagger()
public function testSpecSwagger2()
{
$response = $this->client->call(Client::METHOD_GET, '/specs/swagger2?platform=client', [
'content-type' => 'application/json',
@ -119,8 +119,36 @@ class HTTPTest extends Scope
$response['body'] = json_decode($response['body'], true);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertEmpty($response['body']);
$this->assertFalse(isset($response['body']['messages']));
unlink(realpath(__DIR__ . '/../../resources/swagger2.json'));
}
public function testSpecOpenAPI3()
{
$response = $this->client->call(Client::METHOD_GET, '/specs/open-api3?platform=client', [
'content-type' => 'application/json',
], []);
if(!file_put_contents(__DIR__ . '/../../resources/open-api3.json', json_encode($response['body']))) {
throw new Exception('Failed to save spec file');
}
$client = new Client();
$client->setEndpoint('https://validator.swagger.io');
/**
* Test for SUCCESS
*/
$response = $client->call(Client::METHOD_POST, '/validator/debug', [
'content-type' => 'application/json',
], json_decode(file_get_contents(realpath(__DIR__ . '/../../resources/open-api3.json')), true));
$response['body'] = json_decode($response['body'], true);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertFalse(isset($response['body']['messages']));
unlink(realpath(__DIR__ . '/../../resources/open-api3.json'));
}
}