Skip to content

Commit f37ec3b

Browse files
author
Nithin Tatikonda
committed
enable generating html file with mojo
1 parent 07c6a89 commit f37ec3b

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

maven/src/main/java/org/openapitools/openapidiff/maven/OpenApiDiffMojo.java

+28-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package org.openapitools.openapidiff.maven;
22

3+
import java.io.File;
4+
import java.io.FileWriter;
5+
import java.io.IOException;
36
import org.apache.maven.plugin.AbstractMojo;
47
import org.apache.maven.plugin.MojoExecutionException;
58
import org.apache.maven.plugin.MojoFailureException;
@@ -9,6 +12,7 @@
912
import org.openapitools.openapidiff.core.OpenApiCompare;
1013
import org.openapitools.openapidiff.core.model.ChangedOpenApi;
1114
import org.openapitools.openapidiff.core.output.ConsoleRender;
15+
import org.openapitools.openapidiff.core.output.HtmlRender;
1216

1317
/** A Maven Mojo that diffs two OpenAPI specifications and reports on differences. */
1418
@Mojo(name = "diff", defaultPhase = LifecyclePhase.TEST)
@@ -25,6 +29,12 @@ public class OpenApiDiffMojo extends AbstractMojo {
2529
@Parameter(property = "failOnChanged", defaultValue = "false")
2630
Boolean failOnChanged = false;
2731

32+
@Parameter(property = "outputType")
33+
String outputType = "";
34+
35+
@Parameter(property = "outputFile")
36+
String outputFile = "";
37+
2838
@Parameter(property = "skip", defaultValue = "false")
2939
Boolean skip = false;
3040

@@ -37,7 +47,24 @@ public void execute() throws MojoExecutionException, MojoFailureException {
3747

3848
try {
3949
final ChangedOpenApi diff = OpenApiCompare.fromLocations(oldSpec, newSpec);
40-
getLog().info(new ConsoleRender().render(diff));
50+
51+
if (outputType == null || outputType.equals("")) {
52+
getLog().info(new ConsoleRender().render(diff));
53+
}
54+
55+
if (outputType.equalsIgnoreCase("html") || outputType.equalsIgnoreCase("html-detailed")) {
56+
boolean detailed = outputType.equalsIgnoreCase("html-detailed");
57+
File htmlFile = new File(outputFile);
58+
String htmlRender = new HtmlRender(detailed).render(diff);
59+
try {
60+
FileWriter fileWriter = new FileWriter(htmlFile);
61+
fileWriter.write(htmlRender);
62+
fileWriter.close();
63+
64+
} catch (IOException e) {
65+
throw new RuntimeException(e.getMessage());
66+
}
67+
}
4168

4269
if (failOnIncompatible && diff.isIncompatible()) {
4370
throw new BackwardIncompatibilityException("The API changes broke backward compatibility");

0 commit comments

Comments
 (0)