Skip to content

Commit e7ae5b6

Browse files
committed
Export RPC API version
1 parent 92e2358 commit e7ae5b6

3 files changed

Lines changed: 24 additions & 4 deletions

File tree

.github/workflows/codegen.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,17 @@ jobs:
9696
name: codegen-rpc-interfaces
9797
path: generated
9898

99+
- name: Check release version tag
100+
run: |
101+
version=$(grep -oP 'RPC_API_VERSION\s*=\s*"\K[^"]+' RpcInterface.h)
102+
tag=${{ github.event.release.tag_name }}
103+
tag="${tag#v}"
104+
if [ "$tag" != "$version" ]; then
105+
echo "Release version does not match the version in generated interfaces. Update csolution-openapi.yml"
106+
exit 1
107+
fi
108+
working-directory: generated
109+
99110
- name: ZIP generated files
100111
run: zip -r csolution-rpc.zip RpcInterface.h rpc-interface.ts
101112
working-directory: generated

api/csolution-openapi.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
openapi: 3.1.0
22
info:
33
title: csolution rpc
4-
version: 0.0.3
4+
version: 0.0.4
55
description: Specification of remote procedure call methods for CMSIS csolution integration
66
license:
77
name: Apache 2.0
@@ -784,6 +784,9 @@ components:
784784
version:
785785
type: string
786786
description: Tool version
787+
apiVersion:
788+
type: string
789+
description: API version
787790
GetVersionResponse:
788791
allOf:
789792
- $ref: '#/x-jsonrpc-envelope-response'

codegen/src/codegen.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ const program = new Command();
1414
program
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

Comments
 (0)