Skip to content

fix: merge enum values for same-named enums across endpoints#1362

Closed
premtsd-code wants to merge 2 commits intomasterfrom
fix-sdk-enum-merge
Closed

fix: merge enum values for same-named enums across endpoints#1362
premtsd-code wants to merge 2 commits intomasterfrom
fix-sdk-enum-merge

Conversation

@premtsd-code
Copy link
Copy Markdown
Contributor

@premtsd-code premtsd-code commented Feb 23, 2026

Summary

  • Fix in_array($enumName, $list) bug in getRequestEnums() — it checked array values (which are always arrays) instead of keys (strings), so the check never matched and each endpoint silently overwrote the previous enum values
  • When multiple endpoints define the same enum name (e.g., Resources), the generator now merges all unique values into a single unified enum
  • This caused the Resources enum to only contain values from the last migration endpoint (NHost), missing resource types like function, deployment, site, provider, etc.

Related PR: appwrite/sdk-for-console#64

Summary by CodeRabbit

  • Bug Fixes
    • Improved enum handling in API specifications by properly merging and deduplicating enumeration values when duplicates are encountered, ensuring more accurate and consistent enum declarations.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 23, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0433335 and 8108354.

📒 Files selected for processing (1)
  • src/Spec/Swagger2.php
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/Spec/Swagger2.php

📝 Walkthrough

Walkthrough

The getRequestEnums method in src/Spec/Swagger2.php is modified to merge and deduplicate enum values and keys when an enumName already exists in the aggregation list, rather than skipping duplicates. Previously, duplicate enumNames were ignored; now they are consolidated with deduplicated values and keys.

Changes

Cohort / File(s) Summary
Enum Deduplication Logic
src/Spec/Swagger2.php
Modified getRequestEnums method to merge and deduplicate enum values and keys when an enumName already exists, instead of ignoring duplicates. New entries initialize keys to an empty array if missing.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A rabbit hops through enum fields,
Combining duplicates with zeal,
Merging keys and values true,
Deduplicated through and through!
No more scattered, now complete,

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main fix: merging enum values for same-named enums across endpoints, which directly addresses the bug fixed in the getRequestEnums method.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-sdk-enum-merge

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/Spec/Swagger2.php`:
- Around line 623-625: The assignment to $list[$enumName]['keys'] uses
array_unique without a mode, which collapses associative array entries because
PHP casts arrays to "Array" for string comparison; update the merge dedupe to
call array_unique(..., SORT_REGULAR) on the merged array of
$list[$enumName]['keys'] and $parameter['enumKeys'] (the line assigning
$list[$enumName]['keys']) so array elements are compared by content and enum key
metadata is preserved.
- Around line 620-625: The merge can receive null because $param['enumKeys']
(assigned from $parameter['x-enum-keys']) may be null; update the code so any
use of $parameter['enumKeys'] (and $param['enumKeys']) passed into array_merge
is defaulted to an empty array — e.g., when assigning and when merging into
$list[$enumName]['keys'] replace direct uses of $parameter['enumKeys'] with a
null-safe fallback (such as $parameter['enumKeys'] ?? []) so
array_merge($list[$enumName]['keys'], ...) never receives null; ensure the same
null-safe default is applied wherever $param['enumKeys'] might be merged or
initialized (references: $param['enumKeys'], $parameter['x-enum-keys'],
array_merge, $list[$enumName]['keys']).

In `@templates/cli/package.json.twig`:
- Line 49: The template currently references a non-published package version
("@appwrite.io/console": "^3.2.0"); update the dependency in
templates/cli/package.json.twig by changing the "@appwrite.io/console" version
from "^3.2.0" back to "^3.1.0" (or alternatively wait and ensure 3.2.0 is
published before merging) so generated CLIs will not fail during npm install.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b31e6b4 and 2cf9ab1.

📒 Files selected for processing (2)
  • src/Spec/Swagger2.php
  • templates/cli/package.json.twig

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@templates/cli/package.json.twig`:
- Line 49: Replace the mutable GitHub branch dependency for the console
SDK—specifically the entry "@appwrite.io/console":
"github:appwrite/sdk-for-console#dev"—with a published, pinned npm release (for
example "3.1.0" or a fixed semver like "^3.1.0") so installs are reproducible
and do not track the tip of the dev branch.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2cf9ab1 and 0433335.

📒 Files selected for processing (1)
  • templates/cli/package.json.twig

@premtsd-code premtsd-code force-pushed the fix-sdk-enum-merge branch 2 times, most recently from 4748b3c to e4201ba Compare February 23, 2026 13:13
@premtsd-code
Copy link
Copy Markdown
Contributor Author

Closing: fix belongs in appwrite repo Format.php, not sdk-generator

@premtsd-code premtsd-code deleted the fix-sdk-enum-merge branch February 24, 2026 11:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant