@@ -62,6 +62,35 @@ func NewAPISpecValidator(serverURL string, logger *zap.SugaredLogger) *APISpecVa
62
62
}
63
63
}
64
64
65
+ func (v * APISpecValidator ) buildCurlCommand (req * http.Request ) string {
66
+ var cmd strings.Builder
67
+
68
+ cmd .WriteString ("curl --location '" )
69
+ cmd .WriteString (req .URL .String ())
70
+ cmd .WriteString ("' \\ \n " )
71
+
72
+ // Add headers
73
+ for key , values := range req .Header {
74
+ for _ , value := range values {
75
+ cmd .WriteString (fmt .Sprintf (" --header '%s: %s' \\ \n " , key , value ))
76
+ }
77
+ }
78
+
79
+ // Add cookies
80
+ if len (v .additionalCookies ) > 0 {
81
+ cmd .WriteString (" --cookie '" )
82
+ for name , value := range v .additionalCookies {
83
+ cmd .WriteString (name )
84
+ cmd .WriteString ("=" )
85
+ cmd .WriteString (value )
86
+ cmd .WriteString ("; " )
87
+ }
88
+ cmd .WriteString ("' \\ \n " )
89
+ }
90
+
91
+ return cmd .String ()
92
+ }
93
+
65
94
// LoadSpecs loads all OpenAPI specs from the specs directory
66
95
func (v * APISpecValidator ) LoadSpecs (specsDir string ) error {
67
96
v .logger .Infow ("Loading API specs from directory" , "dir" , specsDir )
@@ -215,14 +244,6 @@ func (v *APISpecValidator) testEndpoint(result *ValidationResult, path, method s
215
244
req .Header .Set ("Content-Type" , "application/json" )
216
245
req .Header .Set ("Accept" , "*/*" )
217
246
req .Header .Set ("Accept-Language" , "en-US,en;q=0.9,hi;q=0.8" )
218
- req .Header .Set ("User-Agent" , "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36" )
219
- req .Header .Set ("Sec-Ch-Ua" , `"Not)A;Brand";v="8", "Chromium";v="138", "Google Chrome";v="138"` )
220
- req .Header .Set ("Sec-Ch-Ua-Mobile" , "?0" )
221
- req .Header .Set ("Sec-Ch-Ua-Platform" , `"macOS"` )
222
- req .Header .Set ("Sec-Fetch-Dest" , "empty" )
223
- req .Header .Set ("Sec-Fetch-Mode" , "cors" )
224
- req .Header .Set ("Sec-Fetch-Site" , "same-origin" )
225
- req .Header .Set ("Priority" , "u=1, i" )
226
247
227
248
// Set authentication - cookie-based only as per curl request pattern
228
249
v .setAuthentication (req )
@@ -237,6 +258,9 @@ func (v *APISpecValidator) testEndpoint(result *ValidationResult, path, method s
237
258
}
238
259
}
239
260
261
+ // print the curl command for debugging
262
+ v .logger .Debugw ("Curl command" , "command" , v .buildCurlCommand (req ))
263
+
240
264
// Make the request
241
265
resp , err := v .httpClient .Do (req )
242
266
if err != nil {
0 commit comments