Allow running OAPI generator without any pre-action

This commit is contained in:
Mustafa Gezen 2023-08-30 01:45:30 +02:00
parent 653d0736ed
commit 1f3100019e
Signed by: mustafa
GPG Key ID: DCDF010D946438C1
4 changed files with 28 additions and 24 deletions

View File

@ -36,10 +36,10 @@ func NewTemporalClient(host string, namespace string, opts client.Options) (clie
}
}
LogInfof("Connecting to Temporal at %s", host)
opts.HostPort = host
LogInfof("Using Temporal namespace %s", namespace)
// Register namespace (ignore error if already exists)
nscl, err := client.NewNamespaceClient(opts)
if err != nil {
@ -59,6 +59,8 @@ func NewTemporalClient(host string, namespace string, opts client.Options) (clie
// Set namespace in opts
opts.Namespace = namespace
LogInfof("Connecting to Temporal at %s", host)
// Dial Temporal
cl, err := client.Dial(opts)
if err != nil {

9
third_party/BUILD vendored
View File

@ -1,12 +1,13 @@
exports_files(["openapi-generator-cli-6.6.0.jar"])
java_binary(
name = "copybara_uberjar",
main_class = "com.google.copybara.Main",
runtime_deps = [":copybara_deploy.jar"],
)
java_binary(
name = "openapi_generator",
main_class = "org.openapitools.codegen.OpenAPIGenerator",
alias(
name = "openapi-generator-cli.jar",
actual = ":openapi-generator-cli-6.6.0.jar",
visibility = ["//visibility:public"],
runtime_deps = [":openapi-generator-cli-6.6.0.jar"],
)

View File

@ -16,9 +16,11 @@
set -euo pipefail
cli_bin="{{generator_cli_bin}}"
java_bin="{{java_bin}}"
cli_jar="{{generator_cli_jar}}"
generator="{{generator}}"
openapi_file="{{openapi_file}}"
output_dir="{{output_dir}}"
$cli_bin generate -i $openapi_file -g $generator -o $output_dir --skip-validate-spec > /dev/null
# Generate the client.
$java_bin -jar $cli_jar generate -i $openapi_file -g $generator -o $output_dir --skip-validate-spec > /dev/null

View File

@ -18,18 +18,9 @@ def _oapi_gen_ts_sdk_impl(ctx):
Converts an OpenAPI spec to a TypeScript SDK using openapi-generator.
"""
java_runtime = ctx.attr._jdk[java_common.JavaRuntimeInfo]
openapi = ctx.file.openapi
# java_binary returns the jar and a wrapper binary that runs it.
# we need the wrapper binary
oapi_cli_outputs = ctx.files._oapi_bin
oapi_cli = ""
for output in oapi_cli_outputs:
if output.path.endswith(".jar"):
continue
oapi_cli = output.path
break
# Run openapi-generator. With typescript we can just export a directory
# containing the generated code.
output_dir = ctx.actions.declare_directory(ctx.attr.name)
@ -39,18 +30,22 @@ def _oapi_gen_ts_sdk_impl(ctx):
template = ctx.file._oapi_converter,
output = gen,
substitutions = {
"{{generator_cli_bin}}": oapi_cli,
"{{generator_cli_jar}}": ctx.file._oapi_jar.path,
"{{openapi_file}}": openapi.path,
"{{generator}}": "typescript-fetch",
"{{output_dir}}": output_dir.path,
"{{java_bin}}": java_runtime.java_executable_exec_path,
},
is_executable = True,
)
ctx.actions.run(
inputs = [openapi] + ctx.files._oapi_bin,
inputs = [openapi] + java_runtime.files.to_list(),
outputs = [output_dir, index_ts],
executable = gen,
env = {
"JAVA_HOME": java_runtime.java_home,
},
)
return [
@ -67,10 +62,14 @@ oapi_gen_ts_sdk = rule(
mandatory = True,
doc = "The OpenAPI spec for the API, can be generated with protoc_gen_openapiv2",
),
"_oapi_bin": attr.label(
allow_files = True,
default = Label("//third_party:openapi_generator"),
doc = "The openapi-generator CLI binary",
"_jdk": attr.label(
default = Label("@bazel_tools//tools/jdk:current_host_java_runtime"),
providers = [java_common.JavaRuntimeInfo],
),
"_oapi_jar": attr.label(
allow_single_file = True,
default = Label("//third_party:openapi-generator-cli.jar"),
doc = "The openapi-generator CLI jar",
),
"_oapi_converter": attr.label(
allow_single_file = True,