diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index db0fd32..d45027e 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1 +1 @@ -* @ddyett @MichaelMainer @nikithauc @zengin @silaskenneth @Ndiritu @shemogumbe +* @microsoft/kiota-write diff --git a/.github/workflows/conflicting-pr-label.yml b/.github/workflows/conflicting-pr-label.yml index da6e5f3..fb4a14e 100644 --- a/.github/workflows/conflicting-pr-label.yml +++ b/.github/workflows/conflicting-pr-label.yml @@ -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" diff --git a/.github/workflows/pr-validation.yml b/.github/workflows/pr-validation.yml index d912dd1..329192d 100644 --- a/.github/workflows/pr-validation.yml +++ b/.github/workflows/pr-validation.yml @@ -7,6 +7,10 @@ on: pull_request: branches: [ main, dev ] +permissions: + contents: read + pull-requests: read + jobs: build: runs-on: ubuntu-latest @@ -15,7 +19,7 @@ jobs: php-versions: ['7.4', '8.0', '8.1', '8.2'] steps: - name: Checkout - uses: actions/checkout@v4.1.1 + uses: actions/checkout@v4.1.2 - name: Setup PHP and Xdebug for Code Coverage report uses: shivammathur/setup-php@v2 with: diff --git a/src/JsonSerializationWriter.php b/src/JsonSerializationWriter.php index dd19581..aa845b1 100644 --- a/src/JsonSerializationWriter.php +++ b/src/JsonSerializationWriter.php @@ -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); } } diff --git a/tests/JsonSerializationWriterTest.php b/tests/JsonSerializationWriterTest.php index c4832d5..3d1824f 100644 --- a/tests/JsonSerializationWriterTest.php +++ b/tests/JsonSerializationWriterTest.php @@ -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()); } } diff --git a/tests/Samples/Person.php b/tests/Samples/Person.php index 71c2045..577aed2 100644 --- a/tests/Samples/Person.php +++ b/tests/Samples/Person.php @@ -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 { @@ -19,6 +20,8 @@ class Person implements Parsable, AdditionalDataHolder private ?Address $address = null; private ?MaritalStatus $maritalStatus = null; + + private ?StreamInterface $bio = null; /** * @inheritDoc */ @@ -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());} ]; } @@ -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); } /** @@ -133,4 +138,20 @@ public function setAddress(?Address $address): void { $this->address = $address; } -} \ No newline at end of file + /** + * @param StreamInterface|null $bio + */ + public function setBio(?StreamInterface $bio): void + { + $this->bio = $bio; + } + + /** + * @return StreamInterface|null + */ + public function getBio(): ?StreamInterface + { + return $this->bio; + } + +}