From bc6ecbd22cd34b1063332561587890e9bfb0f25d Mon Sep 17 00:00:00 2001 From: Darshan Date: Wed, 14 Jan 2026 17:15:33 +0530 Subject: [PATCH] address comments. --- app/config/specs/open-api3-1.8.x-console.json | 4 +- app/config/specs/swagger2-1.8.x-console.json | 4 +- .../SDK/Specification/Format/OpenAPI3.php | 40 +++++++++++++------ .../SDK/Specification/Format/Swagger2.php | 40 +++++++++++++------ 4 files changed, 58 insertions(+), 30 deletions(-) diff --git a/app/config/specs/open-api3-1.8.x-console.json b/app/config/specs/open-api3-1.8.x-console.json index 97c032720a..f7cbca76a5 100644 --- a/app/config/specs/open-api3-1.8.x-console.json +++ b/app/config/specs/open-api3-1.8.x-console.json @@ -28250,9 +28250,7 @@ "yammer", "yandex", "zoho", - "zoom", - "mock", - "mock-unverified" + "zoom" ], "x-enum-name": "OAuthProvider", "x-enum-keys": [] diff --git a/app/config/specs/swagger2-1.8.x-console.json b/app/config/specs/swagger2-1.8.x-console.json index f0e1c5608c..17064287be 100644 --- a/app/config/specs/swagger2-1.8.x-console.json +++ b/app/config/specs/swagger2-1.8.x-console.json @@ -28351,9 +28351,7 @@ "yammer", "yandex", "zoho", - "zoom", - "mock", - "mock-unverified" + "zoom" ], "x-enum-name": "OAuthProvider", "x-enum-keys": [] diff --git a/src/Appwrite/SDK/Specification/Format/OpenAPI3.php b/src/Appwrite/SDK/Specification/Format/OpenAPI3.php index ed5beff853..27dcf92923 100644 --- a/src/Appwrite/SDK/Specification/Format/OpenAPI3.php +++ b/src/Appwrite/SDK/Specification/Format/OpenAPI3.php @@ -604,16 +604,24 @@ class OpenAPI3 extends Format } } if ($allowed && $validator->getType() === 'string') { - $enumValues = \array_values($validator->getList()); + $allValues = \array_values($validator->getList()); + $allKeys = $this->getRequestEnumKeys($sdk->getNamespace() ?? '', $methodName, $name); + if ($excludeKeys !== null) { - $enumValues = \array_values(\array_filter($enumValues, fn ($key) => !\in_array($key, $excludeKeys, true))); + $keepIndices = []; + foreach ($allValues as $index => $value) { + if (!\in_array($value, $excludeKeys, true)) { + $keepIndices[] = $index; + } + } + $enumKeys = \array_values(\array_intersect_key($allKeys, \array_flip($keepIndices))); + $enumValues = \array_values(\array_intersect_key($allValues, \array_flip($keepIndices))); + } else { + $enumKeys = $allKeys; + $enumValues = $allValues; } $node['schema']['items']['enum'] = $enumValues; $node['schema']['items']['x-enum-name'] = $this->getRequestEnumName($sdk->getNamespace() ?? '', $methodName, $name); - $enumKeys = $this->getRequestEnumKeys($sdk->getNamespace() ?? '', $methodName, $name); - if ($excludeKeys !== null) { - $enumKeys = \array_values(\array_filter($enumKeys, fn ($key) => \in_array($key, $enumValues, true))); - } $node['schema']['items']['x-enum-keys'] = $enumKeys; } if ($validator->getType() === 'integer') { @@ -646,16 +654,24 @@ class OpenAPI3 extends Format } } if ($allowed && $validator->getType() === 'string') { - $enumValues = \array_values($validator->getList()); + $allValues = \array_values($validator->getList()); + $allKeys = $this->getRequestEnumKeys($sdk->getNamespace() ?? '', $methodName, $name); + if ($excludeKeys !== null) { - $enumValues = \array_values(\array_filter($enumValues, fn ($key) => !\in_array($key, $excludeKeys, true))); + $keepIndices = []; + foreach ($allValues as $index => $value) { + if (!\in_array($value, $excludeKeys, true)) { + $keepIndices[] = $index; + } + } + $enumKeys = \array_values(\array_intersect_key($allKeys, \array_flip($keepIndices))); + $enumValues = \array_values(\array_intersect_key($allValues, \array_flip($keepIndices))); + } else { + $enumKeys = $allKeys; + $enumValues = $allValues; } $node['schema']['enum'] = $enumValues; $node['schema']['x-enum-name'] = $this->getRequestEnumName($sdk->getNamespace() ?? '', $methodName, $name); - $enumKeys = $this->getRequestEnumKeys($sdk->getNamespace() ?? '', $methodName, $name); - if ($excludeKeys !== null) { - $enumKeys = \array_values(\array_filter($enumKeys, fn ($key) => \in_array($key, $enumValues, true))); - } $node['schema']['x-enum-keys'] = $enumKeys; } if ($validator->getType() === 'integer') { diff --git a/src/Appwrite/SDK/Specification/Format/Swagger2.php b/src/Appwrite/SDK/Specification/Format/Swagger2.php index dc135f15d4..de25a57ccc 100644 --- a/src/Appwrite/SDK/Specification/Format/Swagger2.php +++ b/src/Appwrite/SDK/Specification/Format/Swagger2.php @@ -588,16 +588,24 @@ class Swagger2 extends Format } } if ($allowed && $validator->getType() === 'string') { - $enumValues = \array_values($validator->getList()); + $allValues = \array_values($validator->getList()); + $allKeys = $this->getRequestEnumKeys($namespace, $methodName, $name); + if ($excludeKeys !== null) { - $enumValues = \array_values(\array_filter($enumValues, fn ($key) => !\in_array($key, $excludeKeys, true))); + $keepIndices = []; + foreach ($allValues as $index => $value) { + if (!\in_array($value, $excludeKeys, true)) { + $keepIndices[] = $index; + } + } + $enumKeys = \array_values(\array_intersect_key($allKeys, \array_flip($keepIndices))); + $enumValues = \array_values(\array_intersect_key($allValues, \array_flip($keepIndices))); + } else { + $enumKeys = $allKeys; + $enumValues = $allValues; } $node['items']['enum'] = $enumValues; $node['items']['x-enum-name'] = $this->getRequestEnumName($namespace, $methodName, $name); - $enumKeys = $this->getRequestEnumKeys($namespace, $methodName, $name); - if ($excludeKeys !== null) { - $enumKeys = \array_values(\array_filter($enumKeys, fn ($key) => \in_array($key, $enumValues, true))); - } $node['items']['x-enum-keys'] = $enumKeys; } if ($validator->getType() === 'integer') { @@ -624,16 +632,24 @@ class Swagger2 extends Format } } if ($allowed && $validator->getType() === 'string') { - $enumValues = \array_values($validator->getList()); + $allValues = \array_values($validator->getList()); + $allKeys = $this->getRequestEnumKeys($namespace, $methodName, $name); + if ($excludeKeys !== null) { - $enumValues = \array_values(\array_filter($enumValues, fn ($key) => !\in_array($key, $excludeKeys, true))); + $keepIndices = []; + foreach ($allValues as $index => $value) { + if (!\in_array($value, $excludeKeys, true)) { + $keepIndices[] = $index; + } + } + $enumKeys = \array_values(\array_intersect_key($allKeys, \array_flip($keepIndices))); + $enumValues = \array_values(\array_intersect_key($allValues, \array_flip($keepIndices))); + } else { + $enumKeys = $allKeys; + $enumValues = $allValues; } $node['enum'] = $enumValues; $node['x-enum-name'] = $this->getRequestEnumName($namespace, $methodName, $name); - $enumKeys = $this->getRequestEnumKeys($namespace, $methodName, $name); - if ($excludeKeys !== null) { - $enumKeys = \array_values(\array_filter($enumKeys, fn ($key) => \in_array($key, $enumValues, true))); - } $node['x-enum-keys'] = $enumKeys; } if ($validator->getType() === 'integer') {