Skip to content

Commit

Permalink
fix test with default value
Browse files Browse the repository at this point in the history
  • Loading branch information
mpoiriert committed Oct 1, 2017
1 parent 537fd62 commit 5273f65
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
6 changes: 3 additions & 3 deletions Extraction/Extractor/PhpDocOperationExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,19 @@ public function extract($method, $operation, ExtractionContextInterface $extract
$docBlock = new DocBlock($method->getDocComment());

if(!$operation->summary) {
$operation->summary = $docBlock->getShortDescription();
$operation->summary = $docBlock->getShortDescription() ?: null;
}

if($operation->description) {
$operation->description = $docBlock->getLongDescription();
$operation->description = $docBlock->getLongDescription() ?: null;
}

foreach ($docBlock->getTagsByName('return') as $returnTag) {
/* @var $returnTag \phpDocumentor\Reflection\DocBlock\Tag\ReturnTag */
foreach ($returnTag->getTypes() as $type) {
$response = new Response();
$response->schema = $responseSchema = new Schema();
$response->description = $returnTag->getDescription();
$response->description = $returnTag->getDescription() ?: null;
$operation->responses[200] = $response;

$subContext = $extractionContext->createSubContext();
Expand Down
3 changes: 2 additions & 1 deletion tests/Extraction/Extractor/PhpDocOperationExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public function testExtract()
$reflectionMethod = new \ReflectionMethod(__NAMESPACE__ . '\PhpDocOperationExtractorStubService', 'operation');

$context = $this->getExtractionContext();
$context->getSwagger()->registerExtractor(new TypeSchemaExtractor());
$schema = $context->getRootSchema();
$schema->paths['/service'] = $pathItem = new PathItem();

Expand All @@ -63,7 +64,7 @@ public function testExtract()

$this->assertJsonStringEqualsJsonString(
file_get_contents(__DIR__ . '/fixture/phpDocOperationExtractorExtract.json'),
$context->getSwagger()->dump($context->getRootSchema())
$context->getSwagger()->dump($context->getRootSchema(), false)
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
{
"swagger": "2.0",
"paths": {
"\/service": {
"/service": {
"get": {
"parameters": [],
"responses": {
"200": {"schema": {"$ref": "#\/definitions\/Draw\/Swagger\/Extraction\/Extractor\/PhpDocOperationExtractorStubService"}},
"500": {"description": "When problem occur"},
"408": {"description": "Define message"},
"400": {"description": "The extraction is impossible"}
"200": {
"schema": {
"$ref": "#/definitions/Draw.Swagger.Extraction.Extractor.PhpDocOperationExtractorStubService",
"type": "object"
}
},
"500": {
"description": "When problem occur"
},
"408": {
"description": "Define message"
},
"400": {
"description": "The extraction is impossible"
}
}
}
}
},
"definitions": {"Draw.Swagger.Extraction.Extractor.PhpDocOperationExtractorStubService": {}}
"definitions": {
"Draw.Swagger.Extraction.Extractor.PhpDocOperationExtractorStubService": {
"type": "object"
}
}
}
2 changes: 1 addition & 1 deletion tests/SwaggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ public function testExtractSwaggerSchema($file)
$schema = $swagger->extract(file_get_contents($file));
$this->assertInstanceOf('Draw\Swagger\Schema\Swagger', $schema);

$this->assertJsonStringEqualsJsonString(file_get_contents($file), $swagger->dump($schema));
$this->assertJsonStringEqualsJsonString(file_get_contents($file), $swagger->dump($schema, false));
}
}

0 comments on commit 5273f65

Please sign in to comment.