Fix some SonarCloud issues (#955)

* Fixed some SonarCloud issues

* if (value.Contains('\n'))
This commit is contained in:
Stef Heyenrath
2023-06-13 19:31:04 +02:00
committed by GitHub
parent f6e35cbe2d
commit 5d0bf6f4e1
5 changed files with 176 additions and 167 deletions

View File

@@ -320,14 +320,14 @@ internal class OpenApiPathsMapper
var mappedHeaders = headers?.ToDictionary(
item => item.Key,
_ => GetExampleMatcherModel(null, _settings.HeaderPatternToUse).Pattern!
);
) ?? new Dictionary<string, object>();
if (!string.IsNullOrEmpty(responseContentType))
{
mappedHeaders.TryAdd(HeaderContentType, responseContentType!);
}
return mappedHeaders?.Keys.Any() == true ? mappedHeaders : null;
return mappedHeaders.Keys.Any() ? mappedHeaders : null;
}
private IList<ParamModel>? MapQueryParameters(IEnumerable<OpenApiParameter> queryParameters)

View File

@@ -47,9 +47,9 @@ public class WireMockOpenApiParser : IWireMockOpenApiParser
/// <inheritdoc />
[PublicAPI]
public IReadOnlyList<MappingModel> FromDocument(OpenApiDocument openApiDocument, WireMockOpenApiParserSettings? settings = null)
public IReadOnlyList<MappingModel> FromDocument(OpenApiDocument document, WireMockOpenApiParserSettings? settings = null)
{
return new OpenApiPathsMapper(settings ?? new WireMockOpenApiParserSettings()).ToMappingModels(openApiDocument.Paths, openApiDocument.Servers);
return new OpenApiPathsMapper(settings ?? new WireMockOpenApiParserSettings()).ToMappingModels(document.Paths, document.Servers);
}
/// <inheritdoc />

View File

@@ -138,7 +138,7 @@ internal static class CSharpFormatter
return "\"\"";
}
if (value.Contains("\n"))
if (value.Contains('\n'))
{
var escapedValue = value?.Replace("\"", "\"\"") ?? string.Empty;
return $"@\"{escapedValue}\"";