Skip to content

JsonRpcResponseSchema violates JSON-RPC 2.0 spec by allowing both result and error #91

@petersalomonsen

Description

@petersalomonsen

The generated JsonRpcResponseSchema incorrectly makes both result and error optional, allowing invalid responses where both fields are present or both are absent.

Root Cause:
The OpenAPI spec correctly uses oneOf to enforce that exactly one of result or error must be present. However, the code generator in tools/codegen/generate.ts lines 590-594 hardcodes a simplified schema that ignores this constraint.

Expected:
Per JSON-RPC 2.0 spec, a response MUST contain either result OR error, never both, never neither.

Actual:
Current schema allows:

  • Both result and error present
  • Neither result nor error present

Fix:
Use Zod's union types to properly implement the oneOf constraint from the OpenAPI spec.

Location:

  • tools/codegen/generate.ts lines 590-594
  • packages/jsonrpc-types/src/schemas.ts lines 5450-5456
  • Test acknowledging this issue: packages/jsonrpc-types/src/__tests__/schemas.test.ts lines 145-165

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions