|
72 | 72 | { |
73 | 73 | // Try to parse as JSON |
74 | 74 | var doc = JsonDocument.Parse(spec); |
75 | | - var endpoints = new List<object>(); |
| 75 | + var endpoints = new List<(string Path, string Method, string Summary, string OperationId)>(); |
76 | 76 |
|
77 | 77 | if (doc.RootElement.TryGetProperty("paths", out var paths)) |
78 | 78 | { |
79 | 79 | foreach (var path in paths.EnumerateObject()) |
80 | 80 | { |
81 | 81 | foreach (var method in path.Value.EnumerateObject()) |
82 | 82 | { |
83 | | - var endpoint = new |
84 | | - { |
85 | | - path = path.Name, |
86 | | - method = method.Name.ToUpper(), |
87 | | - summary = method.Value.TryGetProperty("summary", out var s) ? s.GetString() : "", |
88 | | - operationId = method.Value.TryGetProperty("operationId", out var o) ? o.GetString() : "" |
89 | | - }; |
90 | | - endpoints.Add(endpoint); |
| 83 | + endpoints.Add( |
| 84 | + ( |
| 85 | + path.Name, |
| 86 | + method.Name.ToUpperInvariant(), |
| 87 | + method.Value.TryGetProperty("summary", out var s) ? (s.GetString() ?? "") : "", |
| 88 | + method.Value.TryGetProperty("operationId", out var o) ? (o.GetString() ?? "") : "" |
| 89 | + ) |
| 90 | + ); |
91 | 91 | if (endpoints.Count > 50) break; // Limit |
92 | 92 | } |
93 | 93 | if (endpoints.Count > 50) break; |
94 | 94 | } |
95 | 95 | } |
96 | | - |
97 | | - return new ParseEndpointsResult(true, $"Found {endpoints.Count} endpoints", endpoints, endpoints.Count); |
| 96 | + |
| 97 | + var sb = new System.Text.StringBuilder(); |
| 98 | + sb.AppendLine($"success: true"); |
| 99 | + sb.AppendLine($"count: {endpoints.Count}"); |
| 100 | + sb.AppendLine("endpoints:"); |
| 101 | + foreach (var ep in endpoints) |
| 102 | + { |
| 103 | + var summary = string.IsNullOrWhiteSpace(ep.Summary) ? "" : $" — {ep.Summary}"; |
| 104 | + var opId = string.IsNullOrWhiteSpace(ep.OperationId) ? "" : $" (operationId: {ep.OperationId})"; |
| 105 | + sb.AppendLine($"- {ep.Method} {ep.Path}{summary}{opId}"); |
| 106 | + } |
| 107 | + return sb.ToString(); |
98 | 108 | } |
99 | 109 | catch (Exception ex) |
100 | 110 | { |
101 | | - return new ParseEndpointsResult(false, ex.Message, new List<object>(), 0); |
| 111 | + return $"success: false\nmessage: {ex.Message}\n"; |
102 | 112 | } |
103 | 113 | }, |
104 | 114 | "parse_endpoints", |
|
121 | 131 | if (spec.Contains("basic", StringComparison.OrdinalIgnoreCase)) |
122 | 132 | authTypes.Add("Basic Auth"); |
123 | 133 | } |
124 | | - |
125 | | - return new AuthAnalysisResult(authTypes); |
| 134 | + |
| 135 | + if (authTypes.Count == 0) |
| 136 | + return "authenticationTypes: (none detected)\n"; |
| 137 | + |
| 138 | + return "authenticationTypes:\n" + string.Join("\n", authTypes.Select(a => $"- {a}")) + "\n"; |
126 | 139 | }, |
127 | 140 | "analyze_auth", |
128 | 141 | "Analyze authentication requirements" |
|
147 | 160 | testCases.Add($"Test {method} {path} - Missing Required Fields"); |
148 | 161 | testCases.Add($"Test {method} {path} - Invalid Data Types"); |
149 | 162 | } |
150 | | - |
151 | | - return new TestCaseResult($"{method} {path}", testCases); |
| 163 | + |
| 164 | + var sb = new System.Text.StringBuilder(); |
| 165 | + sb.AppendLine($"endpoint: {method} {path}"); |
| 166 | + sb.AppendLine("testCases:"); |
| 167 | + foreach (var tc in testCases) |
| 168 | + sb.AppendLine($"- {tc}"); |
| 169 | + return sb.ToString(); |
152 | 170 | }, |
153 | 171 | "generate_test_cases", |
154 | 172 | "Generate test case scenarios for an endpoint" |
@@ -252,7 +270,3 @@ 2. Analyze authentication requirements |
252 | 270 | Console.WriteLine($"💡 Tip: Review and customize the generated tests before use"); |
253 | 271 |
|
254 | 272 | return 0; |
255 | | - |
256 | | -record ParseEndpointsResult(bool success, string message, List<object> endpoints, int count); |
257 | | -record AuthAnalysisResult(List<string> authenticationTypes); |
258 | | -record TestCaseResult(string endpoint, List<string> testCases); |
|
0 commit comments