linyaps/tools/run-openapi-generator-cli.sh

41 lines
1.4 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/env bash
# SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
#
# SPDX-License-Identifier: LGPL-3.0-or-later
set -x
set -e
GIT=${GIT:="git"}
repoRoot="$("$GIT" rev-parse --show-toplevel)"
cd "$repoRoot/tools"
output=../external/http
cppNamespace=linglong::api::client
# 单个接口可能存在有多个tagopenapi-generator-cli会为每个tag生成client文件
# 这些client之间有重复并且在客户端不会被用到所以这里只保留第一个tag
onlyFirstTag=KEEP_ONLY_FIRST_TAG_IN_OPERATION=true
# 服务端使用自定义的@X-Role生成接口权限文档openapi-generator-cli无法识别所以跳过验证
skipValidate=--skip-validate-spec
# 清理输出目录
rm -r $output || true
openapi-generator-cli() {
if [ -z "$OPENAPI_GENERATOR_CLI" ]; then
npm install @openapitools/openapi-generator-cli
exec npx openapi-generator-cli "$@"
else
exec $OPENAPI_GENERATOR_CLI "$@"
fi
}
openapi-generator-cli generate -g cpp-qt-client -o "$output" \
-i ../api/http/client_swagger.json \
$skipValidate \
--openapi-normalizer $onlyFirstTag \
--additional-properties="modelNamePrefix=,optionalProjectFile=false,cppNamespace=$cppNamespace" \
--package-name=QtLinglongRepoClientAPI \
--template-dir "$repoRoot/tools/openapi-cpp-qt-client"