@@ -19,6 +19,7 @@ import {
19
19
formatModifiedValuesReport ,
20
20
} from "./summary.js" ;
21
21
import { compareDocuments , printPathDiff } from "./compare.js" ;
22
+ import { writeFile } from "fs/promises" ;
22
23
23
24
function parseArguments ( ) {
24
25
return yargs ( hideBin ( process . argv ) )
@@ -50,6 +51,14 @@ function parseArguments() {
50
51
"Compare two swagger specs" ,
51
52
)
52
53
. example ( "$0 oldSpecPath newSpecPath" , "Compare using positional arguments" )
54
+ . example (
55
+ "$0 --oldPath ./old-spec --newPath ./new-spec --reportFile ./custom-report.md" ,
56
+ "Compare specs with custom report file" ,
57
+ )
58
+ . example (
59
+ "$0 --oldPath ./old-spec --newPath ./new-spec --outputFolder ./validation-results" ,
60
+ "Compare specs with custom output folder" ,
61
+ )
53
62
. example (
54
63
"$0 add-ignore --path \"paths['/api/resource'].put.parameters[0].required__added\" --outputFolder ./results" ,
55
64
"Add a path to ignore file" ,
@@ -68,6 +77,11 @@ function parseArguments() {
68
77
alias : "out" ,
69
78
describe : "Output folder for analysis results" ,
70
79
type : "string" ,
80
+ } )
81
+ . option ( "reportFile" , {
82
+ alias : "r" ,
83
+ describe : "Path to the report file" ,
84
+ type : "string" ,
71
85
} )
72
86
. option ( "ignoreDescription" , {
73
87
description : "Ignore description differences" ,
@@ -95,9 +109,6 @@ function parseArguments() {
95
109
if ( ! argv . newPath && positional . length > 1 ) {
96
110
argv . newPath = positional [ 1 ] ! . toString ( ) ;
97
111
}
98
- if ( ! argv . outputFolder && positional . length > 2 ) {
99
- argv . outputFolder = positional [ 2 ] ! . toString ( ) ;
100
- }
101
112
102
113
if ( ! argv . oldPath || ! argv . newPath ) {
103
114
throw new Error ( "Both oldPath and newPath are required" ) ;
@@ -155,7 +166,7 @@ export async function main() {
155
166
156
167
// If using add-ignore command, the command handler will exit the process
157
168
158
- const { oldPath, newPath, outputFolder, ignoreDescription, ignorePathCase } = args ;
169
+ const { oldPath, newPath, reportFile , outputFolder, ignoreDescription, ignorePathCase } = args ;
159
170
configuration . ignoreDescription = ignoreDescription ;
160
171
if ( ignorePathCase !== undefined ) {
161
172
configuration . ignorePathCase = ignorePathCase ;
@@ -261,7 +272,10 @@ export async function main() {
261
272
) ;
262
273
}
263
274
}
264
- else {
275
+ else if ( reportFile ) {
276
+ if ( compareResult . length > 0 ) {
277
+ await writeFile ( reportFile , outputMarkdown ) ;
278
+ }
265
279
if ( compareResult . filter ( ( x ) => x . level === "error" ) . length > 0 ) {
266
280
logError ( "Differences found. Please fix the issues before proceeding." ) ;
267
281
process . exit ( 1 ) ;
0 commit comments