From aa10f9a2da31e297ee070ea5b0a9f1673ecc555f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Str=C3=BCbe?= Date: Mon, 9 Nov 2015 23:34:37 +0100 Subject: [PATCH] Introduced default-value parameter to JsonSerializableParser JSP is now able to set a default value for scalar types This makes merging the parser result with other parser results easier and gives some additional info when creating docs Removed PHP doc comment block --- Parser/JsonSerializableParser.php | 3 ++- Tests/Parser/JsonSerializableParserTest.php | 9 ++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Parser/JsonSerializableParser.php b/Parser/JsonSerializableParser.php index 818e623..9bf46ef 100644 --- a/Parser/JsonSerializableParser.php +++ b/Parser/JsonSerializableParser.php @@ -59,7 +59,8 @@ class JsonSerializableParser implements ParserInterface 'subType' => null, 'required' => null, 'description' => null, - 'readonly' => null + 'readonly' => null, + 'default' => is_scalar($item) ? $item : null, ); if ($type == 'object' && $item instanceof \JsonSerializable) { diff --git a/Tests/Parser/JsonSerializableParserTest.php b/Tests/Parser/JsonSerializableParserTest.php index 88d4e98..114bbaf 100644 --- a/Tests/Parser/JsonSerializableParserTest.php +++ b/Tests/Parser/JsonSerializableParserTest.php @@ -46,13 +46,15 @@ class JsonSerializableParserTest extends \PHPUnit_Framework_TestCase array( 'property' => 'id', 'expected' => array( - 'dataType' => 'integer' + 'dataType' => 'integer', + 'default' => 123 ) ), array( 'property' => 'name', 'expected' => array( - 'dataType' => 'string' + 'dataType' => 'string', + 'default' => 'My name', ) ), array( @@ -66,7 +68,8 @@ class JsonSerializableParserTest extends \PHPUnit_Framework_TestCase 'subType' => null, 'required' => null, 'description' => null, - 'readonly' => null + 'readonly' => null, + 'default' => null, ) ) )