diff --git a/src/Appwrite/SDK/Specification/Format.php b/src/Appwrite/SDK/Specification/Format.php index 47c683b358..b60d16274f 100644 --- a/src/Appwrite/SDK/Specification/Format.php +++ b/src/Appwrite/SDK/Specification/Format.php @@ -263,17 +263,6 @@ abstract class Format return $contents; } - protected function getRegisteredModel(string $type): Model - { - foreach ($this->models as $model) { - if ($model->getType() === $type) { - return $model; - } - } - - throw new \RuntimeException("Unresolved model '{$type}'. Ensure the model is registered."); - } - /** * @param array $models * @return array|null diff --git a/src/Appwrite/SDK/Specification/Format/OpenAPI3.php b/src/Appwrite/SDK/Specification/Format/OpenAPI3.php index bb9451ff4d..72dac7064a 100644 --- a/src/Appwrite/SDK/Specification/Format/OpenAPI3.php +++ b/src/Appwrite/SDK/Specification/Format/OpenAPI3.php @@ -907,7 +907,15 @@ class OpenAPI3 extends Format return ['$ref' => '#/components/schemas/' . $type]; }, $rule['type']), 'discriminator' => $this->getDisciminator( - \array_map(fn (string $type) => $this->getRegisteredModel($type), $rule['type']), + \array_map(function (string $type) { + foreach ($this->models as $model) { + if ($model->getType() === $type) { + return $model; + } + } + + throw new \RuntimeException("Unresolved model '{$type}'. Ensure the model is registered."); + }, $rule['type']), '#/components/schemas/' ), ]); @@ -917,7 +925,15 @@ class OpenAPI3 extends Format return ['$ref' => '#/components/schemas/' . $type]; }, $rule['type']), 'discriminator' => $this->getDisciminator( - \array_map(fn (string $type) => $this->getRegisteredModel($type), $rule['type']), + \array_map(function (string $type) { + foreach ($this->models as $model) { + if ($model->getType() === $type) { + return $model; + } + } + + throw new \RuntimeException("Unresolved model '{$type}'. Ensure the model is registered."); + }, $rule['type']), '#/components/schemas/' ), ]); diff --git a/src/Appwrite/SDK/Specification/Format/Swagger2.php b/src/Appwrite/SDK/Specification/Format/Swagger2.php index 5258fc8b7c..46280152e4 100644 --- a/src/Appwrite/SDK/Specification/Format/Swagger2.php +++ b/src/Appwrite/SDK/Specification/Format/Swagger2.php @@ -885,7 +885,15 @@ class Swagger2 extends Format $items = \array_filter([ 'x-anyOf' => \array_map(fn ($type) => ['$ref' => '#/definitions/' . $type], $rule['type']), 'x-discriminator' => $this->getDisciminator( - \array_map(fn (string $type) => $this->getRegisteredModel($type), $rule['type']), + \array_map(function (string $type) { + foreach ($this->models as $model) { + if ($model->getType() === $type) { + return $model; + } + } + + throw new \RuntimeException("Unresolved model '{$type}'. Ensure the model is registered."); + }, $rule['type']), '#/definitions/' ), ]); @@ -893,7 +901,15 @@ class Swagger2 extends Format $items = \array_filter([ 'x-oneOf' => \array_map(fn ($type) => ['$ref' => '#/definitions/' . $type], $rule['type']), 'x-discriminator' => $this->getDisciminator( - \array_map(fn (string $type) => $this->getRegisteredModel($type), $rule['type']), + \array_map(function (string $type) { + foreach ($this->models as $model) { + if ($model->getType() === $type) { + return $model; + } + } + + throw new \RuntimeException("Unresolved model '{$type}'. Ensure the model is registered."); + }, $rule['type']), '#/definitions/' ), ]);