From 765933a3149049121dde4f3deccda542ea54b5b1 Mon Sep 17 00:00:00 2001 From: ndr_brt Date: Tue, 20 Aug 2024 11:47:42 +0200 Subject: [PATCH] feat: permit to set spec version with property --- .../conventions/OpenApiMergerConvention.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/plugins/edc-build/src/main/java/org/eclipse/edc/plugins/edcbuild/conventions/OpenApiMergerConvention.java b/plugins/edc-build/src/main/java/org/eclipse/edc/plugins/edcbuild/conventions/OpenApiMergerConvention.java index 1377a0ba..627ee93a 100644 --- a/plugins/edc-build/src/main/java/org/eclipse/edc/plugins/edcbuild/conventions/OpenApiMergerConvention.java +++ b/plugins/edc-build/src/main/java/org/eclipse/edc/plugins/edcbuild/conventions/OpenApiMergerConvention.java @@ -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; @@ -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()); @@ -61,4 +67,10 @@ public void apply(Project target) { }); } } + + private String propertyOrElse(Project target, String key, Supplier orElse) { + return target.hasProperty(key) + ? target.property(key).toString() + : orElse.get(); + } }