Skip to content

Commit f303f0c

Browse files
format
1 parent 7d75541 commit f303f0c

File tree

11 files changed

+119
-76
lines changed

11 files changed

+119
-76
lines changed

RestClient.Net.McpGenerator/McpServerGenerator.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ string extensionsNamespace
3131

3232
if (readResult.Document == null)
3333
{
34-
return new Result<string, string>.Error<string, string>("Error parsing OpenAPI: Document is null");
34+
return new Result<string, string>.Error<string, string>(
35+
"Error parsing OpenAPI: Document is null"
36+
);
3537
}
3638

3739
var document = readResult.Document;

RestClient.Net.McpGenerator/McpToolGenerator.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ Dictionary<string, int> methodNameCounts
105105
);
106106
var parameters = GetParameters(operation, schemas);
107107
// Match ExtensionMethodGenerator behavior: POST/PUT/PATCH always have body
108-
var hasBody = operationType == HttpMethod.Post
108+
var hasBody =
109+
operationType == HttpMethod.Post
109110
|| operationType == HttpMethod.Put
110111
|| operationType == HttpMethod.Patch;
111112
var bodyType = GetRequestBodyType(operation) ?? "object";
@@ -116,9 +117,8 @@ Dictionary<string, int> methodNameCounts
116117

117118
// Build the full response type name for alias lookup
118119
// When error type is not "string", append it to response type (e.g., "KnowledgeBoxObjHTTPValidationError")
119-
var fullResponseType = errorType != "string"
120-
? $"{resultResponseType}{errorType}"
121-
: resultResponseType;
120+
var fullResponseType =
121+
errorType != "string" ? $"{resultResponseType}{errorType}" : resultResponseType;
122122

123123
var summary = operation.Description ?? operation.Summary ?? $"{mcpToolName} operation";
124124

@@ -150,7 +150,9 @@ string errorType
150150

151151
// Separate required and optional parameters
152152
// A parameter is optional if it has a default value OR is nullable, regardless of Required flag
153-
var optionalParams = parameters.Where(p => p.DefaultValue != null || p.Type.Contains('?', StringComparison.Ordinal)).ToList();
153+
var optionalParams = parameters
154+
.Where(p => p.DefaultValue != null || p.Type.Contains('?', StringComparison.Ordinal))
155+
.ToList();
154156
var requiredParams = parameters.Except(optionalParams).ToList();
155157

156158
// Add required parameters first
@@ -371,7 +373,7 @@ private static string GetResponseType(OpenApiOperation operation)
371373
JsonSchemaType.Number => schema.Format == "float" ? "float" : "double",
372374
JsonSchemaType.Boolean => "bool",
373375
JsonSchemaType.Array => "object", // Arrays are complex
374-
_ => "object"
376+
_ => "object",
375377
};
376378
}
377379

RestClient.Net.OpenApiGenerator/ExtensionMethodGenerator.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,10 @@ private static List<ParameterInfo> GetParameters(
816816
: "object";
817817
}
818818

