1
0
Fork 0
mirror of synced 2024-09-29 17:01:37 +13:00

fix: openapi specification

This commit is contained in:
Torsten Dittmann 2023-03-10 15:36:10 +05:30
parent df9f1ee4c4
commit cb065e4228
11 changed files with 97 additions and 104 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -200,29 +200,11 @@ function updateAttribute(
throw new Exception(Exception::ATTRIBUTE_DEFAULT_UNSUPPORTED, 'Cannot set default value for array attributes');
}
$attributeChanged = false;
$collectionId = 'database_' . $db->getInternalId() . '_collection_' . $collection->getInternalId();
if ($default !== $attribute->getAttribute('default')) {
$attributeChanged = true;
$attribute->setAttribute('default', $default);
$dbForProject->updateAttributeDefault(
collection: $collectionId,
id: $key,
default: $default
);
}
if ($required !== $attribute->getAttribute('required')) {
$attributeChanged = true;
$attribute->setAttribute('required', $required);
$dbForProject->updateAttributeRequired(
collection: $collectionId,
id: $key,
required: $required
);
}
$attribute
->setAttribute('default', $default)
->setAttribute('required', $required);
$formatOptions = $attribute->getAttribute('formatOptions');
@ -250,8 +232,6 @@ function updateAttribute(
'max' => $max
];
$attribute->setAttribute('formatOptions', $options);
$dbForProject->updateAttributeFormatOptions(collection: $collectionId, id: $key, formatOptions: $options);
$attributeChanged = true;
break;
case APP_DATABASE_ATTRIBUTE_FLOAT_RANGE:
@ -281,8 +261,6 @@ function updateAttribute(
'max' => $max
];
$attribute->setAttribute('formatOptions', $options);
$dbForProject->updateAttributeFormatOptions(collection: $collectionId, id: $key, formatOptions: $options);
$attributeChanged = true;
break;
case APP_DATABASE_ATTRIBUTE_ENUM:
@ -303,28 +281,32 @@ function updateAttribute(
if (!is_null($default) && !in_array($default, $elements)) {
throw new Exception(Exception::ATTRIBUTE_VALUE_INVALID, 'Default value not found in elements');
}
$options = [
'elements' => $elements
];
$attribute->setAttribute('formatOptions', $options);
$dbForProject->updateAttributeFormatOptions(collection: $collectionId, id: $key, formatOptions: $options);
$attributeChanged = true;
break;
}
if ($attributeChanged) {
$dbForProject->updateDocument('attributes', $db->getInternalId() . '_' . $collection->getInternalId() . '_' . $key, $attribute);
$dbForProject->deleteCachedDocument('database_' . $db->getInternalId(), $collectionId);
}
$dbForProject->updateAttribute(
collection: $collectionId,
id: $key,
required: $required,
default: $default,
formatOptions: $options ?? null
);
$dbForProject->updateDocument('attributes', $db->getInternalId() . '_' . $collection->getInternalId() . '_' . $key, $attribute);
$dbForProject->deleteCachedDocument('database_' . $db->getInternalId(), $collectionId);
$events
->setContext('collection', $collection)
->setContext('database', $db)
->setParam('databaseId', $databaseId)
->setParam('collectionId', $collection->getId())
->setParam('attributeId', $attribute->getId())
;
->setParam('attributeId', $attribute->getId());
return $attribute;
}

View file

@ -43,13 +43,13 @@
"ext-sockets": "*",
"appwrite/php-clamav": "1.1.*",
"appwrite/php-runtimes": "0.11.*",
"utopia-php/abuse": "0.20.*",
"utopia-php/abuse": "0.21.*",
"utopia-php/analytics": "0.2.*",
"utopia-php/audit": "0.22.*",
"utopia-php/audit": "0.23.*",
"utopia-php/cache": "0.8.*",
"utopia-php/cli": "0.13.*",
"utopia-php/config": "0.2.*",
"utopia-php/database": "0.32.*",
"utopia-php/database": "0.33.*",
"utopia-php/preloader": "0.2.*",
"utopia-php/domains": "1.1.*",
"utopia-php/framework": "0.28.*",

