Skip to content

feat(specs): let array params declare their item type - #14266

Merged
ChiragAgg5k merged 1 commit into
mainfrom
feat/spec-items-validator
Oct 8, 2026
Merged

ChiragAgg5k merged 1 commit into
mainfrom
feat/spec-items-validator

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #14265. After it, a param whose validator checks the whole array gets an array schema, but items is {}, because these validators don't say what an item is. Two params land there, and both are lists of strings:

  • WAF conditions (Utopia\WAF\Validator\Conditions): an array of condition strings.
  • OAuth2 resource (Multiple([], TYPE_ARRAY)): RFC 8707 resource indicator URIs, validated in the action.

Their SDK types came out as interface{} and Dict[str, Any] (flagged on appwrite/sdk-for-go#83 and appwrite/sdk-for-console-python#15). This adds both validators to OpenAPI3 and the GraphQL mapper:

  • Conditions joins Queries, Permissions and Roles as a list of strings.
  • Multiple emits its declared type, adding string items when that type is array. The webhook URL and health domain params use string-typed Multiples and come out unchanged.

testMultipleEmitsItsDeclaredType and testMultipleMapsToItsDeclaredType fail without the change.

Related: appwrite-labs/cloud#6413

@tenki-reviewer

tenki-reviewer Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Review complete. No blocking issues — approved ✅; 1 nitpick below.

🧹 Nitpicks (1) — 🟢 1 low
  • 🟢 Items drops the WhiteList enum promotion ArrayList gets (OpenAPI3.php:670) — In OpenAPI3.php the array-promotion block (src/Appwrite/SDK/Specification/Format/OpenAPI3.php:670) matches only ArrayList, setting $array = true and remapping $class to the inner WhiteList/Operation validator so the enum-producing case at line 869 runs.

This PR adds Appwrite\SDK\Specification\Validator\Items, a delegating validator that pairs an item validator with an isArray flag, so array parameters can describe their element type rather than just being ArrayList-wrapped.

Files Change
src/Appwrite/SDK/Specification/Validator/Items.php New validator wrapping an inner validator plus getType()/isArray() metadata, delegating isValid() unchanged.
src/Appwrite/SDK/Specification/Format/OpenAPI3.php Handles Items in the OpenAPI3 formatter, emitting type: array with a typed items schema.
src/Appwrite/GraphQL/Types/Mapper.php Maps Items validators in GraphQL type building.
tests/unit/GraphQL/BuilderTest.php, tests/unit/SDK/Specification/FormatTest.php Unit coverage for the new GraphQL mapping and OpenAPI3 output.

One low-severity latent gap: the WhiteList enum-promotion path that ArrayList triggers is not applied to Items, so an Items-wrapped WhiteList currently emits a plain string-array schema without the enum. No production call site hits that path yet.

Reviewed commit: b5908b3

@ChiragAgg5k ChiragAgg5k self-assigned this Oct 8, 2026
@hansi-codes

hansi-codes Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

🟡 Tier B · Needs changes before merging

The generic item-type declaration described by the PR is not implemented, and the new OpenAPI branch can emit an invalid schema for default Multiple validators.

The change updates GraphQL and OpenAPI mappings for WAF conditions and Multiple validators, including array and example handling. It also adds unit tests for these generator mappings.

Verdict New comments Fixed Still open
🛑 Changes requested 2 0 0
Finding Where
🟠 Array item types are hard-coded to string src/Appwrite/SDK/Specification/Format/OpenAPI3.php:827
🟡 Avoid emitting mixed as an OpenAPI type src/Appwrite/SDK/Specification/Format/OpenAPI3.php:825
Fix with agent prompt
### Issue 1
src/Appwrite/SDK/Specification/Format/OpenAPI3.php:827-828
**Array item types are hard-coded to string**

`Multiple` runs its rules against the whole value, so `TYPE_ARRAY` does not establish that each element is a string; the new test even uses an empty rule set. No item-validator wrapper or equivalent declaration is added, so array parameters with integer or object items cannot declare their type and both generators advertise them as string lists, leaving the described item-type feature unavailable beyond these special cases.

### Issue 2
src/Appwrite/SDK/Specification/Format/OpenAPI3.php:825
**Avoid emitting `mixed` as an OpenAPI type**

`Multiple` defaults to `Validator::TYPE_MIXED` (`packages/validators/src/Validator/Multiple.php`), so a default `new Multiple([...])` now emits `schema.type: mixed`. `mixed` is not a valid OpenAPI schema type, making the generated spec invalid for this supported validator construction.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
📂 Walkthrough · 4
File Change
src/Appwrite/GraphQL/Types/Mapper.php Maps WAF conditions and array-typed Multiple validators to GraphQL lists.
src/Appwrite/SDK/Specification/Format/OpenAPI3.php Adds OpenAPI schema handling for WAF conditions and Multiple validators.
tests/unit/GraphQL/BuilderTest.php Covers GraphQL type mappings for Multiple parameters.
tests/unit/SDK/Specification/FormatTest.php Covers OpenAPI schemas and examples for Multiple parameters.

Reviewed 326b7a1 · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@hansi-codes hansi-codes Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Tier S · Looks good to merge. Summary

@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

32 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (17)
  • php.appwrite.permissive-write-permission (8)
  • php.appwrite.secret-compare-timing (5)
  • php.appwrite.weak-secret-env-default (2)

Posted by Checks / Rules. Re-runs update this comment in place. Rule details and baseline: .semgrep/README.md.

Both check a whole array, so #14265 emitted them as arrays with untyped items and the SDKs typed WAF conditions and OAuth2 resource indicators as untyped values. Conditions always holds condition strings; an array-typed Multiple is only used for the resource indicator list, so both get string items in OpenAPI and GraphQL.
@ChiragAgg5k
ChiragAgg5k force-pushed the feat/spec-items-validator branch from b5908b3 to 326b7a1 Compare October 8, 2026 13:25
@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → feat/spec-items-validator (after).

⚠️ Before benchmark did not complete — change column unavailable.

⚠️ Current branch benchmark did not complete — showing available metrics only.

Metric Before After Change
🚀 Requests/sec n/a n/a n/a
⏱️ Latency P50 n/a n/a n/a
⏱️ Latency P95 n/a n/a n/a
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total n/a n/a n/a n/a n/a
Account n/a n/a n/a n/a n/a
TablesDB n/a n/a n/a n/a n/a
Storage n/a n/a n/a n/a n/a
Functions n/a n/a n/a n/a n/a

Top API waits (after)

API request Max wait (ms)
n/a n/a

@ChiragAgg5k
ChiragAgg5k merged commit 192d009 into main Oct 8, 2026
5 of 6 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the feat/spec-items-validator branch October 8, 2026 13:26

@hansi-codes hansi-codes Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Tier B · 1 blocking finding to address. Summary

Comment on lines +827 to +828
$node['schema']['items'] = [
'type' => 'string',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Array item types are hard-coded to string

Multiple runs its rules against the whole value, so TYPE_ARRAY does not establish that each element is a string; the new test even uses an empty rule set. No item-validator wrapper or equivalent declaration is added, so array parameters with integer or object items cannot declare their type and both generators advertise them as string lists, leaving the described item-type feature unavailable beyond these special cases.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Appwrite/SDK/Specification/Format/OpenAPI3.php
Line: 827-828

Comment:
**Array item types are hard-coded to string**

`Multiple` runs its rules against the whole value, so `TYPE_ARRAY` does not establish that each element is a string; the new test even uses an empty rule set. No item-validator wrapper or equivalent declaration is added, so array parameters with integer or object items cannot declare their type and both generators advertise them as string lists, leaving the described item-type feature unavailable beyond these special cases.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

🟠 Major · bug · Reply if this doesn't apply.

case \Utopia\Validator\Multiple::class:
// Its rules check the whole value, so an array-typed Multiple declares no
// item type. The only one in use is the OAuth2 resource indicator list.
$node['schema']['type'] = $validator->getType();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Avoid emitting mixed as an OpenAPI type

Multiple defaults to Validator::TYPE_MIXED (packages/validators/src/Validator/Multiple.php), so a default new Multiple([...]) now emits schema.type: mixed. mixed is not a valid OpenAPI schema type, making the generated spec invalid for this supported validator construction.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Appwrite/SDK/Specification/Format/OpenAPI3.php
Line: 825

Comment:
**Avoid emitting `mixed` as an OpenAPI type**

`Multiple` defaults to `Validator::TYPE_MIXED` (`packages/validators/src/Validator/Multiple.php`), so a default `new Multiple([...])` now emits `schema.type: mixed`. `mixed` is not a valid OpenAPI schema type, making the generated spec invalid for this supported validator construction.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

🟡 Minor · bug · Reply if this doesn't apply.

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