@@ -6,6 +6,8 @@ import ReactMarkdown from "react-markdown";
66import { MethodObject , ExampleObject , ExamplePairingObject } from "@open-rpc/meta-schema" ;
77import _ from "lodash" ;
88
9+ export type TParamStructure = "either" | "by-name" | "by-position" ;
10+
911interface IProps extends WithStyles < typeof styles > {
1012 examplePosition ?: number ;
1113 method ?: MethodObject ;
@@ -31,10 +33,21 @@ class ExamplePairing extends Component<IProps, {}> {
3133 if ( ! example || _ . isEmpty ( example ) ) {
3234 return null ;
3335 }
36+ if ( ! method ) {
37+ return ;
38+ }
39+ const paramStructure : TParamStructure = method . paramStructure || "either" ;
40+ const params = paramStructure === "by-name"
41+ ? ( example . params as ExampleObject [ ] ) . reduce ( ( ( memo , p ) => {
42+ memo [ p . name ] = p . value ;
43+ return memo ;
44+ } ) , { } as any )
45+ : ( example . params as ExampleObject [ ] ) . map ( ( ( p ) => p . value ) ) ;
46+
3447 return (
3548 < Grid container spacing = { 10 } >
3649 < Grid item xs = { 12 } >
37- < ReactMarkdown source = { example . description } className = { classes . description } />
50+ < ReactMarkdown source = { example . description } className = { classes . description } />
3851 </ Grid >
3952 < Grid item xs = { 6 } >
4053 < Card >
@@ -43,7 +56,7 @@ class ExamplePairing extends Component<IProps, {}> {
4356 id : 1 ,
4457 jsonrpc : "2.0" ,
4558 method : method && method . name ,
46- params : ( example . params as ExampleObject [ ] ) . map ( ( ( p ) => p . value ) ) ,
59+ params,
4760 } } { ...this . props . reactJsonOptions } /> }
4861 </ CardContent >
4962 </ Card >
0 commit comments