mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
refactor(specs): inline model resolution
This commit is contained in:
@@ -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<Model> $models
|
||||
* @return array<string, mixed>|null
|
||||
|
||||
@@ -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/'
|
||||
),
|
||||
]);
|
||||
|
||||
@@ -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/'
|
||||
),
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user