added additonal property key to rename on the sdk generator

This commit is contained in:
ArnabChatterjee20k
2026-04-30 17:47:31 +05:30
parent 971858078c
commit 8597d48e41
4 changed files with 40 additions and 8 deletions
@@ -825,6 +825,13 @@ 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)) {
@@ -807,6 +807,13 @@ 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,6 +12,26 @@ 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
*
@@ -19,6 +19,9 @@ 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,
@@ -83,15 +86,10 @@ class Presence extends Any
'required' => false,
'default' => null,
'example' => self::TYPE_DATETIME_EXAMPLE,
])
// not adding hostname here in the response model
->addRule('metadata', [
'type' => self::TYPE_STRING,
'description' => 'Presence metadata.',
'required' => false,
'default' => [],
'example' => ['device' => 'web'],
]);
// `hostname` is intentionally not exposed.
// User-defined extras flow through Any's generic mapping, surfaced under
// the "metadata" key declared via setAdditionalPropertiesKey() above.
}
public function filter(DatabaseDocument $document): DatabaseDocument