fix(spec): mark DeviceStats.index and NodeInfo.essentials_category as nullable#13706
Conversation
… nullable
Two fields in openapi.yaml are declared as required/non-nullable but
the Python implementation legitimately returns `null` for them, so any
client that response-validates against the spec will fail.
`DeviceStats.index` (used by GET /api/system_stats):
- server.py emits `"index": device.index` unconditionally
- For the CPU device (--cpu mode), `torch.device("cpu").index` is `None`
- → JSON response includes `"index": null` for CPU devices
`NodeInfo.essentials_category` (used by GET /api/object_info):
- The V3 schema-based path (comfy_api/latest/_io.py:1654) unconditionally
passes `essentials_category=self.essentials_category` into NodeInfoV1
and serializes via dataclasses.asdict(), so the key is always present
- Schema's `essentials_category` defaults to `None` for nodes that
don't set it in `define_schema` (e.g. the APG node)
- → JSON response includes `"essentials_category": null` for those nodes
- (The V1 path in server.py uses `hasattr` and so omits the key
entirely when not set, but the V3 path is the one that produces nulls)
Both fields keep their existing `required` status — they're always
present in the response, the value is just nullable. Descriptions
expanded to spell out when `null` is expected.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe OpenAPI spec was updated: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Review rate limit: 1/5 review remaining, refill in 45 minutes and 17 seconds. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@openapi.yaml`:
- Around line 2512-2515: Update the description for the essentials category
field to clarify V1 behavior: change the text that currently states it is
"`null` for nodes that don't set `ESSENTIALS_CATEGORY` (V1)..." to say the key
may be omitted or set to null in V1; reference the field name
`essentials_category` (and env var `ESSENTIALS_CATEGORY`) in the sentence so
clients understand legacy V1 can omit the key entirely as well as return null.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: f6f73c5f-0c61-4200-a0b1-516ee7650c98
📒 Files selected for processing (1)
openapi.yaml
The previous description said "null for nodes that don't set ESSENTIALS_CATEGORY (V1)" — that's wrong. server.py:739-740 uses `hasattr` and OMITS the key when the V1 attribute isn't defined; null only happens if the attribute is explicitly set to None. Spell out all three legal shapes (string / null / absent) and which path produces which.
Summary
Two fields in
openapi.yamlare declared non-nullable but the Python implementation legitimately returnsnullfor them. This PR marks both fieldsnullable: trueso spec-driven response validators don't fail on conformant responses.DeviceStats.index(used byGET /api/system_stats)server.py:677emits\"index\": device.indexunconditionally. For the CPU device (--cpumode),torch.device(\"cpu\").indexisNoneper PyTorch convention, so the JSON response includes\"index\": null.The field stays in
required— it's always present in the response. Only the value can be null.NodeInfo.essentials_category(used byGET /api/object_info)Two emitters disagree on this field:
server.py:739-740only sets the key whenhasattr(obj_class, 'ESSENTIALS_CATEGORY'). Field absent for nodes that don't set it.comfy_api/latest/_io.py:1654unconditionally passesessentials_category=self.essentials_categoryintoNodeInfoV1, then serializes viadataclasses.asdict(). The dataclass default isNone, so for V3 nodes that don't setessentials_categoryindefine_schema(e.g. APG, incomfy_extras/nodes_apg.py) the JSON response includes\"essentials_category\": null.The field stays optional (already not in
required). Marking it nullable lets the V3-generatednullvalidate cleanly while still allowing the V1 "key absent" shape.Reproduction
Stand up ComfyUI in
--cpumode and validate the responses against the current spec with any OpenAPI 3.1 response validator (e.g.kin-openapi'sopenapi3filter.ValidateResponse):GET /api/system_stats→ `response body doesn't match schema #/components/schemas/SystemStatsResponse: Error at "/devices/0/index": Value is not nullable`GET /api/object_info→ `response body doesn't match schema: Error at "/APG/essentials_category": Value is not nullable`After this PR both validate cleanly.
Notes
nullis expected, so future readers don't have to re-derive it.kin-openapiafter the change.