Skip to content

Commit fdd7e68

Browse files
authored
feat: publish openapi spec as artifact (#245)
* feat: publish openapi spec as artifact * dependencies
1 parent 9a55b3c commit fdd7e68

File tree

6 files changed

+67
-32
lines changed

6 files changed

+67
-32
lines changed

DEPENDENCIES

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ maven/mavencentral/com.fasterxml.jackson/jackson-bom/2.17.1, Apache-2.0, approve
1212
maven/mavencentral/com.fasterxml/classmate/1.3.1, Apache-2.0, approved, CQ10239
1313
maven/mavencentral/com.github.fge/btf/1.2, Apache-2.0 OR LGPL-2.0-or-later, approved, CQ14455
1414
maven/mavencentral/com.github.fge/jackson-coreutils/1.6, Apache-2.0 or LGPL-3.0-only, approved, #2572
15-
maven/mavencentral/com.github.fge/jackson-coreutils/1.8, LGPL-3.0 OR Apache-2.0, approved, clearlydefined
15+
maven/mavencentral/com.github.fge/jackson-coreutils/1.8, (Apache-2.0 AND LGPL-3.0 AND LGPL-3.0-only) OR (Apache-2.0 AND LGPL-3.0-only), restricted, clearlydefined
1616
maven/mavencentral/com.github.fge/json-patch/1.6, Apache-2.0 OR LGPL-3.0-or-later, approved, #10358
1717
maven/mavencentral/com.github.fge/msg-simple/1.1, Apache-2.0 OR LGPL-3.0-or-later, approved, #2574
1818
maven/mavencentral/com.github.fge/uri-template/0.9, Apache-2.0 OR LGPL-3.0-or-later, approved, #9668
19-
maven/mavencentral/com.github.java-json-tools/json-schema-core/1.2.8, Apache-2.0 AND LGPL-2.1-or-later AND LGPL-3.0-only AND (Apache-2.0 AND GPL-1.0-or-later AND LGPL-3.0-only) AND Apache-2.0 AND LGPL-3.0-only, restricted, #15282
19+
maven/mavencentral/com.github.java-json-tools/json-schema-core/1.2.8, Apache-2.0 OR LGPL-3.0-or-later, approved, #15282
2020
maven/mavencentral/com.github.java-json-tools/json-schema-validator/2.2.8, Apache-2.0 OR LGPL-3.0-or-later, approved, CQ20779
2121
maven/mavencentral/com.google.code.findbugs/jsr305/2.0.1, BSD-3-Clause AND CC-BY-2.5 AND LGPL-2.1+, approved, CQ13390
2222
maven/mavencentral/com.google.code.findbugs/jsr305/3.0.1, CC-BY-2.5, approved, #15220
@@ -54,7 +54,7 @@ maven/mavencentral/io.opentelemetry/opentelemetry-api/1.32.0, Apache-2.0, approv
5454
maven/mavencentral/io.opentelemetry/opentelemetry-context/1.32.0, Apache-2.0, approved, #11683
5555
maven/mavencentral/io.swagger.core.v3/swagger-annotations/2.1.5, Apache-2.0, approved, clearlydefined
5656
maven/mavencentral/io.swagger.core.v3/swagger-core/2.1.5, Apache-2.0, approved, clearlydefined
57-
maven/mavencentral/io.swagger.core.v3/swagger-gradle-plugin/2.2.21, Apache-2.0 AND MIT, approved, #10356
57+
maven/mavencentral/io.swagger.core.v3/swagger-gradle-plugin/2.2.22, Apache-2.0 AND MIT, approved, #10356
5858
maven/mavencentral/io.swagger.core.v3/swagger-models/2.1.5, Apache-2.0, approved, clearlydefined
5959
maven/mavencentral/io.swagger.parser.v3/swagger-parser-core/2.0.23, Apache-2.0, approved, clearlydefined
6060
maven/mavencentral/io.swagger.parser.v3/swagger-parser-v2-converter/2.0.23, Apache-2.0, approved, clearlydefined

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jetbrainsAnnotation = "24.0.1"
1010
jakarta-ws-rs = "4.0.0"
1111
jupiter = "5.10.1"
1212
mockito = "5.12.0"
13-
swagger = "2.2.21"
13+
swagger = "2.2.22"
1414

1515
[libraries]
1616
assertj-core = { module = "org.assertj:assertj-core", version.ref = "assertj" }

plugins/autodoc/autodoc-plugin/src/main/java/org/eclipse/edc/plugins/autodoc/AutodocDependencyInjector.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,12 @@ public void beforeResolve(ResolvableDependencies dependencies) {
5151
project.getLogger().debug("{}: use configured version from AutodocExtension (override) [{}]", project.getName(), version);
5252
} else {
5353
artifact += ":+";
54-
project.getLogger().warn("No explicit configuration value for the annotationProcessor version was found. Please supply a configuration for the Autodoc Plugin's annotationProcessor.");
54+
project.getLogger().info("No explicit configuration value for the annotationProcessor version was found. Current one will be used");
5555
}
5656

5757
if (addDependency(project, artifact)) {
5858
var task = project.getTasks().findByName("compileJava");
59-
if ((task instanceof JavaCompile)) {
60-
var compileJava = (JavaCompile) task;
59+
if ((task instanceof JavaCompile compileJava)) {
6160
var versionArg = format("-A%s=%s", VERSION, project.getVersion());
6261
var idArg = format("-A%s=%s:%s", ID, project.getGroup(), project.getName());
6362
var outputArg = format("-A%s=%s", OUTPUTDIR, extension.getOutputDirectory().getOrNull());

plugins/autodoc/autodoc-plugin/src/main/java/org/eclipse/edc/plugins/autodoc/AutodocExtension.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ public abstract class AutodocExtension {
2222
private boolean includeTransitive = true;
2323

2424
/**
25-
* Overrides the default output directory relative to the current project dir
25+
* Overrides the default output directory relative to the current project dir.
26+
* By default, it is the "build" directory.
2627
*/
2728
public abstract Property<File> getOutputDirectory();
2829

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

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
import org.gradle.api.publish.PublishingExtension;
2525
import org.gradle.api.publish.maven.MavenPom;
2626
import org.gradle.api.publish.maven.MavenPublication;
27+
import org.jetbrains.annotations.NotNull;
2728

29+
import java.io.File;
2830
import java.nio.file.Path;
2931

3032
import static org.eclipse.edc.plugins.edcbuild.conventions.ConventionFunctions.requireExtension;
@@ -50,27 +52,41 @@ public void apply(Project target) {
5052
.filter(p -> p instanceof MavenPublication)
5153
.map(p -> (MavenPublication) p)
5254
.peek(mavenPub -> mavenPub.pom(pom -> setPomInformation(pomExt, target, pom)))
53-
.forEach(mavenPub -> addManifestArtifact(target, mavenPub));
55+
.forEach(mavenPub -> {
56+
57+
addArtifactIfExist(target, getManifestFile(target), mavenPub, artifact -> {
58+
artifact.setClassifier("manifest");
59+
artifact.setType("json");
60+
artifact.builtBy("autodoc");
61+
});
62+
63+
addArtifactIfExist(target, getOpenapiFile(target), mavenPub, artifact -> {
64+
artifact.setClassifier("openapi");
65+
artifact.setType("yaml");
66+
artifact.builtBy("openapi");
67+
});
68+
});
5469
});
5570
}
5671

57-
private Action<ConfigurablePublishArtifact> configureManifestArtifact() {
58-
return artifact -> {
59-
artifact.setClassifier("manifest");
60-
artifact.setType("json");
61-
artifact.builtBy("autodoc");
62-
};
72+
private void addArtifactIfExist(Project project, File location, MavenPublication mavenPublication, Action<ConfigurablePublishArtifact> configureAction) {
73+
if (location.exists()) {
74+
mavenPublication.getArtifacts()
75+
.artifact(project.getArtifacts().add("archives", location, configureAction));
76+
}
6377
}
6478

65-
private void addManifestArtifact(Project target, MavenPublication mavenPub) {
79+
private static @NotNull File getManifestFile(Project target) {
6680
var autodocExt = requireExtension(target, AutodocExtension.class);
67-
var pathToManifest = autodocExt.getOutputDirectory().getOrElse(target.getBuildDir()).getAbsolutePath();
81+
var pathToManifest = autodocExt.getOutputDirectory().getOrElse(target.getLayout().getBuildDirectory().getAsFile().get()).getAbsolutePath();
6882
var manifestFileName = "edc.json";
69-
var manifestFile = Path.of(pathToManifest, manifestFileName).toFile();
70-
if (manifestFile.exists()) {
71-
var jsonArtifact = target.getArtifacts().add("archives", manifestFile, configureManifestArtifact());
72-
mavenPub.getArtifacts().artifact(jsonArtifact);
73-
}
83+
return Path.of(pathToManifest, manifestFileName).toFile();
84+
}
85+
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();
7490
}
7591

7692
private static void setPomInformation(MavenPomExtension pomExt, Project project, MavenPom pom) {

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

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,26 +48,45 @@ public void apply(Project target) {
4848
"jakarta.ws.rs:jakarta.ws.rs-api:%s".formatted(Versions.JAKARTA_WS_RS)
4949
).forEach(dependency -> target.getDependencies().add(IMPLEMENTATION_CONFIGURATION_NAME, dependency));
5050

51-
var javaExt = requireExtension(target, JavaPluginExtension.class);
51+
var classpath = requireExtension(target, JavaPluginExtension.class)
52+
.getSourceSets().getAt("main").getRuntimeClasspath();
5253
var swaggerExt = requireExtension(target, BuildExtension.class).getSwagger();
53-
var fallbackOutputDir = defaultOutputDirectory(target);
54-
55-
var outputFileName = swaggerExt.getOutputFilename().getOrElse(target.getName());
56-
57-
var apiGroup = swaggerExt.getApiGroup().getOrElse(DEFAULT_API_GROUP);
58-
var outputDir = Path.of(swaggerExt.getOutputDirectory().getOrElse(fallbackOutputDir.toFile()).toURI())
59-
.resolve(apiGroup)
60-
.toFile();
6154

6255
var resourcePkgs = swaggerExt.getResourcePackages(); // already provides the default
6356

6457
target.getTasks().withType(ResolveTask.class, task -> {
58+
var outputFileName = swaggerExt.getOutputFilename().getOrElse(target.getName());
59+
var apiGroup = swaggerExt.getApiGroup().getOrElse(DEFAULT_API_GROUP);
60+
var fallbackOutputDir = defaultOutputDirectory(target);
61+
62+
var outputDir = Path.of(swaggerExt.getOutputDirectory().getOrElse(fallbackOutputDir.toFile()).toURI())
63+
.resolve(apiGroup)
64+
.toFile();
65+
6566
task.setOutputFileName(outputFileName);
6667
task.setOutputDir(outputDir);
6768
task.setOutputFormat(ResolveTask.Format.YAML);
6869
task.setSortOutput(true);
6970
task.setPrettyPrint(true);
70-
task.setClasspath(javaExt.getSourceSets().getAt("main").getRuntimeClasspath());
71+
task.setClasspath(classpath);
72+
task.setBuildClasspath(task.getClasspath());
73+
task.setResourcePackages(resourcePkgs);
74+
});
75+
76+
target.getTasks().register("openapi", ResolveTask.class).configure(task -> {
77+
var outputDir = target.getLayout().getBuildDirectory().getAsFile().get().toPath()
78+
.resolve("docs").resolve("openapi")
79+
.toFile();
80+
81+
target.getTasks().findByName("jar").dependsOn(task);
82+
task.setGroup("documentation");
83+
task.setDescription("Generates openapi specification documentation.");
84+
task.setOutputFileName("openapi");
85+
task.setOutputDir(outputDir);
86+
task.setOutputFormat(ResolveTask.Format.YAML);
87+
task.setSortOutput(true);
88+
task.setPrettyPrint(true);
89+
task.setClasspath(classpath);
7190
task.setBuildClasspath(task.getClasspath());
7291
task.setResourcePackages(resourcePkgs);
7392
});

0 commit comments

Comments
 (0)