From c3089acafc017eaef452066e9f72642cf527fa08 Mon Sep 17 00:00:00 2001 From: Jeff Gandt <76117044+jgandt-marq@users.noreply.github.com> Date: Wed, 6 Apr 2022 14:05:29 -0400 Subject: [PATCH] Add support for the template-dir flag This flag is supported by both swagger_cli and openapi_cli. Thus implementing it is as simple as passing in the flag to the cli, regardless of version. --- openapi/openapi.bzl | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/openapi/openapi.bzl b/openapi/openapi.bzl index fb3f7f0..c338020 100644 --- a/openapi/openapi.bzl +++ b/openapi/openapi.bzl @@ -120,6 +120,11 @@ def _new_generator_command(ctx, gen_dir, rjars): package = ctx.attr.model_package, ) + if ctx.file.template_dir: + gen_cmd += " --template-dir {template_dir}".format( + template_dir = ctx.file.template_dir.path, + ) + # fixme: by default, swagger-codegen is rather verbose. this helps with that but can also mask useful error messages # when it fails. look into log configuration options. it's a java app so perhaps just a log4j.properties or something gen_cmd += " 2>/dev/null" @@ -152,6 +157,7 @@ def _impl(ctx): inputs = ctx.files._jdk + [ ctx.file.codegen_cli, ctx.file.spec, + ctx.file.template_dir, ] + _collect_files(ctx.attr.spec_refs) + cjars.to_list() + rjars.to_list() ctx.actions.run_shell( inputs = inputs, @@ -214,6 +220,10 @@ openapi_gen = rule( allow_files = [".json", ".yaml"], default = [], ), + "template_dir": attr.label( + default = None, + allow_single_file = True, + ), # language to generate "language": attr.string(mandatory = True), "api_package": attr.string(),