From fb7e302de4597277bea12757836f2ce988c805ee Mon Sep 17 00:00:00 2001 From: Lukas Bischofberger Date: Wed, 12 Jan 2022 12:31:56 +0100 Subject: [PATCH] add reserved-words-mappings parameter (#33) * add reserved-words-mappings parameter Add the option to pass the `--reserved-words-mappings` flag to the generator. * Update openapi_generator.bzl * test * Update openapi_generator.bzl --- internal/openapi_generator.bzl | 5 +++++ internal/test/BUILD.bazel | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/internal/openapi_generator.bzl b/internal/openapi_generator.bzl index b36a510..b7c439e 100644 --- a/internal/openapi_generator.bzl +++ b/internal/openapi_generator.bzl @@ -59,6 +59,10 @@ def _new_generator_command(ctx, declared_dir, rjars): gen_cmd += ' --type-mappings "{mappings}"'.format( mappings = _comma_separated_pairs(ctx.attr.type_mappings), ) + + gen_cmd += ' --reserved-words-mappings "{reserved_words_mappings}"'.format( + reserved_words_mappings = ",".join(ctx.attr.reserved_words_mappings), + ) if ctx.attr.api_package: gen_cmd += " --api-package {package}".format( @@ -161,6 +165,7 @@ _openapi_generator = rule( "system_properties": attr.string_dict(), "engine": attr.string(), "type_mappings": attr.string_dict(), + "reserved_words_mappings": attr.string_list(), "is_windows": attr.bool(mandatory = True), "_jdk": attr.label( default = Label("@bazel_tools//tools/jdk:current_java_runtime"), diff --git a/internal/test/BUILD.bazel b/internal/test/BUILD.bazel index 3c3f225..f0f1829 100644 --- a/internal/test/BUILD.bazel +++ b/internal/test/BUILD.bazel @@ -41,3 +41,13 @@ openapi_generator( "Integer": "java.math.BigDecimal", }, ) + +openapi_generator( + name = "petstore_java_reserved_words", + generator = "java", + spec = "petstore.yaml", + reserved_words_mappings = [ + "interface=interface", + ], +) +