diff --git a/README.md b/README.md index e7d63ba..dcec3bb 100644 --- a/README.md +++ b/README.md @@ -783,13 +783,13 @@ require 'vendor/autoload.php'; use JiraRestApi\Issue\IssueService; use JiraRestApi\Issue\IssueFieldV3; +use JiraRestApi\Issue\DescriptionV3; use JiraRestApi\JiraException; try { $issueField = new IssueFieldV3(); $paraDesc =<<< DESC - Full description for issue - order list 1 - order list 2 @@ -797,18 +797,15 @@ Full description for issue -- sub order list 1 - order list 3 DESC; - - $issueField->setProjectKey('TEST') - ->setSummary('something's wrong') + $descV3 = new DescriptionV3(); + $descV3->addDescriptionContent('paragraph', $paraDesc); + + $issueField->setProjectKey('TEST') + ->setSummary("something's wrong") ->setAssigneeAccountId('user-account-id-here') ->setPriorityNameAsString('Critical') ->setIssueTypeAsString('Bug') - ->addDescriptionHeading(3, 'level 3 heading here') - ->addDescriptionParagraph($paraDesc) - ->addVersion(['1.0.1', '1.0.3']) - ->addComponents(['Component-1', 'Component-2']) - // set issue security if you need. - ->setDueDateAsString('2019-06-19') + ->setDescriptionV3($descV3) ; $issueService = new IssueService(); diff --git a/src/Issue/IssueFieldV3.php b/src/Issue/IssueFieldV3.php index 100a23b..a3901cc 100644 --- a/src/Issue/IssueFieldV3.php +++ b/src/Issue/IssueFieldV3.php @@ -4,20 +4,23 @@ use JiraRestApi\ClassSerialize; +/** + * Atlassian Document Format + * + * @see https://developer.atlassian.com/cloud/jira/platform/apis/document/structure/ + */ class IssueFieldV3 extends IssueField { use ClassSerialize; - /** @var \JiraRestApi\Issue\DescriptionV3|null */ public ?DescriptionV3 $descriptionV3; - /** @var \JiraRestApi\Issue\DescriptionV3|null */ public ?DescriptionV3 $environmentV3; /** * @param \JiraRestApi\Issue\DescriptionV3|null $description * - * @return $this|IssueField + * @return IssueFieldV3 */ public function setDescriptionV3(?DescriptionV3 $description): static { @@ -72,4 +75,19 @@ public function setEnvironment(?DescriptionV3 $environment): static return $this; } + + #[\ReturnTypeWillChange] + public function jsonSerialize() + { + $params = array_filter(get_object_vars($this), function ($var) { + return !is_null($var); + }); + + if ($this->descriptionV3 != null) { + $params['description'] = $this->descriptionV3; + unset($params['descriptionV3']); + } + + return $params; + } } diff --git a/src/Issue/IssueService.php b/src/Issue/IssueService.php index 4c981da..688d9b9 100644 --- a/src/Issue/IssueService.php +++ b/src/Issue/IssueService.php @@ -50,6 +50,13 @@ public function get($issueIdOrKey, $paramArray = [], $issueObject = null): Issue $ret = $this->exec($this->uri.'/'.$issueIdOrKey.$this->toHttpQueryParameter($paramArray), null); + // very ugly workaround for avoiding below error. + // JSON property "description" in class "JiraRestApi\Issue\IssueFieldV3" is an object and cannot be converted to a string + // @see https://github.com/lesstif/php-jira-rest-client/issues/457 + if ($this->isRestApiV3()) { + $ret = str_replace('description', 'descriptionv3', $ret); + } + $this->log->info("Result=\n".$ret); return $issue = $this->json_mapper->map(