|
1 | | -using System.Security.Cryptography; |
2 | 1 | using System.Diagnostics; |
| 2 | +using System.Security.Cryptography; |
3 | 3 | using System.Text; |
4 | 4 | using System.Text.Json; |
5 | 5 | using System.Text.Json.Nodes; |
6 | | -using System.Linq; |
7 | 6 | using NJsonSchema.CodeGeneration.CSharp; |
8 | 7 | using NSwag; |
9 | | -using NSwag.CodeGeneration; |
10 | 8 | using NSwag.CodeGeneration.CSharp; |
11 | 9 | using NSwag.CodeGeneration.OperationNameGenerators; |
12 | 10 |
|
@@ -35,9 +33,9 @@ public static async Task RunAsync(GeneratorOptions options, CancellationToken ca |
35 | 33 | string generatedDirectory = Path.Combine(projectDirectory, "Generated"); |
36 | 34 | string intermediateDirectory = Path.Combine(projectDirectory, "obj"); |
37 | 35 |
|
38 | | - Directory.CreateDirectory(openApiDirectory); |
39 | | - Directory.CreateDirectory(generatedDirectory); |
40 | | - Directory.CreateDirectory(intermediateDirectory); |
| 36 | + _ = Directory.CreateDirectory(openApiDirectory); |
| 37 | + _ = Directory.CreateDirectory(generatedDirectory); |
| 38 | + _ = Directory.CreateDirectory(intermediateDirectory); |
41 | 39 |
|
42 | 40 | string lockFilePath = Path.Combine(intermediateDirectory, LockFileName); |
43 | 41 | using FileStream generatorLock = await AcquireGeneratorLockAsync(lockFilePath, TimeSpan.FromMinutes(2), cancellationToken) |
@@ -122,7 +120,7 @@ await File.WriteAllTextAsync( |
122 | 120 |
|
123 | 121 | private static async Task<FileStream> AcquireGeneratorLockAsync(string lockFilePath, TimeSpan timeout, CancellationToken cancellationToken) |
124 | 122 | { |
125 | | - Stopwatch stopwatch = Stopwatch.StartNew(); |
| 123 | + var stopwatch = Stopwatch.StartNew(); |
126 | 124 |
|
127 | 125 | while (true) |
128 | 126 | { |
@@ -258,19 +256,19 @@ private static void NormalizeParameters(JsonObject operation) |
258 | 256 | if (typeNode is not null) |
259 | 257 | { |
260 | 258 | schema["type"] = typeNode.DeepClone(); |
261 | | - parameter.Remove("type"); |
| 259 | + _ = parameter.Remove("type"); |
262 | 260 | } |
263 | 261 |
|
264 | 262 | if (parameter.TryGetPropertyValue("enum", out JsonNode? enumNode) && enumNode is not null) |
265 | 263 | { |
266 | 264 | schema["enum"] = enumNode.DeepClone(); |
267 | | - parameter.Remove("enum"); |
| 265 | + _ = parameter.Remove("enum"); |
268 | 266 | } |
269 | 267 |
|
270 | 268 | if (parameter.TryGetPropertyValue("items", out JsonNode? itemsNode) && itemsNode is not null) |
271 | 269 | { |
272 | 270 | schema["items"] = itemsNode.DeepClone(); |
273 | | - parameter.Remove("items"); |
| 271 | + _ = parameter.Remove("items"); |
274 | 272 | } |
275 | 273 |
|
276 | 274 | parameter["schema"] = schema; |
@@ -347,44 +345,41 @@ private static JsonObject CreateResponseSchema(string path) |
347 | 345 | _ => null, |
348 | 346 | }; |
349 | 347 |
|
350 | | - if (feedProperty is null) |
351 | | - { |
352 | | - return new JsonObject |
| 348 | + return feedProperty is null |
| 349 | + ? new JsonObject |
353 | 350 | { |
354 | 351 | ["type"] = "object", |
355 | 352 | ["additionalProperties"] = true, |
356 | | - }; |
357 | | - } |
358 | | - |
359 | | - return new JsonObject |
360 | | - { |
361 | | - ["type"] = "object", |
362 | | - ["properties"] = new JsonObject |
| 353 | + } |
| 354 | + : new JsonObject |
363 | 355 | { |
364 | | - [feedProperty] = new JsonObject |
| 356 | + ["type"] = "object", |
| 357 | + ["properties"] = new JsonObject |
365 | 358 | { |
366 | | - ["type"] = "array", |
367 | | - ["items"] = new JsonObject |
| 359 | + [feedProperty] = new JsonObject |
368 | 360 | { |
369 | | - ["type"] = "object", |
370 | | - ["additionalProperties"] = true, |
| 361 | + ["type"] = "array", |
| 362 | + ["items"] = new JsonObject |
| 363 | + { |
| 364 | + ["type"] = "object", |
| 365 | + ["additionalProperties"] = true, |
| 366 | + }, |
| 367 | + }, |
| 368 | + ["limit"] = new JsonObject |
| 369 | + { |
| 370 | + ["type"] = "integer", |
| 371 | + }, |
| 372 | + ["offset"] = new JsonObject |
| 373 | + { |
| 374 | + ["type"] = "integer", |
| 375 | + }, |
| 376 | + ["count"] = new JsonObject |
| 377 | + { |
| 378 | + ["type"] = "integer", |
371 | 379 | }, |
372 | 380 | }, |
373 | | - ["limit"] = new JsonObject |
374 | | - { |
375 | | - ["type"] = "integer", |
376 | | - }, |
377 | | - ["offset"] = new JsonObject |
378 | | - { |
379 | | - ["type"] = "integer", |
380 | | - }, |
381 | | - ["count"] = new JsonObject |
382 | | - { |
383 | | - ["type"] = "integer", |
384 | | - }, |
385 | | - }, |
386 | | - ["additionalProperties"] = true, |
387 | | - }; |
| 381 | + ["additionalProperties"] = true, |
| 382 | + }; |
388 | 383 | } |
389 | 384 |
|
390 | 385 | private static async Task<string> GenerateClientAsync( |
@@ -424,14 +419,14 @@ private static async Task<string> GenerateClientAsync( |
424 | 419 | private static string AddAutoGeneratedHeader(string generatedCode, string source) |
425 | 420 | { |
426 | 421 | StringBuilder builder = new(); |
427 | | - builder.AppendLine("// <auto-generated>"); |
428 | | - builder.AppendLine("// This file was generated by GoAffPro.Client.Generator."); |
429 | | - builder.Append("// Source: ").AppendLine(source); |
430 | | - builder.Append("// Generated: ").AppendLine(DateTimeOffset.UtcNow.ToString("O")); |
431 | | - builder.AppendLine("// Do not edit manually."); |
432 | | - builder.AppendLine("// </auto-generated>"); |
433 | | - builder.AppendLine(); |
434 | | - builder.Append(generatedCode); |
| 422 | + _ = builder.AppendLine("// <auto-generated>"); |
| 423 | + _ = builder.AppendLine("// This file was generated by GoAffPro.Client.Generator."); |
| 424 | + _ = builder.Append("// Source: ").AppendLine(source); |
| 425 | + _ = builder.Append("// Generated: ").AppendLine(DateTimeOffset.UtcNow.ToString("O")); |
| 426 | + _ = builder.AppendLine("// Do not edit manually."); |
| 427 | + _ = builder.AppendLine("// </auto-generated>"); |
| 428 | + _ = builder.AppendLine(); |
| 429 | + _ = builder.Append(generatedCode); |
435 | 430 | return builder.ToString(); |
436 | 431 | } |
437 | 432 |
|
|
0 commit comments