819-
private static string GenerateTypeAliasesFile(HashSet<(string SuccessType, string ErrorType)> resultTypes, string @namespace)
819+
private static string GenerateTypeAliasesFile(
820+
HashSet<(string SuccessType, string ErrorType)> resultTypes,
821+
string @namespace
822+
)
820823
{
821824
if (resultTypes.Count == 0)
822825
{
@@ -843,7 +846,11 @@ string @namespace
843846
return aliases;
844847
}
845848

846-
foreach (var (successType, errorType) in resultTypes.OrderBy(t => t.SuccessType).ThenBy(t => t.ErrorType))
849+
foreach (
850+
var (successType, errorType) in resultTypes
851+
.OrderBy(t => t.SuccessType)
852+
.ThenBy(t => t.ErrorType)
853+
)
847854
{
848855
var typeName = successType
849856
.Replace("List<", string.Empty, StringComparison.Ordinal)
@@ -854,10 +861,13 @@ string @namespace
854861
: string.Empty;
855862

856863
// Include error type in alias name if not string (to avoid conflicts)
857-
var errorTypeName = errorType == "string" ? "" : errorType
858-
.Replace("List<", string.Empty, StringComparison.Ordinal)
859-
.Replace(">", string.Empty, StringComparison.Ordinal)
860-
.Replace(".", string.Empty, StringComparison.Ordinal);
864+
var errorTypeName =
865+
errorType == "string"
866+
? ""
867+
: errorType
868+
.Replace("List<", string.Empty, StringComparison.Ordinal)
869+
.Replace(">", string.Empty, StringComparison.Ordinal)
870+
.Replace(".", string.Empty, StringComparison.Ordinal);
861871
var aliasName = $"{typeName}{pluralSuffix}{errorTypeName}";
862872

863873
// Qualify type names with namespace (except for System types and Outcome.Unit)

RestClient.Net.OpenApiGenerator/ModelGenerator.cs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ namespace {{@namespace}};
4343
/// <param name="schema">The schema to check.</param>
4444
/// <returns>True if the schema is a string enum.</returns>
4545
private static bool IsStringEnum(OpenApiSchema schema) =>
46-
schema.Type == JsonSchemaType.String &&
47-
schema.Enum != null &&
48-
schema.Enum.Count > 0;
46+
schema.Type == JsonSchemaType.String && schema.Enum != null && schema.Enum.Count > 0;
4947

5048
/// <summary>Generates a single C# model record from an OpenAPI schema.</summary>
5149
/// <param name="name">The name of the model.</param>
@@ -73,7 +71,10 @@ private static string GenerateModel(
7371
var propDesc = SanitizeDescription(
7472
(p.Value as OpenApiSchema)?.Description ?? propName
7573
);
76-
return (ParamDoc: $"/// <param name=\"{propName}\">{propDesc}</param>", ParamDecl: $"{propType} {propName}");
74+
return (
75+
ParamDoc: $"/// <param name=\"{propName}\">{propDesc}</param>",
76+
ParamDecl: $"{propType} {propName}"
77+
);
7778
})
7879
.ToList();
7980

@@ -116,13 +117,12 @@ public static string MapOpenApiType(
116117
if (schema is OpenApiSchemaReference schemaRef)
117118
{
118119
// Return "string" if this is a reference to a string enum, otherwise return the class name
119-
return schemaRef.Reference.Id == null
120-
? "object"
121-
: schemas != null &&
122-
schemas.TryGetValue(schemaRef.Reference.Id, out var referencedSchema) &&
123-
referencedSchema is OpenApiSchema refSchemaObj &&
124-
IsStringEnum(refSchemaObj)
125-
? "string"
120+
return schemaRef.Reference.Id == null ? "object"
121+
: schemas != null
122+
&& schemas.TryGetValue(schemaRef.Reference.Id, out var referencedSchema)
123+
&& referencedSchema is OpenApiSchema refSchemaObj
124+
&& IsStringEnum(refSchemaObj)
125+
? "string"
126126
: CodeGenerationHelpers.ToPascalCase(schemaRef.Reference.Id);
127127
}
128128

@@ -137,21 +137,21 @@ referencedSchema is OpenApiSchema refSchemaObj &&
137137
return schemaObj.Items is OpenApiSchemaReference itemsRef
138138
? itemsRef.Reference.Id == null
139139
? "List<object>"
140-
: schemas != null &&
141-
schemas.TryGetValue(itemsRef.Reference.Id, out var itemsSchema) &&
142-
itemsSchema is OpenApiSchema itemsSchemaObj &&
143-
IsStringEnum(itemsSchemaObj)
144-
? "List<string>"
145-
: $"List<{CodeGenerationHelpers.ToPascalCase(itemsRef.Reference.Id)}>"
140+
: schemas != null
141+
&& schemas.TryGetValue(itemsRef.Reference.Id, out var itemsSchema)
142+
&& itemsSchema is OpenApiSchema itemsSchemaObj
143+
&& IsStringEnum(itemsSchemaObj)
144+
? "List<string>"
145+
: $"List<{CodeGenerationHelpers.ToPascalCase(itemsRef.Reference.Id)}>"
146146
: schemaObj.Items is OpenApiSchema items
147-
? items.Type switch
148-
{
149-
JsonSchemaType.String => "List<string>",
150-
JsonSchemaType.Integer => "List<int>",
151-
JsonSchemaType.Number => "List<double>",
152-
_ => "List<object>",
153-
}
154-
: "List<object>";
147+
? items.Type switch
148+
{
149+
JsonSchemaType.String => "List<string>",
150+
JsonSchemaType.Integer => "List<int>",
151+
JsonSchemaType.Number => "List<double>",
152+
_ => "List<object>",
153+
}
154+
: "List<object>";
155155
}
156156

157157
// Handle primitive types

RestClient.Net/Utilities/ProgressReportingHttpContent.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ public ProgressReportingHttpContent(
3535
progress: progress,
3636
bufferSize: bufferSize,
3737
contentType: contentType
38-
)
39-
{ }
38+
) { }
4039

