Skip to content

Commit

Permalink
Fix some code formatting issues (#5054)
Browse files Browse the repository at this point in the history
  • Loading branch information
lahma authored Nov 23, 2024
1 parent e8d971e commit 29eef8f
Show file tree
Hide file tree
Showing 43 changed files with 123 additions and 128 deletions.
7 changes: 2 additions & 5 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,9 @@
[IDE0039] Use local function
[IDE0045] 'if' statement can be simplified
[IDE0046] 'if' statement can be simplified
[IDE0055] Fix formatting
[IDE0056] Indexing can be simplified
[IDE0057] Substring can be simplified
[IDE0060] Remove unused parameter
[IDE0061] Use block body for local function
[IDE0090] 'new' expression can be simplified
[IDE0130] Namespace does not match folder structure
[IDE0160] Convert to block scoped namespace
Expand All @@ -77,14 +75,13 @@
[CA1720] Identifier 'xxx' contains type name
[CA1725] Overriden parameter name mismatch
[CA1845] Use span-based 'string.Concat' and 'AsSpan' instead of 'Substring'
[CA1861] Prefer 'static readonly' fields over constant array arguments
[CA1870] Use a cached 'SearchValues' instance for improved searching performance
[CA2263] Prefer the generic overload 'System.Enum.GetValues<TEnum>()'
[SYSLIB0012] 'Assembly.CodeBase' is obsolete
-->
<NoWarn>$(NoWarn);IDE0005;IDE0008;IDE0017;IDE0021;IDE0022;IDE0029;IDE0032;IDE0039;IDE0045;IDE0046;IDE0055;IDE0056;IDE0057;IDE0060;IDE0061;IDE0090;IDE0130;IDE0160;IDE0200;IDE0270;IDE0290;IDE0330</NoWarn>
<NoWarn>$(NoWarn);CA1200;CA1510;CA1514;CA1710;CA1716;CA1720;CA1725;CA1845;CA1861;CA1870;CA2263;SYSLIB0012</NoWarn>
<NoWarn>$(NoWarn);IDE0005;IDE0008;IDE0017;IDE0021;IDE0022;IDE0029;IDE0032;IDE0039;IDE0045;IDE0046;IDE0056;IDE0057;IDE0060;IDE0090;IDE0130;IDE0160;IDE0200;IDE0270;IDE0290;IDE0330</NoWarn>
<NoWarn>$(NoWarn);CA1200;CA1510;CA1514;CA1710;CA1716;CA1720;CA1725;CA1845;CA1870;CA2263;SYSLIB0012</NoWarn>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static IServiceCollection AddSwaggerDocument(this IServiceCollection serv
if (newtonsoftSettings != null && !hasSystemTextJsonOutputFormatter)
{
settings.ApplySettings(new NewtonsoftJsonSchemaGeneratorSettings { SerializerSettings = newtonsoftSettings }, mvcOptions.Value);
}
}
else if (systemTextJsonOptions != null)
{
settings.ApplySettings(new SystemTextJsonSchemaGeneratorSettings { SerializerOptions = systemTextJsonOptions }, mvcOptions.Value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public async Task When_parameter_is_array_then_CSharp_is_correct()
// Assert
Assert.Contains(@"foreach (var item_ in elementId) { urlBuilder_.Append(System.Uri.EscapeDataString(""elementId"")).Append('=').Append(System.Uri.EscapeDataString(ConvertToString(item_, System.Globalization.CultureInfo.InvariantCulture))).Append('&'); }", code);
}

[Fact]
public async Task when_content_is_formdata_with_property_array_then_content_should_be_added_in_foreach_in_csharp()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public async Task When_UseHttpRequestMessageCreationMethod_is_set_then_CreateReq
{
SchemaSettings = new NewtonsoftJsonSchemaGeneratorSettings()
});

var document = await swaggerGenerator.GenerateForControllerAsync<FooController>();
var generator = new CSharpClientGenerator(document, new CSharpClientGeneratorSettings
{
Expand Down Expand Up @@ -95,7 +95,7 @@ public async Task When_parameter_name_is_reserved_keyword_then_it_is_appended_wi
{
SchemaSettings = new NewtonsoftJsonSchemaGeneratorSettings()
});

var document = await swaggerGenerator.GenerateForControllerAsync<FooController>();
var generator = new CSharpClientGenerator(document, new CSharpClientGeneratorSettings());

Expand All @@ -114,7 +114,7 @@ public async Task When_code_is_generated_then_by_default_the_system_httpclient_i
{
SchemaSettings = new NewtonsoftJsonSchemaGeneratorSettings()
});

var document = await swaggerGenerator.GenerateForControllerAsync<FooController>();
var generator = new CSharpClientGenerator(document, new CSharpClientGeneratorSettings
{
Expand Down Expand Up @@ -212,7 +212,7 @@ public async Task When_client_class_generation_is_enabled_and_suppressed_then_cl
SuppressClientClassesOutput = true,
GenerateClientInterfaces = true,
// SuppressClientInterfacesOutput = false, // default
});
});

