Skip to content

Commit 9470402

Browse files
committed
fix: add support for params by name
1 parent 91cf2ae commit 9470402

File tree

1 file changed

+36
-11
lines changed

1 file changed

+36
-11
lines changed

src/containers/JSONRPCRequestEditor.tsx

+36-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useRef, useEffect } from "react";
22
import MonacoEditor from "@etclabscore/react-monaco-editor";
33
import * as monaco from "monaco-editor";
4-
import { MethodObject } from "@open-rpc/meta-schema";
4+
import { MethodObject, ContentDescriptorObject } from "@open-rpc/meta-schema";
55
import useWindowSize from "@rehooks/window-size";
66
import { addDiagnostics } from "@etclabscore/monaco-add-json-schema-diagnostics";
77

@@ -48,9 +48,6 @@ const JSONRPCRequestEditor: React.FC<IProps> = (props) => {
4848
method: {
4949
type: "string",
5050
},
51-
params: {
52-
type: "array",
53-
},
5451
},
5552
};
5653
if (props.openrpcMethodObject) {
@@ -64,13 +61,41 @@ const JSONRPCRequestEditor: React.FC<IProps> = (props) => {
6461
enum: [props.openrpcMethodObject.name],
6562
},
6663
params: {
67-
...schema.properties.params,
68-
items: props.openrpcMethodObject.params.map((param: any) => {
69-
return {
70-
...param.schema,
71-
additionalProperties: false,
72-
};
73-
}),
64+
oneOf: [
65+
{
66+
type: "array",
67+
...schema.properties.params,
68+
items: props.openrpcMethodObject.params.map((param: any) => {
69+
return {
70+
...param.schema,
71+
additionalProperties: false,
72+
};
73+
}),
74+
},
75+
{
76+
type: "object",
77+
properties: props.openrpcMethodObject.params.reduce((memo: any, param: any) => {
78+
memo[param.name] = {
79+
...param.schema,
80+
additionalProperties: false,
81+
};
82+
return memo;
83+
}, {}),
84+
},
85+
],
86+
},
87+
},
88+
};
89+
} else {
90+
schema = {
91+
additionalProperties: false,
92+
properties: {
93+
...schema.properties,
94+
params: {
95+
oneOf: [
96+
{ type: "array" },
97+
{ type: "object" },
98+
],
7499
},
75100
},
76101
};

0 commit comments

Comments
 (0)