Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/codegen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion api/csolution-openapi.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -784,6 +784,9 @@ components:
version:
type: string
description: Tool version
apiVersion:
type: string
description: API version
GetVersionResponse:
allOf:
- $ref: '#/x-jsonrpc-envelope-response'
Expand Down
12 changes: 9 additions & 3 deletions codegen/src/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const program = new Command();
program
.name("codegen")
.description("json-rpc interface code generator")
.version("0.0.9")
.argument('<schema>', 'openapi.yml schema')
.option("-c, --client <string>", "Generate TypeScript client interface")
.option("-s, --server <string>", "Generate C++ server interface")
Expand Down Expand Up @@ -63,6 +62,7 @@ export class Codegen {

public structs: Record<string, Struct> = {};
public functions: Record<string, Function> = {};
public rpcVersion: string = '0.0.0';

readonly header =
`/*
Expand Down Expand Up @@ -132,6 +132,8 @@ using namespace jsonrpccxx;\n`;
return {};
}

this.rpcVersion = doc?.info?.version ?? '0.0.0';

const methods: Record<string, Method> = {};

if (doc) {
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
}