@@ -116,11 +116,23 @@ export async function loadMethods(openRpcJson: OpenrpcDocument): Promise<NimiqRp
116116 return result
117117}
118118
119+ function getTypeString ( schema : any ) : string {
120+ if ( schema . oneOf ) {
121+ // Handle union types like ValidityStartHeight
122+ return schema . oneOf . map ( ( s : any ) => s . type ) . join ( ' | ' )
123+ }
124+ if ( schema . type === 'array' && schema . items ) {
125+ const itemType = schema . items . type || 'any'
126+ return `${ itemType } []`
127+ }
128+ return schema . type || 'unknown'
129+ }
130+
119131function parseInput ( params : any [ ] ) {
120132 const isParamRequired = ( param : string ) => params . find ( p => p . name === param ) ?. required || false
121133 const input = params . map ( param => ( {
122134 key : param . name ,
123- type : param . schema . type ,
135+ type : getTypeString ( param . schema ) ,
124136 required : isParamRequired ( param . name ) ,
125137 label : param . humanReadableName ,
126138 } ) )
@@ -130,18 +142,18 @@ function parseInput(params: any[]) {
130142function parseOutput ( result : any ) {
131143 let output : { key : string , type : string , required : boolean , label : string } [ ] = [ ]
132144 if ( 'properties' in result . schema ) {
133- const isResultRequired = ( param : string ) => ( result . schema as any ) . required . includes ( param )
145+ const isResultRequired = ( param : string ) => ( result . schema as any ) . required ? .includes ( param ) || false
134146 const schema = ( result . schema as any ) . properties || [ ]
135147 const properties = Object . keys ( schema )
136148 output = properties . map ( ( prop : string ) => ( {
137149 key : prop ,
138- type : schema [ prop ] . type ,
150+ type : getTypeString ( schema [ prop ] ) ,
139151 required : isResultRequired ( prop ) ,
140152 label : schema [ prop ] . humanReadableName ,
141153 } ) )
142154 }
143- else if ( 'type' in result . schema ) {
144- output = [ { key : result . name , type : result . schema . type , required : true , label : result . humanReadableName } ]
155+ else if ( 'type' in result . schema || 'oneOf' in result . schema ) {
156+ output = [ { key : result . name , type : getTypeString ( result . schema ) , required : true , label : result . humanReadableName } ]
145157 }
146158 return output
147159}
0 commit comments