123
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "a6abc919f27338638cf3d7c685152fb4",
"content-hash": "db9e7adb4caf775eaa200d3888b65579",
"packages": [
{
"name": "adhocore/jwt",
@ -693,16 +693,16 @@
},
{
"name": "guzzlehttp/psr7",
"version": "2.4.3",
"version": "2.4.4",
"source": {
"type": "git",
"url": "https://github.com/guzzle/psr7.git",
"reference": "67c26b443f348a51926030c83481b85718457d3d"
"reference": "3cf1b6d4f0c820a2cf8bcaec39fc698f3443b5cf"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/psr7/zipball/67c26b443f348a51926030c83481b85718457d3d",
"reference": "67c26b443f348a51926030c83481b85718457d3d",
"url": "https://api.github.com/repos/guzzle/psr7/zipball/3cf1b6d4f0c820a2cf8bcaec39fc698f3443b5cf",
"reference": "3cf1b6d4f0c820a2cf8bcaec39fc698f3443b5cf",
"shasum": ""
},
"require": {
@ -792,7 +792,7 @@
],
"support": {
"issues": "https://github.com/guzzle/psr7/issues",
"source": "https://github.com/guzzle/psr7/tree/2.4.3"
"source": "https://github.com/guzzle/psr7/tree/2.4.4"
},
"funding": [
{
@ -808,7 +808,7 @@
"type": "tidelift"
}
],
"time": "2022-10-26T14:07:24+00:00"
"time": "2023-03-09T13:19:02+00:00"
},
{
"name": "influxdb/influxdb-php",
@ -1808,23 +1808,23 @@
},
{
"name": "utopia-php/abuse",
"version": "0.20.0",
"version": "0.21.0",
"source": {
"type": "git",
"url": "https://github.com/utopia-php/abuse.git",
"reference": "4c2f3f25d2fed9b8d3c26312832f2380eed2fb4f"
"reference": "7483068b192b27d698da9534c80091f69666d5eb"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/utopia-php/abuse/zipball/4c2f3f25d2fed9b8d3c26312832f2380eed2fb4f",
"reference": "4c2f3f25d2fed9b8d3c26312832f2380eed2fb4f",
"url": "https://api.github.com/repos/utopia-php/abuse/zipball/7483068b192b27d698da9534c80091f69666d5eb",
"reference": "7483068b192b27d698da9534c80091f69666d5eb",
"shasum": ""
},
"require": {
"ext-curl": "*",
"ext-pdo": "*",
"php": ">=8.0",
"utopia-php/database": "0.32.*"
"utopia-php/database": "0.33.*"
},
"require-dev": {
"laravel/pint": "1.2.*",
@ -1851,9 +1851,9 @@
],
"support": {
"issues": "https://github.com/utopia-php/abuse/issues",
"source": "https://github.com/utopia-php/abuse/tree/0.20.0"
"source": "https://github.com/utopia-php/abuse/tree/0.21.0"
},
"time": "2023-03-02T05:01:35+00:00"
"time": "2023-03-10T08:49:10+00:00"
},
{
"name": "utopia-php/analytics",
@ -1912,28 +1912,27 @@
},
{
"name": "utopia-php/audit",
"version": "0.22.0",
"version": "0.23.0",
"source": {
"type": "git",
"url": "https://github.com/utopia-php/audit.git",
"reference": "410d105d87faeb55767c59a2bba848aa3c8f57ce"
"reference": "f16e893a22b93560d2af02afcb4761b3a940148a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/utopia-php/audit/zipball/410d105d87faeb55767c59a2bba848aa3c8f57ce",
"reference": "410d105d87faeb55767c59a2bba848aa3c8f57ce",
"url": "https://api.github.com/repos/utopia-php/audit/zipball/f16e893a22b93560d2af02afcb4761b3a940148a",
"reference": "f16e893a22b93560d2af02afcb4761b3a940148a",
"shasum": ""
},
"require": {
"ext-pdo": "*",
"php": ">=8.0",
"utopia-php/database": "0.32.*"
"utopia-php/database": "0.33.*"
},
"require-dev": {
"laravel/pint": "1.2.*",
"phpstan/phpstan": "^1.8",
"phpunit/phpunit": "^9.3",
"vimeo/psalm": "4.0.1"
"phpunit/phpunit": "^9.3"
},
"type": "library",
"autoload": {
@ -1955,9 +1954,9 @@
],
"support": {
"issues": "https://github.com/utopia-php/audit/issues",
"source": "https://github.com/utopia-php/audit/tree/0.22.0"
"source": "https://github.com/utopia-php/audit/tree/0.23.0"
},
"time": "2023-03-02T05:02:42+00:00"
"time": "2023-03-10T08:51:26+00:00"
},
{
"name": "utopia-php/cache",
@ -2114,23 +2113,23 @@
},
{
"name": "utopia-php/database",
"version": "0.32.0",
"version": "0.33.0",
"source": {
"type": "git",
"url": "https://github.com/utopia-php/database.git",
"reference": "f252f9cb58d93a9e2ef99915d743151da6f4e218"
"reference": "7453256728053cddfb0c872ac8ca60157c4d8a11"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/utopia-php/database/zipball/f252f9cb58d93a9e2ef99915d743151da6f4e218",
"reference": "f252f9cb58d93a9e2ef99915d743151da6f4e218",
"url": "https://api.github.com/repos/utopia-php/database/zipball/7453256728053cddfb0c872ac8ca60157c4d8a11",
"reference": "7453256728053cddfb0c872ac8ca60157c4d8a11",
"shasum": ""
},
"require": {
"php": ">=8.0",
"utopia-php/cache": "0.8.*",
"utopia-php/framework": "0.*.*",
"utopia-php/mongo": "0.0.2"
"utopia-php/mongo": "0.1.*"
},
"require-dev": {
"ext-mongodb": "*",
@ -2162,9 +2161,9 @@
],
"support": {
"issues": "https://github.com/utopia-php/database/issues",
"source": "https://github.com/utopia-php/database/tree/0.32.0"
"source": "https://github.com/utopia-php/database/tree/0.33.0"
},
"time": "2023-03-01T20:11:40+00:00"
"time": "2023-03-08T08:46:35+00:00"
},
{
"name": "utopia-php/domains",
@ -2222,16 +2221,16 @@
},
{
"name": "utopia-php/framework",
"version": "0.28.0",
"version": "0.28.1",
"source": {
"type": "git",
"url": "https://github.com/utopia-php/framework.git",
"reference": "d4f36ae8f62803a37dae3548977b8079dd045374"
"reference": "7f22c556fc5991e54e5811a68fb39809b21bda55"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/utopia-php/framework/zipball/d4f36ae8f62803a37dae3548977b8079dd045374",
"reference": "d4f36ae8f62803a37dae3548977b8079dd045374",
"url": "https://api.github.com/repos/utopia-php/framework/zipball/7f22c556fc5991e54e5811a68fb39809b21bda55",
"reference": "7f22c556fc5991e54e5811a68fb39809b21bda55",
"shasum": ""
},
"require": {
@ -2260,9 +2259,9 @@
],
"support": {
"issues": "https://github.com/utopia-php/framework/issues",
"source": "https://github.com/utopia-php/framework/tree/0.28.0"
"source": "https://github.com/utopia-php/framework/tree/0.28.1"
},
"time": "2023-03-01T19:48:36+00:00"
"time": "2023-03-02T08:16:01+00:00"
},
{
"name": "utopia-php/image",
@ -2470,16 +2469,16 @@
},
{
"name": "utopia-php/mongo",
"version": "0.0.2",
"version": "0.1.0",
"source": {
"type": "git",
"url": "https://github.com/utopia-php/mongo.git",
"reference": "62f9a9c0201af91b6d0dd4f0aa8a335ec9b56a1e"
"reference": "f4b6ec74c5323ca16c500dd19109518d2eeb1f8f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/utopia-php/mongo/zipball/62f9a9c0201af91b6d0dd4f0aa8a335ec9b56a1e",
"reference": "62f9a9c0201af91b6d0dd4f0aa8a335ec9b56a1e",
"url": "https://api.github.com/repos/utopia-php/mongo/zipball/f4b6ec74c5323ca16c500dd19109518d2eeb1f8f",
"reference": "f4b6ec74c5323ca16c500dd19109518d2eeb1f8f",
"shasum": ""
},
"require": {
@ -2524,9 +2523,9 @@
],
"support": {
"issues": "https://github.com/utopia-php/mongo/issues",
"source": "https://github.com/utopia-php/mongo/tree/0.0.2"
"source": "https://github.com/utopia-php/mongo/tree/0.1.0"
},
"time": "2022-11-08T11:58:46+00:00"
"time": "2023-01-12T14:02:08+00:00"
},
{
"name": "utopia-php/orchestration",
@ -3282,16 +3281,16 @@
},
{
"name": "myclabs/deep-copy",
"version": "1.11.0",
"version": "1.11.1",
"source": {
"type": "git",
"url": "https://github.com/myclabs/DeepCopy.git",
"reference": "14daed4296fae74d9e3201d2c4925d1acb7aa614"
"reference": "7284c22080590fb39f2ffa3e9057f10a4ddd0e0c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/14daed4296fae74d9e3201d2c4925d1acb7aa614",
"reference": "14daed4296fae74d9e3201d2c4925d1acb7aa614",
"url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/7284c22080590fb39f2ffa3e9057f10a4ddd0e0c",
"reference": "7284c22080590fb39f2ffa3e9057f10a4ddd0e0c",
"shasum": ""
},
"require": {
@ -3329,7 +3328,7 @@
],
"support": {
"issues": "https://github.com/myclabs/DeepCopy/issues",
"source": "https://github.com/myclabs/DeepCopy/tree/1.11.0"
"source": "https://github.com/myclabs/DeepCopy/tree/1.11.1"
},
"funding": [
{
@ -3337,20 +3336,20 @@
"type": "tidelift"
}
],
"time": "2022-03-03T13:19:32+00:00"
"time": "2023-03-08T13:26:56+00:00"
},
{
"name": "nikic/php-parser",
"version": "v4.15.3",
"version": "v4.15.4",
"source": {
"type": "git",
"url": "https://github.com/nikic/PHP-Parser.git",
"reference": "570e980a201d8ed0236b0a62ddf2c9cbb2034039"
"reference": "6bb5176bc4af8bcb7d926f88718db9b96a2d4290"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/570e980a201d8ed0236b0a62ddf2c9cbb2034039",
"reference": "570e980a201d8ed0236b0a62ddf2c9cbb2034039",
"url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/6bb5176bc4af8bcb7d926f88718db9b96a2d4290",
"reference": "6bb5176bc4af8bcb7d926f88718db9b96a2d4290",
"shasum": ""
},
"require": {
@ -3391,9 +3390,9 @@
],
"support": {
"issues": "https://github.com/nikic/PHP-Parser/issues",
"source": "https://github.com/nikic/PHP-Parser/tree/v4.15.3"
"source": "https://github.com/nikic/PHP-Parser/tree/v4.15.4"
},
"time": "2023-01-16T22:05:37+00:00"
"time": "2023-03-05T19:49:14+00:00"
},
{
"name": "phar-io/manifest",
@ -3741,16 +3740,16 @@
},
{
"name": "phpunit/php-code-coverage",
"version": "9.2.25",
"version": "9.2.26",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-code-coverage.git",
"reference": "0e2b40518197a8c0d4b08bc34dfff1c99c508954"
"reference": "443bc6912c9bd5b409254a40f4b0f4ced7c80ea1"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/0e2b40518197a8c0d4b08bc34dfff1c99c508954",
"reference": "0e2b40518197a8c0d4b08bc34dfff1c99c508954",
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/443bc6912c9bd5b409254a40f4b0f4ced7c80ea1",
"reference": "443bc6912c9bd5b409254a40f4b0f4ced7c80ea1",
"shasum": ""
},
"require": {
@ -3772,8 +3771,8 @@
"phpunit/phpunit": "^9.3"
},
"suggest": {
"ext-pcov": "*",
"ext-xdebug": "*"
"ext-pcov": "PHP extension that provides line coverage",
"ext-xdebug": "PHP extension that provides line coverage as well as branch and path coverage"
},
"type": "library",
"extra": {
@ -3806,7 +3805,7 @@
],
"support": {
"issues": "https://github.com/sebastianbergmann/php-code-coverage/issues",
"source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.25"
"source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.26"
},
"funding": [
{
@ -3814,7 +3813,7 @@
"type": "github"
}
],
"time": "2023-02-25T05:32:00+00:00"
"time": "2023-03-06T12:58:08+00:00"
},
{
"name": "phpunit/php-file-iterator",

View file

@ -8,6 +8,7 @@ use Appwrite\Utopia\Response\Model;
use Utopia\Database\Helpers\Permission;
use Utopia\Database\Helpers\Role;
use Utopia\Validator;
use Utopia\Validator\Nullable;
class OpenAPI3 extends Format
{
@ -281,6 +282,11 @@ class OpenAPI3 extends Format
}
}
if ($validator instanceof Nullable) {
$validator = $validator->getValidator();
$node['schema']['x-nullable'] = true;
}
switch ((!empty($validator)) ? \get_class($validator) : '') {
case 'Utopia\Validator\Text':
$node['schema']['type'] = $validator->getType();

View file

@ -8,6 +8,7 @@ use Appwrite\Utopia\Response\Model;
use Utopia\Database\Helpers\Permission;
use Utopia\Database\Helpers\Role;
use Utopia\Validator;
use Utopia\Validator\Nullable;
class Swagger2 extends Format
{
@ -282,6 +283,11 @@ class Swagger2 extends Format
}
}
if ($validator instanceof Nullable) {
$validator = $validator->getValidator();
$node['schema']['x-nullable'] = true;
}
switch ((!empty($validator)) ? \get_class($validator) : '') {
case 'Utopia\Validator\Text':
$node['type'] = $validator->getType();