Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 1.3.0 #74

Merged
merged 16 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/policies/resourceManagement.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ configuration:
- isIssue
- isOpen
- hasLabel:
label: 'Needs: Author Feedback'
label: 'status:waiting-for-author-feedback'
- hasLabel:
label: 'Status: No Recent Activity'
- noActivitySince:
Expand All @@ -31,7 +31,7 @@ configuration:
- isIssue
- isOpen
- hasLabel:
label: 'Needs: Author Feedback'
label: 'status:waiting-for-author-feedback'
- noActivitySince:
days: 4
- isNotLabeledWith:
Expand Down Expand Up @@ -64,13 +64,13 @@ configuration:
- isActivitySender:
issueAuthor: True
- hasLabel:
label: 'Needs: Author Feedback'
label: 'status:waiting-for-author-feedback'
- isOpen
then:
- addLabel:
label: 'Needs: Attention :wave:'
- removeLabel:
label: 'Needs: Author Feedback'
label: 'status:waiting-for-author-feedback'
description:
- if:
- payloadType: Issues
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

## [1.3.0]

### Added

### Changed
- fix(logic): Don't cast types since this might introduce some logical bugs. Make sure values match possible values for that type.
- fix(serialization): Fix how composed types are handled.

## [1.0.1]

### Changed
Expand Down
1 change: 1 addition & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ Resources:
- [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/)
- [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
- Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns
- Employees can reach out at [aka.ms/opensource/moderation-support](https://aka.ms/opensource/moderation-support)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ run `composer require microsoft/kiota-serialization-json` or add the following t
```Shell
{
"require": {
"microsoft/kiota-serialization-json": "^1.0.1"
"microsoft/kiota-serialization-json": "^1.3.0"
}
}
```
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
}
},
"require": {
"microsoft/kiota-abstractions": "^1.3.1",
"microsoft/kiota-abstractions": "^1.4.0",
"guzzlehttp/psr7": "^1.6 || ^2",
"php": "^7.4 || ^8",
"ext-json": "*"
Expand Down
8 changes: 4 additions & 4 deletions src/JsonParseNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,28 +53,28 @@ public function getChildNode(string $identifier): ?ParseNode {
* @inheritDoc
*/
public function getStringValue(): ?string {
return $this->jsonNode !== null ? addcslashes(strval($this->jsonNode), "\\\r\n") : null;
return is_string($this->jsonNode) ? addcslashes($this->jsonNode, "\\\r\n") : null;
}

/**
* @inheritDoc
*/
public function getBooleanValue(): ?bool {
return $this->jsonNode !== null ? (bool)$this->jsonNode : null;
return is_bool($this->jsonNode) ? $this->jsonNode : null;
}

/**
* @inheritDoc
*/
public function getIntegerValue(): ?int {
return $this->jsonNode !== null ? intval($this->jsonNode) : null;
return is_int($this->jsonNode) ? $this->jsonNode : null;
}

/**
* @inheritDoc
*/
public function getFloatValue(): ?float {
return $this->jsonNode !== null ? floatval($this->jsonNode) : null;
return is_float($this->jsonNode) ? $this->jsonNode : null;
}

/**
Expand Down
11 changes: 9 additions & 2 deletions src/JsonSerializationWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Microsoft\Kiota\Abstractions\Types\Time;
use Psr\Http\Message\StreamInterface;
use stdClass;
use Microsoft\Kiota\Abstractions\Serialization\ComposedTypeWrapper;

/**
* @method onBeforeObjectSerialization(?Parsable $value);
Expand Down Expand Up @@ -186,7 +187,11 @@ public function writeObjectValue(?string $key, $value, ?Parsable ...$additionalV
if ($this->getOnBeforeObjectSerialization() !== null) {
$this->getOnBeforeObjectSerialization()($value);
}
$this->writer [] = '{';
$isComposedType = $value instanceof ComposedTypeWrapper;

if (!$isComposedType) {
$this->writer [] = '{';
}
if ($this->getOnStartObjectSerialization() !== null) {
$this->getOnStartObjectSerialization()($value, $this);
}
Expand All @@ -200,7 +205,9 @@ public function writeObjectValue(?string $key, $value, ?Parsable ...$additionalV
if ($this->getOnAfterObjectSerialization() !== null) {
$this->getOnAfterObjectSerialization()($value);
}
$this->writer [] = '}';
if (!$isComposedType) {
$this->writer [] = '}';
}
if ($key !== null && $value !== null) {
$this->writer [] = self::PROPERTY_SEPARATOR;
}
Expand Down
8 changes: 5 additions & 3 deletions tests/JsonParseNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ protected function setUp(): void {
}

public function testGetIntegerValue(): void {
$this->parseNode = new JsonParseNode('1243.78');
$this->parseNode = new JsonParseNode(1243.78);
$expected = $this->parseNode->getIntegerValue();
$this->assertEquals(1243, $expected);
$this->assertEquals(null, $expected);
$this->parseNode = new JsonParseNode(1243);
$this->assertEquals(1243, $this->parseNode->getIntegerValue());
}

public function testGetCollectionOfObjectValues(): void {
Expand Down Expand Up @@ -61,7 +63,7 @@ public function testGetObjectValue(): void {
}

public function testGetFloatValue(): void {
$this->parseNode = new JsonParseNode('1243.12');
$this->parseNode = new JsonParseNode(1243.12);
$expected = $this->parseNode->getFloatValue();
$this->assertEquals(1243.12, $expected);
}
Expand Down
50 changes: 50 additions & 0 deletions tests/JsonSerializationWriterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use DateInterval;
use GuzzleHttp\Psr7\Utils;
use Microsoft\Kiota\Abstractions\Serialization\ComposedTypeWrapper;
use Microsoft\Kiota\Abstractions\Serialization\Parsable;
use Microsoft\Kiota\Abstractions\Serialization\ParseNode;
use Microsoft\Kiota\Abstractions\Serialization\SerializationWriter;
Expand Down Expand Up @@ -262,4 +263,53 @@ public function testWriteBinaryContentValue(): void
$content = $this->jsonSerializationWriter->getSerializedContent();
$this->assertEquals("\"body\":\"Hello world!!!\\r\\t\\t\\t\\n\",\"body3\":\"Hello world!!!\\r\\t\\t\\t\\n\"", $content->getContents());
}

public function testWriteObjectValueForComposedTypes(): void
{
$this->jsonSerializationWriter = new JsonSerializationWriter();

$obj = new class implements Parsable, ComposedTypeWrapper {
public function getString(): ?string {return null;}
public function getBoolean(): ?bool { return null;}
public function getInteger(): ?int { return null;}
public function setBoolean(?bool $value): void {}
public function setInteger(?int $value): void {}
public function setString(?string $value): void {}
public function setDouble(?float $value): void {}
public function getDouble(): ?float {return 26.6;}
public function getFieldDeserializers(): array { return [];}
public function serialize(SerializationWriter $writer): void
{
if ($this->getInteger() !== null) {
$writer->writeIntegerValue(null, $this->getInteger());
} elseif ($this->getBoolean() !== null) {
$writer->writeBooleanValue(null, $this->getBoolean());
} elseif ($this->getString() !== null) {
$writer->writeStringValue(null, $this->getString());
} else if ($this->getDouble() !== null) {
$writer->writeFloatValue(null, $this->getDouble());
}
}

public function createFromDiscriminator(ParseNode $parseNode): self {
$result = new $this();
if ($parseNode->getBooleanValue() !== null) {
$result->setBoolean($parseNode->getBooleanValue());
} else if ($parseNode->getFloatValue() !== null) {
$result->setDouble($parseNode->getFloatValue());
} else if ($parseNode->getIntegerValue() !== null) {
$result->setInteger($parseNode->getIntegerValue());
} else if ($parseNode->getStringValue() !== null) {
$result->setString($parseNode->getStringValue());
}
return $result;
}

};

$this->jsonSerializationWriter->writeObjectValue(null, $obj);

$dd = $this->jsonSerializationWriter->getSerializedContent()->getContents();
$this->assertEquals('26.6', $dd);
}
}