Skip to content

Commit

Permalink
fixed #457 - changed JSON property name correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
lesstif committed Jul 24, 2022
1 parent a4135f8 commit 525761d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
17 changes: 7 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -783,32 +783,29 @@ 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
-- sub order list 1
-- 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();
Expand Down
24 changes: 21 additions & 3 deletions src/Issue/IssueFieldV3.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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;
}
}
7 changes: 7 additions & 0 deletions src/Issue/IssueService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 525761d

Please sign in to comment.