-
Notifications
You must be signed in to change notification settings - Fork 140
Description
Jane version(s) affected: next
Description
When iterating over an Model that has properties explicitly defined in an OpenAPI3.1 schema and has additional properties (see example below) only the additional properties are available via the iterator
How to reproduce
using a schema with an object such as:
"Schema": {
"properties": {
"_attachment": {
"anyOf": [
{
"type": "string",
"const": "binary"
},
{
"type": "null"
}
],
"title": "Attachment"
},
"body": {
"anyOf": [
{
"type": "string",
"const": "text"
},
{
"type": "null"
}
],
"title": "Body"
}
},
"additionalProperties": {
"$ref": "#/components/schemas/ValidFields"
},
"type": "object",
"title": "Schema"
}Will create a php object like the following:
<?php
namespace MyApp\Client\Model;
class Schema extends \ArrayObject
{
/**
* @var array
*/
protected $initialized = [];
public function isInitialized($property): bool
{
return array_key_exists($property, $this->initialized);
}
/**
* @var mixed
*/
protected $attachment;
/**
* @var mixed
*/
protected $body;
/**
* @return mixed
*/
public function getAttachment()
{
return $this->attachment;
}
/**
* @param mixed $attachment
*
* @return self
*/
public function setAttachment($attachment): self
{
$this->initialized['attachment'] = true;
$this->attachment = $attachment;
return $this;
}
/**
* @return mixed
*/
public function getBody()
{
return $this->body;
}
/**
* @param mixed $body
*
* @return self
*/
public function setBody($body): self
{
$this->initialized['body'] = true;
$this->body = $body;
return $this;
}
}A response from the api for this looks like:
{
"_attachment": "binary",
"body": "text",
"content": "text",
"created": "date",
"elemental_area": "text",
"last_edited": "date",
"link": "text",
"meta_title": "text",
"record_base_class": "text",
"record_id": "text",
"searchable_things": "text",
"source_class": "text",
"term_ids": "number",
"title": "text"
}when parsed into this model I can see it appears to be populated correctly eg:
however when iterating over this object eg:
$response = $indexService->getClient()->schemaGet($fullIndexName);
foreach ($response as $fieldName => $fieldType) {
$output->{$fieldName} = $fieldType;
}
return json_encode($output);$output only includes the additional properties (namely 'body' and 'attachment' are missing).
Possible Solution
Unsure, there's a bit of chat about issues using ArrayObject in places such as #704. I think the general direction is that there needs to be a specialised class/trait to handle additional properties. I guess there is some prior art in other languages such as python's pydantic which handles 'extra' data which is fairly similar to this scenario https://docs.pydantic.dev/latest/concepts/models/#extra-data
I'm happy to look into something/continue with PR704
Additional context