1
1
package org .openapitools .openapidiff .maven ;
2
2
3
+ import java .io .File ;
4
+ import java .io .FileWriter ;
5
+ import java .io .IOException ;
3
6
import org .apache .maven .plugin .AbstractMojo ;
4
7
import org .apache .maven .plugin .MojoExecutionException ;
5
8
import org .apache .maven .plugin .MojoFailureException ;
9
12
import org .openapitools .openapidiff .core .OpenApiCompare ;
10
13
import org .openapitools .openapidiff .core .model .ChangedOpenApi ;
11
14
import org .openapitools .openapidiff .core .output .ConsoleRender ;
15
+ import org .openapitools .openapidiff .core .output .HtmlRender ;
12
16
13
17
/** A Maven Mojo that diffs two OpenAPI specifications and reports on differences. */
14
18
@ Mojo (name = "diff" , defaultPhase = LifecyclePhase .TEST )
@@ -25,6 +29,12 @@ public class OpenApiDiffMojo extends AbstractMojo {
25
29
@ Parameter (property = "failOnChanged" , defaultValue = "false" )
26
30
Boolean failOnChanged = false ;
27
31
32
+ @ Parameter (property = "outputType" )
33
+ String outputType = "" ;
34
+
35
+ @ Parameter (property = "outputFile" )
36
+ String outputFile = "" ;
37
+
28
38
@ Parameter (property = "skip" , defaultValue = "false" )
29
39
Boolean skip = false ;
30
40
@@ -37,7 +47,24 @@ public void execute() throws MojoExecutionException, MojoFailureException {
37
47
38
48
try {
39
49
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
+ }
41
68
42
69
if (failOnIncompatible && diff .isIncompatible ()) {
43
70
throw new BackwardIncompatibilityException ("The API changes broke backward compatibility" );
0 commit comments