Comfy-Org / Comfy-Org/ComfyUI_frontend

Add Zod schema validation for /api/features response

Open
#9,314 3 comments 0 reactions 1 assignee Claimed by @dante01yoon View on GitHub
Public API
Dominant language
TypeScript
Stars
2k
Forks
699
Avg merge
1d 7h
Merged PRs (30d)
490

Description

## Context

PR #9094 introduced `serverCapabilities.ts` which fetches server capabilities from `GET /api/features` and stores the JSON response directly. Currently no runtime schema validation is performed on the response.

## Problem

If the server returns malformed data (e.g. `supports_preview_metadata: "yes"` instead of `true`), the invalid value propagates to consumers. While `getServerCapability(key, defaultValue)` provides fallback defaults, type mismatches can still cause subtle bugs in boolean checks where truthy strings pass.

## Proposal

Add a Zod schema to validate the `/api/features` response:
- Define expected shape and types for known capability keys
- Use `safeParse` — on failure, log a warning and fall back to `EMPTY`
- Allow unknown keys to pass through (`.passthrough()`) for forward compatibility

## Related

- Part of #9079
- Raised in PR #9094 review ([comment](https://github.com/Comfy-Org/ComfyUI_frontend/pull/9094#discussion_r2867431083))

┆Issue is synchronized with this [Notion page](https://www.notion.so/Issue-9314-Add-Zod-schema-validation-for-api-features-response-3166d73d36508118bd0dfbf63a739705) by [Unito](https://www.unito.io)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.