microsoft / microsoft/kiota

PHP - anyOf/oneOf primitive type array serialization wrong

Open
#5,354 0 comments 0 reactions 0 assignees View on GitHub
PHP priority:p2 type:bug
Dominant language
C#
Stars
3.8k
Forks
333
Avg merge
16h 29m
Merged PRs (30d)
116

Description

related #5348

## Repo

```yaml
openapi: 3.0.3
info:
title: Example
description: Example
version: 1.0.0
servers:
- url: https://example.com/api
paths:
'/example1':
post:
summary: Test error generation.
description: "Test generating error with message property."
operationId: postErrorGeneration
responses:
'200':
description: Success
content:
application/json:
schema:
$ref: '#/components/schemas/Success'
components:
schemas:
Success:
type: object
oneOf:
- type: string
- type: array
items:
type: string
```

(or update to anyOf)

## deseralization

```php
public static function createFromDiscriminatorValue(ParseNode $parseNode): ItemPostRequestBody_tax_rates {
$result = new ItemPostRequestBody_tax_rates();
if ($parseNode->getStringValue() !== null) {
$result->setItemPostRequestBodyTaxRatesString($parseNode->getStringValue());
} else if ($parseNode->getCollectionOfObjectValues([string::class, 'createFromDiscriminatorValue']) !== null) {
$result->setString($parseNode->getCollectionOfObjectValues([string::class, 'createFromDiscriminatorValue']));
}
return $result;
}
````

Should instead call out getCollectionOfPrimitiveValues for the second case.

## serialization

```php
public function serialize(SerializationWriter $writer): void {
if ($this->getItemPostRequestBodyTaxRatesString() !== null) {
$writer->writeStringValue(null, $this->getItemPostRequestBodyTaxRatesString());
} else if ($this->getString() !== null) {
$writer->writeCollectionOfPrimitiveValues(null, $this->getString());
}
}

```

Should instead call writeCollectionOfPrimitiveValues for the second case, the conditions are inverted, and the property/getter `getItemPostRequestBodyTaxRatesString` should be an array of strings, not a simple string.

Contributor guide

Open the contributing guide

Research direction

Use the supplied OpenAPI schema with string and string-array oneOf or anyOf branches to inspect the generated PHP createFromDiscriminatorValue and serialize methods. Trace how primitive arrays are represented and emitted, then verify that generated output uses the primitive collection methods, the correct conditions, and an array-of-strings property.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, php
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.