@@ -14,7 +14,6 @@ const program = new Command();
1414program
1515 . name ( "codegen" )
1616 . description ( "json-rpc interface code generator" )
17- . version ( "0.0.9" )
1817 . argument ( '<schema>' , 'openapi.yml schema' )
1918 . option ( "-c, --client <string>" , "Generate TypeScript client interface" )
2019 . option ( "-s, --server <string>" , "Generate C++ server interface" )
@@ -63,6 +62,7 @@ export class Codegen {
6362
6463 public structs : Record < string , Struct > = { } ;
6564 public functions : Record < string , Function > = { } ;
65+ public rpcVersion : string = '0.0.0' ;
6666
6767 readonly header =
6868`/*
@@ -132,6 +132,8 @@ using namespace jsonrpccxx;\n`;
132132 return { } ;
133133 }
134134
135+ this . rpcVersion = doc ?. info ?. version ?? '0.0.0' ;
136+
135137 const methods : Record < string , Method > = { } ;
136138
137139 if ( doc ) {
@@ -427,7 +429,9 @@ using namespace jsonrpccxx;\n`;
427429 }
428430
429431 public genCpp ( ) {
430- const content = `${ this . header } \n${ this . cppHeader } \n${ this . genCppNamespace ( ) } \n${ this . genCppClass ( ) } \n${ this . cppFooter } \n` ;
432+ const content = `${ this . header } \n${ this . cppHeader }
433+ static constexpr const char* RPC_API_VERSION = "${ this . rpcVersion } ";\n
434+ ${ this . genCppNamespace ( ) } \n${ this . genCppClass ( ) } \n${ this . cppFooter } \n`;
431435 return content ;
432436 }
433437
@@ -477,7 +481,9 @@ using namespace jsonrpccxx;\n`;
477481 }
478482
479483 public genTs ( ) {
480- const content = `${ this . header } \n${ this . genTsTypeInterfaces ( ) } \n${ this . genTsInterface ( ) } \n${ this . genTsClass ( ) } ` ;
484+ const content = `${ this . header }
485+ export const RPC_API_VERSION = '${ this . rpcVersion } ' as const;\n
486+ ${ this . genTsTypeInterfaces ( ) } \n${ this . genTsInterface ( ) } \n${ this . genTsClass ( ) } `;
481487 return content ;
482488 }
483489}
0 commit comments