4140
/// <summary>
4241
/// Initializes a new instance of the <see cref="ProgressReportingHttpContent"/> class using a byte array as content.
@@ -56,8 +55,7 @@ public ProgressReportingHttpContent(
5655
progress: progress,
5756
bufferSize: bufferSize,
5857
contentType: contentType
59-
)
60-
{ }
58+
) { }
6159

6260
/// <summary>
6361
/// Initializes a new instance of the <see cref="ProgressReportingHttpContent"/> class using a stream as content.

Samples/NucliaDbClient.Demo/Program.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44

55
// Setup HTTP client factory
66
var services = new ServiceCollection();
7-
services.AddHttpClient("default", client =>
8-
{
9-
client.BaseAddress = new Uri("http://localhost:8080/api/v1");
10-
client.Timeout = TimeSpan.FromSeconds(30);
11-
});
7+
services.AddHttpClient(
8+
"default",
9+
client =>
10+
{
11+
client.BaseAddress = new Uri("http://localhost:8080/api/v1");
12+
client.Timeout = TimeSpan.FromSeconds(30);
13+
}
14+
);
1215

1316
var serviceProvider = services.BuildServiceProvider();
1417
var httpClientFactory = serviceProvider.GetRequiredService<IHttpClientFactory>();
@@ -30,14 +33,11 @@
3033

3134
var kbId = createResult switch
3235
{
33-
OkKnowledgeBoxObj ok =>
34-
$"Created successfully! UUID: {ok.Value.Uuid}",
36+
OkKnowledgeBoxObj ok => $"Created successfully! UUID: {ok.Value.Uuid}",
3537
ErrorKnowledgeBoxObj error => error.Value switch
3638
{
37-
HttpError<string>.ErrorResponseError err =>
38-
$"Error {err.StatusCode}: {err.Body}",
39-
HttpError<string>.ExceptionError err =>
40-
$"Exception: {err.Exception.Message}",
39+
HttpError<string>.ErrorResponseError err => $"Error {err.StatusCode}: {err.Body}",
40+
HttpError<string>.ExceptionError err => $"Exception: {err.Exception.Message}",
4141
_ => "Unknown error",
4242
},
4343
};
@@ -56,8 +56,7 @@
5656
{
5757
HttpError<HTTPValidationError>.ErrorResponseError err =>
5858
$"Error {err.StatusCode}: {err.Body}",
59-
HttpError<HTTPValidationError>.ExceptionError err =>
60-
$"Exception: {err.Exception.Message}",
59+
HttpError<HTTPValidationError>.ExceptionError err => $"Exception: {err.Exception.Message}",
6160
_ => "Unknown error",
6261
},
6362
};

