9
9
import org .openapitools .openapidiff .core .OpenApiCompare ;
10
10
import org .openapitools .openapidiff .core .model .ChangedOpenApi ;
11
11
import org .openapitools .openapidiff .core .output .ConsoleRender ;
12
+ import org .openapitools .openapidiff .core .output .HtmlRender ;
13
+
14
+ import java .io .File ;
15
+ import java .io .FileWriter ;
16
+ import java .io .IOException ;
12
17
13
18
/** A Maven Mojo that diffs two OpenAPI specifications and reports on differences. */
14
19
@ Mojo (name = "diff" , defaultPhase = LifecyclePhase .TEST )
@@ -25,6 +30,12 @@ public class OpenApiDiffMojo extends AbstractMojo {
25
30
@ Parameter (property = "failOnChanged" , defaultValue = "false" )
26
31
Boolean failOnChanged = false ;
27
32
33
+ @ Parameter (property = "outputType" )
34
+ String outputType ;
35
+
36
+ @ Parameter (property = "outputFile" )
37
+ String outputFile ;
38
+
28
39
@ Parameter (property = "skip" , defaultValue = "false" )
29
40
Boolean skip = false ;
30
41
@@ -37,7 +48,24 @@ public void execute() throws MojoExecutionException, MojoFailureException {
37
48
38
49
try {
39
50
final ChangedOpenApi diff = OpenApiCompare .fromLocations (oldSpec , newSpec );
40
- getLog ().info (new ConsoleRender ().render (diff ));
51
+
52
+ if (outputType == null || outputType .equals ("" )) {
53
+ getLog ().info (new ConsoleRender ().render (diff ));
54
+ }
55
+
56
+ if (outputType .equalsIgnoreCase ("html" ) || outputType .equalsIgnoreCase ("html-detailed" )) {
57
+ boolean detailed = outputType .equalsIgnoreCase ("html-detailed" );
58
+ File htmlFile = new File (outputFile );
59
+ String htmlRender = new HtmlRender (detailed ).render (diff );
60
+ try {
61
+ FileWriter fileWriter = new FileWriter (htmlFile );
62
+ fileWriter .write (htmlRender );
63
+ fileWriter .close ();
64
+
65
+ } catch (IOException e ) {
66
+ throw new RuntimeException (e .getMessage ());
67
+ }
68
+ }
41
69
42
70
if (failOnIncompatible && diff .isIncompatible ()) {
43
71
throw new BackwardIncompatibilityException ("The API changes broke backward compatibility" );
0 commit comments