Skip to content
This repository has been archived by the owner on Jan 15, 2024. It is now read-only.

Commit

Permalink
Minor fixes and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kleijnweb committed Jan 8, 2016
1 parent 1c25b23 commit 5cdf001
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 70 deletions.
8 changes: 4 additions & 4 deletions src/Dev/DocumentFixer/Fixers/SwaggerBundleResponseFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ public function process(SwaggerDocument $document)
foreach ($operations as &$operation) {
if (!isset($operation['responses']['500'])) {
$operation['responses']['500'] = [
'headers' => ['Content-Type' => 'application/vnd.error+json'],
'$ref' => '#/responses/ServerError'
'description' => 'Generic server error',
'schema' => ['$ref' => '#/responses/ServerError']
];
}
if (!isset($operation['responses']['400'])) {
$operation['responses']['400'] = [
'headers' => ['Content-Type' => 'application/vnd.error+json'],
'$ref' => '#/responses/InputError'
'description' => 'Client input error',
'schema' => ['$ref' => '#/responses/InputError']
];
}
}
Expand Down
14 changes: 9 additions & 5 deletions src/Request/RequestValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,16 @@ private function assembleRequestSchema()
$schema->properties = new \stdClass;

foreach ($this->operationDefinition['parameters'] as $paramDefinition) {
$propertySchema = isset($paramDefinition['schema'])
? $paramDefinition['schema']
: $paramDefinition;

if (isset($paramDefinition['required']) && $paramDefinition['required']) {
$schema->required[] = $paramDefinition['name'];
}

if ($paramDefinition['in'] === 'body') {
$schema->properties->{$paramDefinition['name']} = $this->arrayToObject($paramDefinition['schema']);
continue;
}
$propertySchema = ['type' => $paramDefinition['type']];

$schema->properties->{$paramDefinition['name']} = $this->arrayToObject($propertySchema);
}

Expand All @@ -117,7 +119,9 @@ private function assembleParameterDataForValidation(Request $request)
*/
$content = null;
if ($request->getContent()) {
$content = (object)json_decode($request->getContent());
$content = json_decode($request->getContent());
//TODO UT this
$content = (is_array($content) && isset($content[0])) ? $content : (object)$content;
}

$parameters = new \stdClass;
Expand Down
36 changes: 0 additions & 36 deletions src/Tests/Dev/DocumentFixer/ResourceDefinitionFixerTest.php

This file was deleted.

23 changes: 2 additions & 21 deletions src/Tests/Dev/DocumentFixer/SwaggerBundleResponseFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function willAddServerErrorResponseToOperations()
$operationDefinition = $document->getOperationDefinition('/', 'get');
$responses = $operationDefinition['responses'];
$this->assertArrayHasKey('500', $responses);
$this->assertSame($responses['500']['$ref'], '#/responses/ServerError');
$this->assertSame($responses['500']['schema']['$ref'], '#/responses/ServerError');
}

/**
Expand Down Expand Up @@ -96,25 +96,6 @@ public function willAddInputErrorResponseToOperations()
$operationDefinition = $document->getOperationDefinition('/', 'get');
$responses = $operationDefinition['responses'];
$this->assertArrayHasKey('400', $responses);
$this->assertSame($responses['400']['$ref'], '#/responses/InputError');
}

/**
* @test
*/
public function willAddVndErrorHeaderToOperationResponses()
{
$fixer = new SwaggerBundleResponseFixer();
$document = new SwaggerDocument(__DIR__ . '/assets/minimal.yml');
$fixer->fix($document);

$operationDefinition = $document->getOperationDefinition('/', 'get');
$responses = $operationDefinition['responses'];
$this->assertArrayHasKey('headers', $responses['500']);
$this->assertArrayHasKey('headers', $responses['400']);
$this->assertArrayHasKey('Content-Type', $responses['500']['headers']);
$this->assertArrayHasKey('Content-Type', $responses['400']['headers']);
$this->assertSame('application/vnd.error+json', $responses['500']['headers']['Content-Type']);
$this->assertSame('application/vnd.error+json', $responses['400']['headers']['Content-Type']);
$this->assertSame($responses['400']['schema']['$ref'], '#/responses/InputError');
}
}
5 changes: 4 additions & 1 deletion src/Tests/Functional/PetStore/app/swagger/data.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ paths:
- in: body
name: data
required: true
type: object
schema:
type: object
responses:
'200':
description: "The created resource"
Expand All @@ -24,6 +25,8 @@ paths:
- in: body
name: data
required: true
schema:
type: object
responses:
'200':
description: "The modified resource"
Expand Down
8 changes: 5 additions & 3 deletions src/Tests/Request/RequestValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ public function canOmitParameterWhenNotExplicitlyMarkedAsRequired()
$operationDefinition = [
'parameters' => [
[
'name' => 'foo',
'in' => 'body',
'type' => 'integer'
'name' => 'foo',
'in' => 'body',
'schema' => [
'type' => 'integer'
]
]
]
];
Expand Down

0 comments on commit 5cdf001

Please sign in to comment.