.yaml, .yml or .json.
+ *
+ * @return Destination file.
+ */
+ public @Nullable File getCopyOpenApiSpecTo() {
+ return copyOpenApiSpecTo;
+ }
+
+ /**
+ * Copy the generated OpenAPI spec to the given file. The format is determined by the file
+ * extension: .yaml, .yml or .json.
+ *
+ * Example: + * + *
{@code
+ * ${project.basedir}/docs/openapi.yaml
+ * }
+ *
+ * @param copyOpenApiSpecTo Destination file.
+ */
+ public void setCopyOpenApiSpecTo(@Nullable File copyOpenApiSpecTo) {
+ this.copyOpenApiSpecTo = copyOpenApiSpecTo;
+ }
}
diff --git a/modules/jooby-maven-plugin/src/test/java/io/jooby/maven/OpenAPIMojoTest.java b/modules/jooby-maven-plugin/src/test/java/io/jooby/maven/OpenAPIMojoTest.java
new file mode 100644
index 0000000000..e5c138a431
--- /dev/null
+++ b/modules/jooby-maven-plugin/src/test/java/io/jooby/maven/OpenAPIMojoTest.java
@@ -0,0 +1,57 @@
+package io.jooby.maven;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import io.jooby.openapi.OpenAPIGenerator;
+
+public class OpenAPIMojoTest {
+
+ @Test
+ public void specFormat() {
+ assertEquals(
+ OpenAPIGenerator.Format.YAML, OpenAPIMojo.specFormat(Path.of("docs/openapi.yaml")));
+ assertEquals(
+ OpenAPIGenerator.Format.YAML, OpenAPIMojo.specFormat(Path.of("docs/openapi.yml")));
+ assertEquals(
+ OpenAPIGenerator.Format.JSON, OpenAPIMojo.specFormat(Path.of("docs/openapi.json")));
+ assertThrows(
+ IllegalArgumentException.class, () -> OpenAPIMojo.specFormat(Path.of("docs/openapi.txt")));
+ }
+
+ @Test
+ public void copyYamlSpec(@TempDir Path tempDir) throws Exception {
+ var outputDir = tempDir.resolve("classes/myapp");
+ Files.createDirectories(outputDir);
+ var source = outputDir.resolve("App.yaml");
+ Files.writeString(source, "openapi: 3.0.1");
+
+ var destination = tempDir.resolve("docs/openapi.yml");
+ OpenAPIMojo.copySpec(List.of(source), destination);
+
+ assertTrue(Files.isRegularFile(destination));
+ assertEquals(Files.readString(source), Files.readString(destination));
+ }
+
+ @Test
+ public void copyJsonSpec(@TempDir Path tempDir) throws Exception {
+ var outputDir = tempDir.resolve("classes/myapp");
+ Files.createDirectories(outputDir);
+ var source = outputDir.resolve("App.json");
+ Files.writeString(source, "{\"openapi\":\"3.0.1\"}");
+
+ var destination = tempDir.resolve("docs/openapi.json");
+ OpenAPIMojo.copySpec(List.of(source), destination);
+
+ assertTrue(Files.isRegularFile(destination));
+ assertEquals(Files.readString(source), Files.readString(destination));
+ }
+}