Samples/NucliaDbClient.McpServer/Program.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@
99
var services = new ServiceCollection();
1010

1111
// Configure HttpClient with base URL
12-
services.AddHttpClient("default", client =>
13-
{
14-
client.BaseAddress = new Uri(nucleaBaseUrl);
15-
client.Timeout = TimeSpan.FromSeconds(30);
16-
});
12+
services.AddHttpClient(
13+
"default",
14+
client =>
15+
{
16+
client.BaseAddress = new Uri(nucleaBaseUrl);
17+
client.Timeout = TimeSpan.FromSeconds(30);
18+
}
19+
);
1720

1821
// Add the NucliaDB tools to DI
1922
services.AddSingleton<NucliaDbTools>();

Samples/NucliaDbClient.Tests/NucliaDbApiTests.cs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,10 @@ public async Task GetResource_ReturnsResource()
255255
var resource = result switch
256256
{
257257
OkNucliadbModelsResourceResourceHTTPValidationError(var value) => value,
258-
ErrorNucliadbModelsResourceResourceHTTPValidationError(HttpError<HTTPValidationError>.ExceptionError(var ex)) =>
259-
throw new InvalidOperationException("API call failed with exception", ex),
258+
ErrorNucliadbModelsResourceResourceHTTPValidationError(
259+
HttpError<HTTPValidationError>.ExceptionError
260+
(var ex)
261+
) => throw new InvalidOperationException("API call failed with exception", ex),
260262
ErrorNucliadbModelsResourceResourceHTTPValidationError(
261263
HttpError<HTTPValidationError>.ErrorResponseError
262264
(var body, var statusCode, _)
@@ -308,8 +310,10 @@ public async Task ModifyResource_ReturnsResourceUpdated()
308310
var updated = result switch
309311
{
310312
OkResourceUpdatedHTTPValidationError(var value) => value,
311-
ErrorResourceUpdatedHTTPValidationError(HttpError<HTTPValidationError>.ExceptionError(var ex)) =>
312-
throw new InvalidOperationException("API call failed with exception", ex),
313+
ErrorResourceUpdatedHTTPValidationError(
314+
HttpError<HTTPValidationError>.ExceptionError
315+
(var ex)
316+
) => throw new InvalidOperationException("API call failed with exception", ex),
313317
ErrorResourceUpdatedHTTPValidationError(
314318
HttpError<HTTPValidationError>.ErrorResponseError
315319
(var body, var statusCode, _)
@@ -336,8 +340,10 @@ public async Task GetKnowledgeBoxCounters_ReturnsCounters()
336340
var counters = result switch
337341
{
338342
OkKnowledgeboxCountersHTTPValidationError(var value) => value,
339-
ErrorKnowledgeboxCountersHTTPValidationError(HttpError<HTTPValidationError>.ExceptionError(var ex)) =>
340-
throw new InvalidOperationException("API call failed with exception", ex),
343+
ErrorKnowledgeboxCountersHTTPValidationError(
344+
HttpError<HTTPValidationError>.ExceptionError
345+
(var ex)
346+
) => throw new InvalidOperationException("API call failed with exception", ex),
341347
ErrorKnowledgeboxCountersHTTPValidationError(
342348
HttpError<HTTPValidationError>.ErrorResponseError
343349
(var body, var statusCode, _)
@@ -375,8 +381,10 @@ public async Task AddTextFieldToResource_ReturnsResourceFieldAdded()
375381
var fieldAdded = result switch
376382
{
377383
OkResourceFieldAddedHTTPValidationError(var value) => value,
378-
ErrorResourceFieldAddedHTTPValidationError(HttpError<HTTPValidationError>.ExceptionError(var ex)) =>
379-
throw new InvalidOperationException("API call failed with exception", ex),
384+
ErrorResourceFieldAddedHTTPValidationError(
385+
HttpError<HTTPValidationError>.ExceptionError
386+
(var ex)
387+
) => throw new InvalidOperationException("API call failed with exception", ex),
380388
ErrorResourceFieldAddedHTTPValidationError(
381389
HttpError<HTTPValidationError>.ErrorResponseError
382390
(var body, var statusCode, _)
@@ -408,8 +416,10 @@ public async Task DeleteResource_ReturnsUnit()
408416
OkUnitHTTPValidationError(var value) => value,
409417
ErrorUnitHTTPValidationError(HttpError<HTTPValidationError>.ExceptionError(var ex)) =>
410418
throw new InvalidOperationException("API call failed with exception", ex),
411-
ErrorUnitHTTPValidationError(HttpError<HTTPValidationError>.ErrorResponseError(var body, var statusCode, _)) =>
412-
throw new InvalidOperationException($"API call failed: HTTP {statusCode}: {body}"),
419+
ErrorUnitHTTPValidationError(
420+
HttpError<HTTPValidationError>.ErrorResponseError
421+
(var body, var statusCode, _)
422+
) => throw new InvalidOperationException($"API call failed: HTTP {statusCode}: {body}"),
413423
};
414424

415425
Assert.Equal(Unit.Value, unit);

Samples/NucliaDbClient.Tests/NucliaDbFixture.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,11 @@ private static void RunDockerCommand(string arguments)
6767
UseShellExecute = false,
6868
};
6969

70-
using var process = Process.Start(startInfo)
71-
?? throw new InvalidOperationException($"Failed to start docker process with arguments: {arguments}");
70+
using var process =
71+
Process.Start(startInfo)
72+
?? throw new InvalidOperationException(
73+
$"Failed to start docker process with arguments: {arguments}"
74+
);
7275

7376
var output = process.StandardOutput.ReadToEnd();
7477
var error = process.StandardError.ReadToEnd();
@@ -114,7 +117,9 @@ private static void WaitForNucliaDbReady()
114117
return;
115118
}
116119

117-
Console.WriteLine($"Attempt {i + 1}/{maxAttempts}: Status code {response.StatusCode}");
120+
Console.WriteLine(
121+
$"Attempt {i + 1}/{maxAttempts}: Status code {response.StatusCode}"
122+
);
118123
}
119124
catch (Exception ex)
120125
{

Samples/RestClient.AvaloniaUI.Sample.Tests/ViewModelTests.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,12 @@ public async Task UpdatePostAsync_ErrorResponse_SetsErrorStatus()
142142
using var response = GetErrorResponse();
143143
var httpClientFactory = CreateMockHttpClientFactory(response: response);
144144
var viewModel = new MainWindowViewModel(httpClientFactory);
145-
var testPost = new JSONPlaceholder.Generated.Post(UserId: 1, Id: 1, Title: "Test", Body: "Body");
145+
var testPost = new JSONPlaceholder.Generated.Post(
146+
UserId: 1,
147+
Id: 1,
148+
Title: "Test",
149+
Body: "Body"
150+
);
146151

147152
await viewModel.UpdatePostCommand.ExecuteAsync(testPost).ConfigureAwait(false);
148153

@@ -175,7 +180,12 @@ public async Task DeletePostAsync_ErrorResponse_SetsErrorStatus()
175180
using var response = GetErrorResponse();
176181
var httpClientFactory = CreateMockHttpClientFactory(response: response);
177182
var viewModel = new MainWindowViewModel(httpClientFactory);
178-
var testPost = new JSONPlaceholder.Generated.Post(UserId: 1, Id: 1, Title: "Test", Body: "Body");
183+
var testPost = new JSONPlaceholder.Generated.Post(
184+
UserId: 1,
185+
Id: 1,
186+
Title: "Test",
187+
Body: "Body"
188+
);
179189
viewModel.Posts.Add(testPost);
180190

181191
await viewModel.DeletePostCommand.ExecuteAsync(testPost).ConfigureAwait(false);

0 commit comments

Comments
 (0)