Skip to content

Commit 9e6f3b9

Browse files
authored
refactor: publish openapi artifact with api group as classifier (#247)
1 parent 8c9baf4 commit 9e6f3b9

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

plugins/edc-build/src/main/java/org/eclipse/edc/plugins/edcbuild/conventions/MavenArtifactConvention.java

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,34 @@ public void apply(Project target) {
5353
.map(p -> (MavenPublication) p)
5454
.peek(mavenPub -> mavenPub.pom(pom -> setPomInformation(pomExt, target, pom)))
5555
.forEach(mavenPub -> {
56-
5756
addArtifactIfExist(target, getManifestFile(target), mavenPub, artifact -> {
5857
artifact.setClassifier("manifest");
5958
artifact.setType("json");
6059
artifact.builtBy("autodoc");
6160
});
6261

63-
addArtifactIfExist(target, getOpenapiFile(target), mavenPub, artifact -> {
64-
artifact.setClassifier("openapi");
65-
artifact.setType("yaml");
66-
artifact.builtBy("openapi");
67-
});
62+
var openapiFiles = target.getLayout().getBuildDirectory().getAsFile().get().toPath()
63+
.resolve("docs").resolve("openapi").toFile()
64+
.listFiles((dir, name) -> name.endsWith(".yaml"));
65+
66+
if (openapiFiles != null) {
67+
for (var openapiFile : openapiFiles) {
68+
addArtifactIfExist(target, openapiFile, mavenPub, artifact -> {
69+
artifact.setClassifier(getFilenameWithoutExtension(openapiFile));
70+
artifact.setType("yaml");
71+
artifact.builtBy("openapi");
72+
});
73+
}
74+
}
75+
6876
});
6977
});
7078
}
7179

80+
private String getFilenameWithoutExtension(File openapiFile) {
81+
return openapiFile.getName().substring(0, openapiFile.getName().lastIndexOf("."));
82+
}
83+
7284
private void addArtifactIfExist(Project project, File location, MavenPublication mavenPublication, Action<ConfigurablePublishArtifact> configureAction) {
7385
if (location.exists()) {
7486
mavenPublication.getArtifacts()
@@ -83,12 +95,6 @@ private void addArtifactIfExist(Project project, File location, MavenPublication
8395
return Path.of(pathToManifest, manifestFileName).toFile();
8496
}
8597

86-
private static @NotNull File getOpenapiFile(Project target) {
87-
return target.getLayout().getBuildDirectory().getAsFile().get().toPath()
88-
.resolve("docs").resolve("openapi").resolve("openapi.yaml")
89-
.toFile();
90-
}
91-
9298
private static void setPomInformation(MavenPomExtension pomExt, Project project, MavenPom pom) {
9399
// these properties are mandatory!
94100
var projectName = pomExt.getProjectName().getOrElse(project.getName());

plugins/edc-build/src/main/java/org/eclipse/edc/plugins/edcbuild/conventions/SwaggerResolveConvention.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ public void apply(Project target) {
5656

5757
target.getTasks().withType(ResolveTask.class, task -> {
5858
var outputFileName = swaggerExt.getOutputFilename().getOrElse(target.getName());
59-
var apiGroup = swaggerExt.getApiGroup().getOrElse(DEFAULT_API_GROUP);
6059
var fallbackOutputDir = defaultOutputDirectory(target);
60+
var apiGroup = swaggerExt.getApiGroup().getOrElse(DEFAULT_API_GROUP);
6161

6262
var outputDir = Path.of(swaggerExt.getOutputDirectory().getOrElse(fallbackOutputDir.toFile()).toURI())
6363
.resolve(apiGroup)
@@ -81,7 +81,7 @@ public void apply(Project target) {
8181
target.getTasks().findByName("jar").dependsOn(task);
8282
task.setGroup("documentation");
8383
task.setDescription("Generates openapi specification documentation.");
84-
task.setOutputFileName("openapi");
84+
task.setOutputFileName(swaggerExt.getApiGroup().getOrElse("openapi"));
8585
task.setOutputDir(outputDir);
8686
task.setOutputFormat(ResolveTask.Format.YAML);
8787
task.setSortOutput(true);

0 commit comments

Comments
 (0)