Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ jobs:
needs: correct_repository
runs-on: ubuntu-latest
steps:
- uses: release-drafter/release-drafter@v6
- uses: release-drafter/release-drafter@b1476f6e6eb133afa41ed8589daba6dc69b4d3f5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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@77c5b412c50b723d2a4fbc6d71fb5723bcd439aa
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{github.event.release.target_commitish || 'main'}}
4 changes: 2 additions & 2 deletions .github/workflows/secrets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ jobs:
steps:
- uses: actions/checkout@v5
- name: wget
uses: wei/wget@v1
uses: wei/wget@c15e476d1463f4936cb54f882170d9d631f1aba5
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@bf2dc8e55639c1e091e9b45970152e4313705814
with:
config-path: .rules.toml
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
54 changes: 54 additions & 0 deletions boat-maven-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,60 @@ Same with `generate` but with opinionated defaults for Rest Template Client
</additionalProperties>
</configuration>

### 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):

<configuration>
...
<nameMappings>
<nameMapping>old_property_name=NewPropertyName</nameMapping>
<nameMapping>id=identifier</nameMapping>
</nameMappings>
<enumNameMappings>
<enumNameMapping>old_enum_name=NewEnumName</enumNameMapping>
<enumNameMapping>Status=ApiStatus</enumNameMapping>
</enumNameMappings>
</configuration>

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:

<plugin>
<groupId>com.backbase.oss</groupId>
<artifactId>boat-maven-plugin</artifactId>
<configuration>
<nameMappings>
<nameMapping>created_at=createdAt</nameMapping>
<nameMapping>updated_at=updatedAt</nameMapping>
</nameMappings>
<enumNameMappings>
<enumNameMapping>status=ResourceStatus</enumNameMapping>
</enumNameMappings>
</configuration>
</plugin>

## boat:generate-webclient-embedded

Same with `generate` but with opinionated defaults for Web Client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -492,15 +494,36 @@ static String uniqueJoin(Collection<String> values) {
private List<String> 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<String> schemaMappings;

/**
* A map of property names and the new names.
*/
@Parameter(name = "nameMappings", property = "openapi.generator.maven.plugin.nameMappings")
private List<String> nameMappings;

/**
* A map of enum names and the new names.
*/
@Parameter(name = "enumNameMappings", property = "openapi.generator.maven.plugin.enumNameMappings")
private List<String> enumNameMappings;


public void setBuildContext(BuildContext buildContext) {
this.buildContext = buildContext;
}

public void setNameMappings(List<String> nameMappings) {
this.nameMappings = nameMappings;
}

public void setEnumNameMappings(List<String> enumNameMappings) {
this.enumNameMappings = enumNameMappings;
}

@Override
@SuppressWarnings({"java:S3776", "java:S1874"})
public void execute() throws MojoExecutionException, MojoFailureException {
Expand Down Expand Up @@ -865,6 +888,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<String, String> entry : environmentVariables.entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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));
}

Expand Down Expand Up @@ -187,4 +197,25 @@ private <T extends GenerateMojo> 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);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down