Skip to content

Commit

Permalink
Merge pull request #62 from microsoft/dev
Browse files Browse the repository at this point in the history
Release 1.2.0
  • Loading branch information
SilasKenneth authored Mar 15, 2024
2 parents 4fad197 + 690dbda commit dafd911
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @ddyett @MichaelMainer @nikithauc @zengin @silaskenneth @Ndiritu @shemogumbe
* @microsoft/kiota-write
4 changes: 4 additions & 0 deletions .github/workflows/conflicting-pr-label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ on:
types: [synchronize]
branches: [ main ]

permissions:
pull-requests: write
contents: read

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/pr-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ on:
pull_request:
branches: [ main, dev ]

permissions:
contents: read
pull-requests: read

jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -15,7 +19,7 @@ jobs:
php-versions: ['7.4', '8.0', '8.1', '8.2']
steps:
- name: Checkout
uses: actions/[email protected].1
uses: actions/[email protected].2
- name: Setup PHP and Xdebug for Code Coverage report
uses: shivammathur/setup-php@v2
with:
Expand Down
6 changes: 3 additions & 3 deletions src/JsonSerializationWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ public function writeDateValue(?string $key, ?Date $value): void {

public function writeBinaryContent(?string $key, ?StreamInterface $value): void {
if ($value !== null) {
$this->writeStringValue($key, $value->getContents());
} else {
$this->writeNullValue($key);
$val = $value->getContents();
$value->rewind();
$this->writeStringValue($key, $val);
}
}

Expand Down
4 changes: 1 addition & 3 deletions tests/JsonSerializationWriterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,8 @@ public function testWriteBinaryContentValue(): void
$this->jsonSerializationWriter = new JsonSerializationWriter();
$stream = Utils::streamFor("Hello world!!!\r\t\t\t\n");
$this->jsonSerializationWriter->writeBinaryContent('body', $stream);
$stream->rewind();
$this->jsonSerializationWriter->writeAnyValue('body3', $stream);
$this->jsonSerializationWriter->writeBinaryContent('body2', null);
$content = $this->jsonSerializationWriter->getSerializedContent();
$this->assertEquals("\"body\":\"Hello world!!!\\r\\t\\t\\t\\n\",\"body3\":\"Hello world!!!\\r\\t\\t\\t\\n\",\"body2\":null", $content->getContents());
$this->assertEquals("\"body\":\"Hello world!!!\\r\\t\\t\\t\\n\",\"body3\":\"Hello world!!!\\r\\t\\t\\t\\n\"", $content->getContents());
}
}
25 changes: 23 additions & 2 deletions tests/Samples/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Microsoft\Kiota\Abstractions\Serialization\Parsable;
use Microsoft\Kiota\Abstractions\Serialization\ParseNode;
use Microsoft\Kiota\Abstractions\Serialization\SerializationWriter;
use Psr\Http\Message\StreamInterface;

class Person implements Parsable, AdditionalDataHolder
{
Expand All @@ -19,6 +20,8 @@ class Person implements Parsable, AdditionalDataHolder
private ?Address $address = null;

private ?MaritalStatus $maritalStatus = null;

private ?StreamInterface $bio = null;
/**
* @inheritDoc
*/
Expand All @@ -30,7 +33,8 @@ public function getFieldDeserializers(): array
"age" => function (ParseNode $n) use ($currentObject) {$currentObject->setAge($n->getIntegerValue());},
"height" => function (ParseNode $n) use ($currentObject) {$currentObject->setHeight($n->getFloatValue());},
"maritalStatus" => function (ParseNode $n) use ($currentObject) {$currentObject->setMaritalStatus($n->getEnumValue(MaritalStatus::class));},
"address" => function (ParseNode $n) use ($currentObject) {$currentObject->setAddress($n->getObjectValue(array(Address::class, 'createFromDiscriminatorValue')));}
"address" => function (ParseNode $n) use ($currentObject) {$currentObject->setAddress($n->getObjectValue(array(Address::class, 'createFromDiscriminatorValue')));},
"bio" => function (ParseNode $n) use ($currentObject) {$currentObject->setBio($n->getBinaryContent());}
];
}

Expand All @@ -43,6 +47,7 @@ public function serialize(SerializationWriter $writer): void {
$writer->writeEnumValue('maritalStatus', $this->maritalStatus);
$writer->writeFloatValue('height', $this->height);
$writer->writeObjectValue('address', $this->address);
$writer->writeBinaryContent('bio', $this->bio);
}

/**
Expand Down Expand Up @@ -133,4 +138,20 @@ public function setAddress(?Address $address): void {
$this->address = $address;
}

}
/**
* @param StreamInterface|null $bio
*/
public function setBio(?StreamInterface $bio): void
{
$this->bio = $bio;
}

/**
* @return StreamInterface|null
*/
public function getBio(): ?StreamInterface
{
return $this->bio;
}

}

0 comments on commit dafd911

Please sign in to comment.