From da365d490b49d7295af759219276489cc26e37df Mon Sep 17 00:00:00 2001 From: Roman Kniazevych Date: Thu, 25 Sep 2025 11:35:14 +0300 Subject: [PATCH 1/5] NOJIRA: Add additional openapi-generator parameter Allow to use `nameMappings` & `enumNameMappings` in BOAT maven plugin. "openapi.generator.maven.plugin.nameMappings"; "openapi.generator.maven.plugin.enumNameMappings" --- .../com/backbase/oss/boat/GenerateMojo.java | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/boat-maven-plugin/src/main/java/com/backbase/oss/boat/GenerateMojo.java b/boat-maven-plugin/src/main/java/com/backbase/oss/boat/GenerateMojo.java index 233cdabe1..1d57d83d3 100644 --- a/boat-maven-plugin/src/main/java/com/backbase/oss/boat/GenerateMojo.java +++ b/boat-maven-plugin/src/main/java/com/backbase/oss/boat/GenerateMojo.java @@ -7,12 +7,14 @@ import static org.apache.commons.lang3.StringUtils.isNotEmpty; import static org.openapitools.codegen.config.CodegenConfiguratorUtils.applyAdditionalPropertiesKvp; import static org.openapitools.codegen.config.CodegenConfiguratorUtils.applyAdditionalPropertiesKvpList; +import static org.openapitools.codegen.config.CodegenConfiguratorUtils.applyEnumNameMappingsKvpList; import static org.openapitools.codegen.config.CodegenConfiguratorUtils.applyImportMappingsKvp; import static org.openapitools.codegen.config.CodegenConfiguratorUtils.applyImportMappingsKvpList; import static org.openapitools.codegen.config.CodegenConfiguratorUtils.applyInstantiationTypesKvp; import static org.openapitools.codegen.config.CodegenConfiguratorUtils.applyInstantiationTypesKvpList; import static org.openapitools.codegen.config.CodegenConfiguratorUtils.applyLanguageSpecificPrimitivesCsv; import static org.openapitools.codegen.config.CodegenConfiguratorUtils.applyLanguageSpecificPrimitivesCsvList; +import static org.openapitools.codegen.config.CodegenConfiguratorUtils.applyNameMappingsKvpList; import static org.openapitools.codegen.config.CodegenConfiguratorUtils.applyOpenAPINormalizerKvpList; import static org.openapitools.codegen.config.CodegenConfiguratorUtils.applyReservedWordsMappingsKvp; import static org.openapitools.codegen.config.CodegenConfiguratorUtils.applyReservedWordsMappingsKvpList; @@ -492,11 +494,24 @@ static String uniqueJoin(Collection values) { private List openapiNormalizer; /** - * A map of scheme and the new one + * A map of scheme and the new one. */ @Parameter(name = "schemaMappings", property = "openapi.generator.maven.plugin.schemaMappings") private List schemaMappings; + /** + * A map of property names and the new names. + */ + @Parameter(name = "nameMappings", property = "openapi.generator.maven.plugin.nameMappings") + private List nameMappings; + + /** + * A map of enum names and the new names. + */ + @Parameter(name = "enumNameMappings", property = "openapi.generator.maven.plugin.enumNameMappings") + private List enumNameMappings; + + public void setBuildContext(BuildContext buildContext) { this.buildContext = buildContext; } @@ -865,6 +880,16 @@ public void execute() throws MojoExecutionException, MojoFailureException { applySchemaMappingsKvpList(schemaMappings, configurator); } + // Apply Name Mappings + if (nameMappings != null && (configOptions == null || !configOptions.containsKey("name-mappings"))) { + applyNameMappingsKvpList(nameMappings, configurator); + } + + // Apply Enum Name Mappings + if (enumNameMappings != null && (configOptions == null || !configOptions.containsKey("enum-name-mappings"))) { + applyEnumNameMappingsKvpList(enumNameMappings, configurator); + } + if (environmentVariables != null) { for (Entry entry : environmentVariables.entrySet()) { From de0c93da9d4630396434ad7212376de6ecea7ab2 Mon Sep 17 00:00:00 2001 From: Roman Kniazevych Date: Thu, 25 Sep 2025 15:03:58 +0300 Subject: [PATCH 2/5] fix sonar issue --- .../com/backbase/oss/codegen/java/MavenProjectCompiler.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/boat-scaffold/src/test/java/com/backbase/oss/codegen/java/MavenProjectCompiler.java b/boat-scaffold/src/test/java/com/backbase/oss/codegen/java/MavenProjectCompiler.java index 9e7df9b3d..c295fac3b 100644 --- a/boat-scaffold/src/test/java/com/backbase/oss/codegen/java/MavenProjectCompiler.java +++ b/boat-scaffold/src/test/java/com/backbase/oss/codegen/java/MavenProjectCompiler.java @@ -53,12 +53,11 @@ public int compile(File projectDir) { log.debug("Compiling mvn project in: {}", projectDir); var mavenCli = new MavenCli(new ClassWorld("myRealm", contextClassLoader)); final String initialDir = System.getProperty(MavenCli.MULTIMODULE_PROJECT_DIRECTORY); - try { + try(PrintStream out = new PrintStream(new File(projectDir, "mvn.log"))) { System.setProperty(MavenCli.MULTIMODULE_PROJECT_DIRECTORY, projectDir.getAbsolutePath()); String[] args = generateMavenCliArgs(); log.debug("mvn cli args: {}", Arrays.toString(args)); log.info("Building: {}", projectDir.getName()); - PrintStream out = new PrintStream(new File(projectDir, "mvn.log")); int compilationStatus = mavenCli.doMain(args, projectDir.getAbsolutePath(), out, out); log.debug("compilation status={}", compilationStatus); return compilationStatus; From 39f9469d51024b6918faf99e0f3d784aa3623b5f Mon Sep 17 00:00:00 2001 From: Roman Kniazevych Date: Thu, 25 Sep 2025 15:38:04 +0300 Subject: [PATCH 3/5] fix sonar security issue with general version; set direct commit hash --- .github/workflows/release-drafter.yml | 2 +- .github/workflows/release.yml | 2 +- .github/workflows/secrets.yml | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml index 316be6d6a..714a804ba 100644 --- a/.github/workflows/release-drafter.yml +++ b/.github/workflows/release-drafter.yml @@ -18,6 +18,6 @@ jobs: needs: correct_repository runs-on: ubuntu-latest steps: - - uses: release-drafter/release-drafter@v6 + - uses: release-drafter/release-drafter@b1476f6 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 617042144..9b35e5de3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -119,7 +119,7 @@ jobs: git commit -m "[version bump] new dev version" -a - name: Push Development Version to Branch - uses: ad-m/github-push-action@master + uses: ad-m/github-push-action@77c5b41 with: github_token: ${{ secrets.GITHUB_TOKEN }} branch: ${{github.event.release.target_commitish || 'main'}} diff --git a/.github/workflows/secrets.yml b/.github/workflows/secrets.yml index a6f7a25d6..1b9724224 100644 --- a/.github/workflows/secrets.yml +++ b/.github/workflows/secrets.yml @@ -8,10 +8,10 @@ jobs: steps: - uses: actions/checkout@v5 - name: wget - uses: wei/wget@v1 + uses: wei/wget@c15e476 with: args: -O .rules.toml https://raw.githubusercontent.com/fnxpt/gitleaks-action/rules/.rules.toml - name: gitleaks-action - uses: zricethezav/gitleaks-action@master + uses: gitleaks/gitleaks-action@bf2dc8e with: config-path: .rules.toml From 5c506796cd54af88844dae39019d3b31f3144f0e Mon Sep 17 00:00:00 2001 From: Roman Kniazevych Date: Thu, 25 Sep 2025 15:49:12 +0300 Subject: [PATCH 4/5] fix sonar security issue set direct commit full SHA hash --- .github/workflows/release-drafter.yml | 2 +- .github/workflows/release.yml | 2 +- .github/workflows/secrets.yml | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml index 714a804ba..dd3f508cf 100644 --- a/.github/workflows/release-drafter.yml +++ b/.github/workflows/release-drafter.yml @@ -18,6 +18,6 @@ jobs: needs: correct_repository runs-on: ubuntu-latest steps: - - uses: release-drafter/release-drafter@b1476f6 + - uses: release-drafter/release-drafter@b1476f6e6eb133afa41ed8589daba6dc69b4d3f5 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9b35e5de3..d6fdd8483 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -119,7 +119,7 @@ jobs: git commit -m "[version bump] new dev version" -a - name: Push Development Version to Branch - uses: ad-m/github-push-action@77c5b41 + uses: ad-m/github-push-action@77c5b412c50b723d2a4fbc6d71fb5723bcd439aa with: github_token: ${{ secrets.GITHUB_TOKEN }} branch: ${{github.event.release.target_commitish || 'main'}} diff --git a/.github/workflows/secrets.yml b/.github/workflows/secrets.yml index 1b9724224..f5199a2a1 100644 --- a/.github/workflows/secrets.yml +++ b/.github/workflows/secrets.yml @@ -8,10 +8,10 @@ jobs: steps: - uses: actions/checkout@v5 - name: wget - uses: wei/wget@c15e476 + uses: wei/wget@c15e476d1463f4936cb54f882170d9d631f1aba5 with: args: -O .rules.toml https://raw.githubusercontent.com/fnxpt/gitleaks-action/rules/.rules.toml - name: gitleaks-action - uses: gitleaks/gitleaks-action@bf2dc8e + uses: gitleaks/gitleaks-action@bf2dc8e55639c1e091e9b45970152e4313705814 with: config-path: .rules.toml From e1819ebe68163c1242d1161d1b0d112c20c45378 Mon Sep 17 00:00:00 2001 From: Roman Kniazevych Date: Fri, 26 Sep 2025 12:36:57 +0300 Subject: [PATCH 5/5] add tests and documentation --- README.md | 5 ++ boat-maven-plugin/README.md | 54 +++++++++++++++++++ .../com/backbase/oss/boat/GenerateMojo.java | 8 +++ .../backbase/oss/boat/GenerateMojoTests.java | 31 +++++++++++ .../test/resources/oas-examples/petstore.yaml | 9 ++++ 5 files changed, 107 insertions(+) diff --git a/README.md b/README.md index 7dfd5d9c1..9714ddb80 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,11 @@ It currently consists of # Release Notes BOAT is still under development and subject to change. + +## 0.17.63 +Add support params of openapi-generator `name-mappings` and `enum-name-mappings`. +Check `Property & Enum Name Mappings (new)` in [boat-maven-plugin](boat-maven-plugin/README.md) + ## 0.17.62 * Fixed reactive generation of code to not include extra Flux<> to return parameter ## 0.17.61 diff --git a/boat-maven-plugin/README.md b/boat-maven-plugin/README.md index b0009bf2c..52d2e551e 100644 --- a/boat-maven-plugin/README.md +++ b/boat-maven-plugin/README.md @@ -96,6 +96,60 @@ Same with `generate` but with opinionated defaults for Rest Template Client +### Property & Enum Name Mappings (new) + +Two new optional parameters are supported by the BOAT plugin (mirroring OpenAPI Generator capabilities) to rename generated members without post-processing: + + nameMappings A map of property names to their new names. + enumNameMappings A map of enum (symbol) names to their new names. + +You can configure them directly as top-level plugin parameters OR via `configOptions` using the underlying generator keys `name-mappings` and `enum-name-mappings`. + +Supported input formats: +1. Top-level list form (preferred for clarity): + + + ... + + old_property_name=NewPropertyName + id=identifier + + + old_enum_name=NewEnumName + Status=ApiStatus + + + +2. Via system properties / CLI (helpful for experimentation): + + mvn clean compile \ + -Dopenapi.generator.maven.plugin.nameMappings=old_property_name=NewPropertyName,id=identifier \ + -Dopenapi.generator.maven.plugin.enumNameMappings=old_enum_name=NewEnumName,Status=ApiStatus + +Rules & notes: +- Key/value pairs use '='. Whitespace around keys/values is trimmed. +- For multiple entries in system property form, separate by comma. +- Duplicate keys: last one wins. +- These mappings apply after any model / type renames from other mapping options. +- `nameMappings` affects property (field) identifiers in generated models & parameter names (where supported by the underlying generator). +- `enumNameMappings` affects enum constant identifiers (not their serialized wire values). To change wire values, adjust the OpenAPI schema itself. + +Example combining with other options: + + + com.backbase.oss + boat-maven-plugin + + + created_at=createdAt + updated_at=updatedAt + + + status=ResourceStatus + + + + ## boat:generate-webclient-embedded Same with `generate` but with opinionated defaults for Web Client diff --git a/boat-maven-plugin/src/main/java/com/backbase/oss/boat/GenerateMojo.java b/boat-maven-plugin/src/main/java/com/backbase/oss/boat/GenerateMojo.java index 1d57d83d3..73ee45dc6 100644 --- a/boat-maven-plugin/src/main/java/com/backbase/oss/boat/GenerateMojo.java +++ b/boat-maven-plugin/src/main/java/com/backbase/oss/boat/GenerateMojo.java @@ -516,6 +516,14 @@ public void setBuildContext(BuildContext buildContext) { this.buildContext = buildContext; } + public void setNameMappings(List nameMappings) { + this.nameMappings = nameMappings; + } + + public void setEnumNameMappings(List enumNameMappings) { + this.enumNameMappings = enumNameMappings; + } + @Override @SuppressWarnings({"java:S3776", "java:S1874"}) public void execute() throws MojoExecutionException, MojoFailureException { diff --git a/boat-maven-plugin/src/test/java/com/backbase/oss/boat/GenerateMojoTests.java b/boat-maven-plugin/src/test/java/com/backbase/oss/boat/GenerateMojoTests.java index 0b606443c..664959683 100644 --- a/boat-maven-plugin/src/test/java/com/backbase/oss/boat/GenerateMojoTests.java +++ b/boat-maven-plugin/src/test/java/com/backbase/oss/boat/GenerateMojoTests.java @@ -1,11 +1,14 @@ package com.backbase.oss.boat; +import static java.util.Collections.singletonList; import static java.util.Collections.singletonMap; +import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.endsWith; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasSize; +import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -14,6 +17,7 @@ import java.io.File; import java.util.HashMap; import java.util.Map; +import java.util.stream.Stream; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.project.MavenProject; @@ -55,8 +59,14 @@ void addTestCompileSourceRoot() throws MojoExecutionException, MojoFailureExcept void useJavaBoat() throws MojoExecutionException, MojoFailureException { GenerateMojo mojo = configure(new GenerateMojo(), "java"); + mojo.setEnumNameMappings(singletonList("LARGE=SUPER-BIG")); + mojo.setNameMappings(singletonList("size=petSize")); + mojo.execute(); + assertGeneratedClientModels(mojo.output, "Pet.java", "petSize"); + assertGeneratedClientModels(mojo.output, "Size.java", "SUPER-BIG"); + assertThat(mojo.generatorName, equalTo(BoatJavaCodeGen.NAME)); } @@ -187,4 +197,25 @@ private T configure(T mojo, String generatorName) { mojo.generatorName = generatorName; return mojo; } + + private void assertGeneratedClientModels(File mojoOutput, String fileName, String... expectedProperties) { + File dir = mojoOutput.getAbsoluteFile() + .toPath() + .resolve("src/main/java/org/openapitools/client/model") + .toFile(); + File target = new File(dir, fileName); + assertThat(target.exists(), is(true)); + try { + String content = java.nio.file.Files.readString( + target.toPath(), + java.nio.charset.StandardCharsets.UTF_8 + ); + assertAll(Stream.of(expectedProperties).map(prop -> + () -> assertThat("Expected content not found: " + prop, content.contains(prop), is(true)) + )); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + } diff --git a/boat-maven-plugin/src/test/resources/oas-examples/petstore.yaml b/boat-maven-plugin/src/test/resources/oas-examples/petstore.yaml index 137eaff93..e942c5b13 100644 --- a/boat-maven-plugin/src/test/resources/oas-examples/petstore.yaml +++ b/boat-maven-plugin/src/test/resources/oas-examples/petstore.yaml @@ -114,10 +114,19 @@ components: type: string tag: type: string + size: + $ref: '#/components/schemas/Size' Pets: type: array items: $ref: "#/components/schemas/Pet" + Size: + type: string + description: Size of the pet + enum: + - SMALL + - MEDIUM + - LARGE Error: type: object required: