Skip to content

Commit

Permalink
fix: make empty params default to '{}' for methods with explicit by-n…
Browse files Browse the repository at this point in the history
…ame param structure in Inspector
  • Loading branch information
antoine-mulet committed Jun 19, 2020
1 parent 22d0b20 commit 8f84e81
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/plugins/InspectorPlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const InspectorPlugin: React.FC<IMethodPluginProps> = (props) => {
const examplePosition = 0;
let example;
let exampleParams: any;
let emptyParams = [] as any;
if (method && method.examples && method.examples[examplePosition]) {
example = method.examples[examplePosition] as ExamplePairingObject;
const paramStructure: TParamStructure = method.paramStructure || "either";
Expand All @@ -24,6 +25,9 @@ const InspectorPlugin: React.FC<IMethodPluginProps> = (props) => {
}), {} as any)
: (example.params as ExampleObject[]).map(((p) => p.value));
}
if (method && method.paramStructure === "by-name") {
emptyParams = {};
}
return (
<Tooltip title="Open in Inspector">
<Button variant="contained" onClick={() => setInspectorContents({
Expand All @@ -32,7 +36,7 @@ const InspectorPlugin: React.FC<IMethodPluginProps> = (props) => {
request: {
jsonrpc: "2.0",
method: method.name,
params: exampleParams || [],
params: exampleParams || emptyParams,
id: 0,
},
})}><span role="img" aria-label="try-it-inspector">🕵️‍♂️</span>️️ Try It Now</Button>
Expand All @@ -42,5 +46,3 @@ const InspectorPlugin: React.FC<IMethodPluginProps> = (props) => {
};

export default InspectorPlugin;


0 comments on commit 8f84e81

Please sign in to comment.