Skip to content

JSON Schema validator incorrectly rejects unknown formatsย #973

@NexRX

Description

@NexRX

Describe the bug
Incorrectly throws errors when encountering unknown JSON Schema formats, specifically for me "format": "int64". According to JSON Schema Draft 7 specification, validators should ignore unknown formats, not reject them.

To Reproduce
Steps to reproduce the behavior:

  1. Create an OpenRPC specification with a schema containing "format": "int64"
  2. Use @open-rpc/schema-utils-js to validate the schema (e.g., via parseOpenRPCDocument)
  3. Initialize a client using the generated OpenRPC spec
  4. See error in additional context taken from console:

Expected behavior
According to JSON Schema Draft 7 specification:

A format attribute can generally only validate a given set of instance types. If the type of the instance to validate is not in this set, validation for this format attribute and instance SHOULD succeed.

or from JSON Schema Validation: A Vocabulary for Structural Validation of JSON

"An implementation MUST NOT fail to collect unknown formats as annotations."

Screenshots
Image

Desktop (please complete the following information):

  • OS: Windows
  • Browser: Chrome
  • Version: 140.0.7339.77

Additional context
I used the following command to generate the client which raised the error:
open-rpc-generator generate -t client -l typescript -n RpcClientTs -d ./spec.json -o ./generated
Attached is the spec

I used int64 as the format as that is what the rust crate schemars determined to be correct.

Full error:

Uncaught (in promise) Error: unknown format "int64" is used in schema at path "#"
    at Object.generate_format [as code] (@open-rpc_schema-utils-js.js?v=dc7beea9:5317:19)
    at generate_validate (@open-rpc_schema-utils-js.js?v=dc7beea9:4083:39)
    at localCompile (@open-rpc_schema-utils-js.js?v=dc7beea9:4239:26)
    at Ajv.compile (@open-rpc_schema-utils-js.js?v=dc7beea9:4212:17)
    at Ajv._compile (@open-rpc_schema-utils-js.js?v=dc7beea9:8173:27)
    at Ajv.getSchema (@open-rpc_schema-utils-js.js?v=dc7beea9:8061:45)
    at Ajv.validate (@open-rpc_schema-utils-js.js?v=dc7beea9:8003:18)
    at @open-rpc_schema-utils-js.js?v=dc7beea9:9283:48
    at Array.map (<anonymous>)
    at MethodCallValidator2.validate (@open-rpc_schema-utils-js.js?v=dc7beea9:9264:59)

spec.json

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions