mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
Merge pull request #12403 from appwrite/refactor/presence-metadata-typed-property
Refactor Presence to typed metadata property; drop additionalPropertiesKey hack + Swagger2 PHPStan unblock
This commit is contained in:
4 files changed
+9
-40
No files matched your search
@@ -857,13 +857,6 @@ class OpenAPI3 extends Format
|
||||
|
||||
if ($model->isAny()) {
|
||||
$output['components']['schemas'][$model->getType()]['additionalProperties'] = true;
|
||||
|
||||
$additionalKey = \method_exists($model, 'getAdditionalPropertiesKey')
|
||||
? $model->getAdditionalPropertiesKey()
|
||||
: null;
|
||||
if ($additionalKey !== null) {
|
||||
$output['components']['schemas'][$model->getType()]['x-additional-properties-key'] = $additionalKey;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($required)) {
|
||||
|
||||
@@ -820,13 +820,6 @@ class Swagger2 extends Format
|
||||
|
||||
if ($model->isAny()) {
|
||||
$output['definitions'][$model->getType()]['additionalProperties'] = true;
|
||||
|
||||
$additionalKey = \method_exists($model, 'getAdditionalPropertiesKey')
|
||||
? $model->getAdditionalPropertiesKey()
|
||||
: null;
|
||||
if ($additionalKey !== null) {
|
||||
$output['definitions'][$model->getType()]['x-additional-properties-key'] = $additionalKey;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($required)) {
|
||||
|
||||
@@ -12,26 +12,6 @@ class Any extends Model
|
||||
*/
|
||||
protected bool $any = true;
|
||||
|
||||
/**
|
||||
* JSON wire-format key under which extra/dynamic attributes are exposed in
|
||||
* generated SDK models (e.g. Document<T>'s `data` slot). Default null means
|
||||
* SDK templates fall back to their hardcoded "data" key. Set this on
|
||||
* subclasses (via setAdditionalPropertiesKey) to use a custom key like
|
||||
* "metadata" while still benefiting from the generic `Model<T>` mapping.
|
||||
*/
|
||||
protected ?string $additionalPropertiesKey = null;
|
||||
|
||||
public function setAdditionalPropertiesKey(string $key): self
|
||||
{
|
||||
$this->additionalPropertiesKey = $key;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAdditionalPropertiesKey(): ?string
|
||||
{
|
||||
return $this->additionalPropertiesKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Name
|
||||
*
|
||||
|
||||
@@ -3,9 +3,10 @@
|
||||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Utopia\Response\Model;
|
||||
use Utopia\Database\Document as DatabaseDocument;
|
||||
|
||||
class Presence extends Any
|
||||
class Presence extends Model
|
||||
{
|
||||
public function getName(): string
|
||||
{
|
||||
@@ -19,9 +20,6 @@ class Presence extends Any
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
// Expose user-defined extras under "metadata" instead of the SDK default "data"
|
||||
$this->setAdditionalPropertiesKey('metadata');
|
||||
|
||||
$this
|
||||
->addRule('$id', [
|
||||
'type' => self::TYPE_STRING,
|
||||
@@ -73,9 +71,14 @@ class Presence extends Any
|
||||
'required' => false,
|
||||
'default' => null,
|
||||
'example' => self::TYPE_DATETIME_EXAMPLE,
|
||||
])
|
||||
->addRule('metadata', [
|
||||
'type' => self::TYPE_JSON,
|
||||
'description' => 'Presence metadata.',
|
||||
'required' => false,
|
||||
'default' => null,
|
||||
'example' => ['key' => 'value'],
|
||||
]);
|
||||
// User-defined extras flow through Any's generic mapping, surfaced under
|
||||
// the "metadata" key declared via setAdditionalPropertiesKey() above.
|
||||
}
|
||||
|
||||
public function filter(DatabaseDocument $document): DatabaseDocument
|
||||
|
||||
Reference in new issue
Block a user