Skip to content

Commit

Permalink
feat: permit to set spec version with property
Browse files Browse the repository at this point in the history
  • Loading branch information
ndr-brt committed Aug 20, 2024
1 parent 1dbf5ea commit 765933a
Showing 1 changed file with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import org.eclipse.edc.plugins.edcbuild.extensions.BuildExtension;
import org.gradle.api.Project;

import java.util.function.Supplier;

import static org.eclipse.edc.plugins.edcbuild.conventions.ConventionFunctions.requireExtension;
import static org.eclipse.edc.plugins.edcbuild.conventions.SwaggerConvention.defaultOutputDirectory;

Expand Down Expand Up @@ -46,12 +48,16 @@ public void apply(Project target) {
outputExtension.getFileName().set("openapi");
});

var apiTitle = propertyOrElse(target, "apiTitle", () -> swaggerExt.getTitle().getOrNull());
var apiDescription = propertyOrElse(target, "apiDescription", swaggerExt::getDescription);
var apiVersion = propertyOrElse(target, "apiVersion", () -> target.getVersion().toString());

mergerExt.openApi(openApi -> {
openApi.getOpenApiVersion().set(OPEN_API_VERSION);
openApi.info(info -> {
info.getTitle().set(swaggerExt.getTitle());
info.getDescription().set(swaggerExt.getDescription());
info.getVersion().set(target.getVersion().toString());
info.getTitle().set(apiTitle);
info.getDescription().set(apiDescription);
info.getVersion().set(apiVersion);
info.license(license -> {
var mavenPomExt = buildExtension.getPom();
license.getName().set(mavenPomExt.getLicenseName());
Expand All @@ -61,4 +67,10 @@ public void apply(Project target) {
});
}
}

private String propertyOrElse(Project target, String key, Supplier<String> orElse) {
return target.hasProperty(key)
? target.property(key).toString()
: orElse.get();
}
}

0 comments on commit 765933a

Please sign in to comment.