// Act
var code = generator.GenerateFile();
Expand All @@ -238,7 +238,7 @@ public async Task When_client_interface_generation_is_enabled_and_suppressed_the
// SuppressClientClassesOutput = false, // default
GenerateClientInterfaces = true,
SuppressClientInterfacesOutput = true,
});
});

// Act
var code = generator.GenerateFile();
Expand Down
3 changes: 1 addition & 2 deletions src/NSwag.CodeGeneration.CSharp.Tests/WrapResponsesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public async Task When_success_responses_are_wrapped_then_SwaggerResponse_is_ret
WrapResponses = true
});
var code = codeGen.GenerateFile();

// Assert
Assert.Contains("Task<SwaggerResponse<string>>", code);
Assert.Contains("Task<SwaggerResponse>", code);
Expand All @@ -81,7 +81,6 @@ public async Task When_success_responses_are_wrapped_then_SwaggerResponse_is_ret
var codeGen = new CSharpControllerGenerator(document, new CSharpControllerGeneratorSettings
{
WrapResponses = true,

});
var code = codeGen.GenerateFile();

Expand Down
2 changes: 1 addition & 1 deletion src/NSwag.CodeGeneration.CSharp/CSharpGeneratorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public override string GetTypeName(JsonSchema schema, bool isNullable, string ty
/// <returns>FileResponse by default, FileResult if ControllerTarger parameter is AspNetCore</returns>
public override string GetBinaryResponseTypeName()
{
if (_settings is CSharpControllerGeneratorSettings controllerSettings
if (_settings is CSharpControllerGeneratorSettings controllerSettings
&& controllerSettings.ControllerTarget == CSharpControllerTarget.AspNetCore)
{
return "FileResult";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public string JsonSerializerParameterCode
get
{
var parameterCode = CSharpJsonSerializerGenerator.GenerateJsonSerializerParameterCode(
_settings.CSharpGeneratorSettings, RequiresJsonExceptionConverter ? new[] { "JsonExceptionConverter" } : null);
_settings.CSharpGeneratorSettings, RequiresJsonExceptionConverter ? jsonExceptionConverterArray : null);

if (!parameterCode.Contains("new Newtonsoft.Json.JsonSerializerSettings"))
{
Expand All @@ -178,7 +178,7 @@ public string JsonSerializerParameterCode

/// <summary>Gets the JSON converters array code.</summary>
public string JsonConvertersArrayCode
=> CSharpJsonSerializerGenerator.GenerateJsonConvertersArrayCode(_settings.CSharpGeneratorSettings, RequiresJsonExceptionConverter ? new[] { "JsonExceptionConverter" } : null);
=> CSharpJsonSerializerGenerator.GenerateJsonConvertersArrayCode(_settings.CSharpGeneratorSettings, RequiresJsonExceptionConverter ? jsonExceptionConverterArray : null);

/// <summary>Gets the Title.</summary>
public string Title => _document.Info.Title;
Expand All @@ -196,5 +196,7 @@ public string JsonConvertersArrayCode
_settings.CSharpGeneratorSettings.JsonLibrary == CSharpJsonLibrary.NewtonsoftJson &&
_settings.CSharpGeneratorSettings.ExcludedTypeNames?.Contains("JsonExceptionConverter") != true &&
_document.Operations.Any(o => o.Operation.ActualResponses.Any(r => r.Value.Schema?.InheritsSchema(_exceptionSchema) == true));

private static readonly string[] jsonExceptionConverterArray = ["JsonExceptionConverter"];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ protected CSharpTemplateModelBase(string controllerName, CSharpGeneratorBaseSett
public bool UseSystemTextJson => _settings.CSharpGeneratorSettings.JsonLibrary == CSharpJsonLibrary.SystemTextJson;

/// <summary>Gets the JSON serializer settings type.</summary>
public string JsonSerializerSettingsType => _settings.CSharpGeneratorSettings.JsonLibrary == CSharpJsonLibrary.SystemTextJson ?
"System.Text.Json.JsonSerializerOptions" :
"Newtonsoft.Json.JsonSerializerSettings";
public string JsonSerializerSettingsType => _settings.CSharpGeneratorSettings.JsonLibrary == CSharpJsonLibrary.SystemTextJson
? "System.Text.Json.JsonSerializerOptions"
: "Newtonsoft.Json.JsonSerializerSettings";
}
}
4 changes: 2 additions & 2 deletions src/NSwag.CodeGeneration.TypeScript.Tests/AngularTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class Foo
public class DiscussionController : Controller
{
[HttpPost]
public void AddMessage([FromBody, Required]Foo message)
public void AddMessage([FromBody, Required] Foo message)
{
}

Expand Down Expand Up @@ -66,7 +66,7 @@ public class UrlEncodedRequestConsumingController : Controller
{
[HttpPost]
[Consumes("application/x-www-form-urlencoded")]
public void AddMessage([FromForm]Foo message, [FromForm]string messageId)
public void AddMessage([FromForm] Foo message, [FromForm] string messageId)
{
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ public class Foo
public class DiscussionController : Controller
{
[HttpPost]
public void AddMessage([FromBody]Foo message)
public void AddMessage([FromBody] Foo message)
{
}
}
public class UrlEncodedRequestConsumingController: Controller

public class UrlEncodedRequestConsumingController : Controller
{
[HttpPost]
[Consumes("application/x-www-form-urlencoded")]
public void AddMessage([FromForm]Foo message, [FromForm]string messageId)
public void AddMessage([FromForm] Foo message, [FromForm] string messageId)
{
}
}
Expand Down Expand Up @@ -91,7 +91,7 @@ public async Task When_export_types_is_false_then_dont_add_export_before_classes
Assert.DoesNotContain("export class DiscussionClient", code);
Assert.DoesNotContain("export interface IDiscussionClient", code);
}

[Fact]
public async Task When_consumes_is_url_encoded_then_construct_url_encoded_request()
{
Expand Down
10 changes: 5 additions & 5 deletions src/NSwag.CodeGeneration.TypeScript.Tests/JQueryPromisesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ public class Foo
public class DiscussionController : Controller
{
[HttpPost]
public void AddMessage([FromBody]Foo message)
public void AddMessage([FromBody] Foo message)
{
}
}
public class UrlEncodedRequestConsumingController: Controller

public class UrlEncodedRequestConsumingController : Controller
{
[HttpPost]
[Consumes("application/x-www-form-urlencoded")]
public void AddMessage([FromForm]Foo message, [FromForm]string messageId)
public void AddMessage([FromForm] Foo message, [FromForm] string messageId)
{
}
}
Expand Down Expand Up @@ -91,7 +91,7 @@ public async Task When_export_types_is_false_then_dont_add_export_before_classes
Assert.DoesNotContain("export class DiscussionClient", code);
Assert.DoesNotContain("export interface IDiscussionClient", code);
}

[Fact]
public async Task When_consumes_is_url_encoded_then_construct_url_encoded_request()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class SecondChild : Base
public class Nested
{
public Base Child { get; set; }

public ICollection<Base> ChildCollection { get; set; }
}

Expand All @@ -50,19 +50,19 @@ public string TestLeaf(Base param)
{
return null;
}

[Route("foo-arr")]
public string TestLeafArr(ICollection<Base> param)
{
return null;
}

[Route("bar")]
public string Test(OneChild param)
{
return null;
}

[Route("baz")]
public string TestNested(Nested param)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public async Task When_parameter_is_nullable_and_ts20_then_it_is_a_union_type_wi
{
TypeScriptGeneratorSettings =
{
TypeScriptVersion = 2.0m,
TypeScriptVersion = 2.0m,
NullValue = TypeScriptNullValue.Undefined
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/NSwag.CodeGeneration/Models/OperationModelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ protected IList<OpenApiParameter> GetActualParameters()

var formDataSchema =
_operation?.ActualRequestBody?.Content?.ContainsKey("multipart/form-data") == true ?
_operation.ActualRequestBody.Content["multipart/form-data"]?.Schema.ActualSchema: null;
_operation.ActualRequestBody.Content["multipart/form-data"]?.Schema.ActualSchema : null;

if (formDataSchema != null && formDataSchema.ActualProperties.Count > 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public virtual string GetOperationName(OpenApiDocument document, string path, st
var hasNameConflict = document.Paths
.SelectMany(pair => pair.Value.ActualPathItem
.Select(p => new { Path = pair.Key.Trim('/'), HttpMethod = p.Key, Operation = p.Value }))
.Where(op =>
GetClientName(document, op.Path, op.HttpMethod, op.Operation) == GetClientName(document, path, httpMethod, operation) &&
.Where(op =>
GetClientName(document, op.Path, op.HttpMethod, op.Operation) == GetClientName(document, path, httpMethod, operation) &&
ConvertPathToName(op.Path) == operationName
).ToList()
.Count > 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public virtual string GetOperationName(OpenApiDocument document, string path, st
var hasNameConflict = document.Paths
.SelectMany(pair => pair.Value.ActualPathItem
.Select(p => new { Path = pair.Key.Trim('/'), HttpMethod = p.Key, Operation = p.Value }))
.Where(op =>
GetClientName(document, op.Path, op.HttpMethod, op.Operation) == GetClientName(document, path, httpMethod, operation) &&
.Where(op =>
GetClientName(document, op.Path, op.HttpMethod, op.Operation) == GetClientName(document, path, httpMethod, operation) &&
ConvertPathToName(op.Path) == operationName
)
.ToList().Count > 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public override async Task<object> RunAsync(CommandLineProcessor processor, ICon

var binaryName = LauncherBinaryName + ".dll";
var executorBinary = Path.Combine(toolDirectory, binaryName);

if (!File.Exists(executorBinary))
{
binaryName = LauncherBinaryName + ".exe";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ private static async Task<Dictionary<string, string>> TryReadingUsingGetProperti
{
WorkingDirectory = Path.GetDirectoryName(file),
FileName = "dotnet",
Arguments = $"{string.Join(" " , args)} --getProperty:{string.Join(";", properties)}",
Arguments = $"{string.Join(" ", args)} --getProperty:{string.Join(";", properties)}",
CreateNoWindow = true,
RedirectStandardOutput = true,
RedirectStandardError = true
Expand Down
2 changes: 1 addition & 1 deletion src/NSwag.Commands/NSwagCommandProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private void WriteBinDirectory()
var getEntryAssemblyMethod = typeof(Assembly).GetRuntimeMethod("GetEntryAssembly", []);
if (getEntryAssemblyMethod != null)
{
entryAssembly = (Assembly) getEntryAssemblyMethod.Invoke(null, []);
entryAssembly = (Assembly)getEntryAssemblyMethod.Invoke(null, []);
}
else
{
Expand Down
1 change: 0 additions & 1 deletion src/NSwag.Commands/NSwagDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ private string GetArgumentsPrefix()
{
return "\"" + System.IO.Path.Combine(RootBinaryDirectory, "Net90/dotnet-nswag.dll") + "\" ";
}
else
#endif
return "";
}
Expand Down
2 changes: 1 addition & 1 deletion src/NSwag.Commands/NSwagDocumentBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public string ToJson()
/// <returns>The document.</returns>
protected async Task<OpenApiDocument> GenerateSwaggerDocumentAsync()
{
return (OpenApiDocument) await SelectedSwaggerGenerator.RunAsync(null, null);
return (OpenApiDocument)await SelectedSwaggerGenerator.RunAsync(null, null);
}

private static string EscapeJsonString(string value)
Expand Down
4 changes: 2 additions & 2 deletions src/NSwag.Commands/NewLineBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ public enum NewLineBehavior
/// <summary>
/// Automatic line ending based on the current OS.
/// </summary>
Auto,
Auto,

/// <summary>
/// CRLF.
/// </summary>
CRLF,
CRLF,

/// <summary>
/// LF.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,13 @@ private static OpenApiDocument CreateDocument(JsonObjectType type)
new OpenApiPathItem
{
{
OpenApiOperationMethod.Get,
OpenApiOperationMethod.Get,
new OpenApiOperation
{
Responses =
{
{
"200",
"200",
new OpenApiResponse
{
Examples = 123,
Expand Down
Loading

0 comments on commit 29eef8f

Please sign in to comment.