Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tools/cmd/speccheck/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"regexp"
"strings"

openrpc "github.com/open-rpc/meta-schema"
openrpc "github.com/open-rpc/spec-types/generated/packages/go/v1_4"
"github.com/santhosh-tekuri/jsonschema/v5"
)

Expand Down
2 changes: 1 addition & 1 deletion tools/cmd/speccheck/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"os"

openrpc "github.com/open-rpc/meta-schema"
openrpc "github.com/open-rpc/spec-types/generated/packages/go/v1_4"
)

type ContentDescriptor struct {
Expand Down
3 changes: 1 addition & 2 deletions tools/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/ethereum/go-ethereum v1.17.3-0.20260413114535-ecae519972c0
github.com/holiman/uint256 v1.3.2
github.com/mattn/go-jsonpointer v0.0.1
github.com/open-rpc/meta-schema v0.0.0-20210416041958-626a15d0a618
github.com/open-rpc/spec-types/generated/packages/go v0.1.1
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1
github.com/santhosh-tekuri/jsonschema/v6 v6.0.2
golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3
Expand Down Expand Up @@ -92,7 +92,6 @@ require (
github.com/naoina/go-stringutil v0.1.0 // indirect
github.com/naoina/toml v0.1.2-0.20170918210437-9fafd6967416 // indirect
github.com/open-rpc/openrpc-linter v0.0.16 // indirect
github.com/open-rpc/spec-types/generated/packages/go v0.1.1 // indirect
github.com/opentracing/opentracing-go v1.1.0 // indirect
github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7 // indirect
github.com/pion/dtls/v2 v2.2.7 // indirect
Expand Down
13 changes: 0 additions & 13 deletions tools/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,6 @@ github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9k
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
github.com/onsi/gomega v1.10.1 h1:o0+MgICZLuZ7xjH7Vx6zS/zcu93/BEp1VwkIW1mEXCE=
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/open-rpc/meta-schema v0.0.0-20210416041958-626a15d0a618 h1:EoH8oqYGi6BElF3PnUr65GoPVTtaDlnYkrVZct1Q/Sg=
github.com/open-rpc/meta-schema v0.0.0-20210416041958-626a15d0a618/go.mod h1:Ag6rSXkHIckQmjFBCweJEEt1mrTPBv8b9W4aU/NQWfI=
github.com/open-rpc/openrpc-linter v0.0.14 h1:xfK+gynIpYtDoT5iXZh5LvBGa/C+P2nCk39Zi//mkzk=
github.com/open-rpc/openrpc-linter v0.0.14/go.mod h1:5TxXfVxjYVLK3sWXdK5Kp4+/xpIbsU17dF7e3w/PamI=
github.com/open-rpc/openrpc-linter v0.0.16 h1:dkVWIuWGzV8hc09DPOicHb/OglJYBlyYD10C/Whjjys=
github.com/open-rpc/openrpc-linter v0.0.16/go.mod h1:5TxXfVxjYVLK3sWXdK5Kp4+/xpIbsU17dF7e3w/PamI=
github.com/open-rpc/spec-types/generated/packages/go v0.1.1 h1:eznQY3vMHCOy8ja79aUmBVhj2lEmpjqmLmscgMdVnBs=
Expand Down Expand Up @@ -306,13 +302,8 @@ github.com/santhosh-tekuri/jsonschema/v6 v6.0.2 h1:KRzFb2m7YtdldCEkzs6KqmJw4nqEV
github.com/santhosh-tekuri/jsonschema/v6 v6.0.2/go.mod h1:JXeL+ps8p7/KNMjDQk3TCwPpBy0wYklyWTfbkIzdIFU=
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible h1:Bn1aCHHRnjv4Bl16T8rcaFjYSrGrIZvpiGO6P3Q4GpU=
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo=
github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0=
github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU=
github.com/spf13/cobra v1.10.2/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiTUUS4=
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/pflag v1.0.7 h1:vN6T9TfwStFPFM5XzjsvmzZkLuaLX+HS+0SeFLRgU6M=
github.com/spf13/pflag v1.0.7/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
Expand Down Expand Up @@ -418,8 +409,6 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4=
golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down Expand Up @@ -473,8 +462,6 @@ golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.33.0 h1:B3njUFyqtHDUI5jMn1YIr5B0IE2U0qck04r6d4KPAxE=
golang.org/x/text v0.33.0/go.mod h1:LuMebE6+rBincTi9+xWTY8TztLzKHc/9C1uBCG27+q8=
golang.org/x/text v0.37.0 h1:Cqjiwd9eSg8e0QAkyCaQTNHFIIzWtidPahFWR83rTrc=
golang.org/x/text v0.37.0/go.mod h1:a5sjxXGs9hsn/AJVwuElvCAo9v8QYLzvavO5z2PiM38=
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down
41 changes: 30 additions & 11 deletions tools/internal/metaschema/metaschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@ package metaschema

import (
"encoding/json"
"strings"

openrpc "github.com/open-rpc/meta-schema"
openrpc "github.com/open-rpc/spec-types/generated/packages/go/v1_4"
"github.com/santhosh-tekuri/jsonschema/v6"
)

var openrpcSchemaRaw = openrpc.RawOpenrpc_document
var openrpcSchemaRaw = openrpc.RawOpenrpcDocument
var openrpcSchema *jsonschema.Schema

const OpenRpcSchemaURL = "https://meta.open-rpc.org/"
const draft07SchemaURL = "http://json-schema.org/draft-07/schema#"

var externalRefReplacements = map[string]string{
"https://meta.json-schema.tools": draft07SchemaURL,
"https://meta.json-schema.tools/#/definitions/JSONSchemaObject/properties/$ref": draft07SchemaURL + "/properties/$ref",
}

func init() {
var openrpcSchemaJSON = map[string]any{}
Expand All @@ -23,15 +30,7 @@ func init() {
// Override it to a supported JSON Schema draft so compilation doesn't require that metaschema.
openrpcSchemaJSON["$schema"] = "http://json-schema.org/draft-07/schema"

// The upstream OpenRPC meta-schema embeds a copy of the json-schema-tools meta-schema under
// `definitions.JSONSchema` and gives it `$id: https://meta.json-schema.tools/`.
// Remove those identifiers so the embedded definition behaves like a normal local subschema.
if defs, ok := openrpcSchemaJSON["definitions"].(map[string]any); ok {
if js, ok := defs["JSONSchema"].(map[string]any); ok {
delete(js, "$id")
delete(js, "$schema")
}
}
replaceExternalSchemaRefs(openrpcSchemaJSON)

compiler := jsonschema.NewCompiler()
err = compiler.AddResource(OpenRpcSchemaURL, openrpcSchemaJSON)
Expand All @@ -45,3 +44,23 @@ func init() {
func Validate(schema map[string]any) error {
return openrpcSchema.Validate(schema)
}

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.

here we shouldn't strip the json schema, but just point to the canonical draft07 schema. I made a PR to your fork on this branch. This will cause the json-schema tools to resolve locally without removing json schema validation.

func replaceExternalSchemaRefs(v any) {
switch x := v.(type) {
case map[string]any:
if ref, ok := x["$ref"].(string); ok && strings.Contains(ref, "json-schema.tools") {
if repl, found := externalRefReplacements[ref]; found {
x["$ref"] = repl
} else {
x["$ref"] = draft07SchemaURL
}
}
for _, vv := range x {
replaceExternalSchemaRefs(vv)
}
case []any:
for _, vv := range x {
replaceExternalSchemaRefs(vv)
}
}
}
2 changes: 1 addition & 1 deletion tools/internal/specgen/base-doc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"openrpc": "1.2.4",
"openrpc": "1.4.1",
"info": {
"title": "Ethereum JSON-RPC Specification",
"description": "A specification of the standard interface for Ethereum clients.",
Expand Down
Loading