diff --git a/.github/workflows/codegen.yml b/.github/workflows/codegen.yml index fe0fbe0..3656394 100644 --- a/.github/workflows/codegen.yml +++ b/.github/workflows/codegen.yml @@ -96,6 +96,17 @@ jobs: name: codegen-rpc-interfaces path: generated + - name: Check release version tag + run: | + version=$(grep -oP 'RPC_API_VERSION\s*=\s*"\K[^"]+' RpcInterface.h) + tag=${{ github.event.release.tag_name }} + tag="${tag#v}" + if [ "$tag" != "$version" ]; then + echo "Release version does not match the version in generated interfaces. Update csolution-openapi.yml" + exit 1 + fi + working-directory: generated + - name: ZIP generated files run: zip -r csolution-rpc.zip RpcInterface.h rpc-interface.ts working-directory: generated diff --git a/api/csolution-openapi.yml b/api/csolution-openapi.yml index dac3aff..a1772dc 100644 --- a/api/csolution-openapi.yml +++ b/api/csolution-openapi.yml @@ -1,7 +1,7 @@ openapi: 3.1.0 info: title: csolution rpc - version: 0.0.3 + version: 0.0.4 description: Specification of remote procedure call methods for CMSIS csolution integration license: name: Apache 2.0 @@ -784,6 +784,9 @@ components: version: type: string description: Tool version + apiVersion: + type: string + description: API version GetVersionResponse: allOf: - $ref: '#/x-jsonrpc-envelope-response' diff --git a/codegen/src/codegen.ts b/codegen/src/codegen.ts index 2f0f1ac..2df6535 100644 --- a/codegen/src/codegen.ts +++ b/codegen/src/codegen.ts @@ -14,7 +14,6 @@ const program = new Command(); program .name("codegen") .description("json-rpc interface code generator") - .version("0.0.9") .argument('', 'openapi.yml schema') .option("-c, --client ", "Generate TypeScript client interface") .option("-s, --server ", "Generate C++ server interface") @@ -63,6 +62,7 @@ export class Codegen { public structs: Record = {}; public functions: Record = {}; + public rpcVersion: string = '0.0.0'; readonly header = `/* @@ -132,6 +132,8 @@ using namespace jsonrpccxx;\n`; return {}; } + this.rpcVersion = doc?.info?.version ?? '0.0.0'; + const methods: Record = {}; if (doc) { @@ -427,7 +429,9 @@ using namespace jsonrpccxx;\n`; } public genCpp() { - const content = `${this.header}\n${this.cppHeader}\n${this.genCppNamespace()}\n${this.genCppClass()}\n${this.cppFooter}\n`; + const content = `${this.header}\n${this.cppHeader} +static constexpr const char* RPC_API_VERSION = "${this.rpcVersion}";\n +${this.genCppNamespace()}\n${this.genCppClass()}\n${this.cppFooter}\n`; return content; } @@ -477,7 +481,9 @@ using namespace jsonrpccxx;\n`; } public genTs() { - const content = `${this.header}\n${this.genTsTypeInterfaces()}\n${this.genTsInterface()}\n${this.genTsClass()}`; + const content = `${this.header} +export const RPC_API_VERSION = '${this.rpcVersion}' as const;\n +${this.genTsTypeInterfaces()}\n${this.genTsInterface()}\n${this.genTsClass()}`; return content; } }