Skip to content

Commit 3ed810a

Browse files
committed
chore: fix some SA-rules
1 parent ebee5eb commit 3ed810a

File tree

5 files changed

+45
-15
lines changed

5 files changed

+45
-15
lines changed

src/Atc.Rest.ApiGenerator.Framework/ContentGenerators/Server/ContentGeneratorServerConfigureSwaggerDocOptions.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,16 +245,18 @@ private static string BuildStringLiteral(
245245
// Use verbatim if backslashes or newlines are present.
246246
if (text.IndexOfAny(new[] { '\\', '\r', '\n' }) >= 0)
247247
{
248-
var verbatim = text.Replace("\"", "\"\"");
248+
var verbatim = text.Replace("\"", "\"\"", StringComparison.Ordinal);
249249
return "@\"" + verbatim + "\"";
250250
}
251251

252252
// Otherwise, use a normal C# string literal.
253-
var normal = text.Replace("\\", "\\\\").Replace("\"", "\\\"");
253+
var normal = text
254+
.Replace("\\", "\\\\", StringComparison.Ordinal)
255+
.Replace("\"", "\\\"", StringComparison.Ordinal);
254256
return "\"" + normal + "\"";
255257
}
256258

257259
private static bool Has(
258260
string? s)
259261
=> !string.IsNullOrWhiteSpace(s);
260-
}
262+
}

src/Atc.Rest.ApiGenerator.OpenApi/Extensions/OpenApiAnyExtensions.cs

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,41 @@ public static class OpenApiAnyExtensions
44
{
55
/// <summary>
66
/// Returns a string representation of common OpenAPI primitives with predictable, culture-fixed formatting.
7-
/// Notes:
8-
/// - Booleans -> "true"/"false" (lowercase JSON style).
9-
/// - Date -> "yyyy-MM-dd" (e.g., 2025-09-03), culture-fixed to avoid month/day swaps.
10-
/// - DateTime -> ISO 8601 round-trip "O" (e.g., 2025-09-03T12:34:56.7890123+00:00).
11-
/// - Double/Float -> "N" using en-US (group separators + decimals; e.g., 1,234.00).
12-
/// - Long/Integer -> default numeric ("G") with en-US (no group separators, no decimals; e.g., 1234).
13-
/// - Null -> "null" literal.
14-
/// - String/Password -> empty -> "string.Empty"; otherwise the raw value (unquoted).
157
/// </summary>
8+
/// <remarks>
9+
/// <para>Formatting rules:</para>
10+
/// <list type="bullet">
11+
/// <item><description><b>Booleans</b> → <c>"true"</c>/<c>"false"</c> (lowercase JSON style).</description></item>
12+
/// <item><description><b>Date</b> → <c>"yyyy-MM-dd"</c> (e.g., <c>2025-09-03</c>), culture-fixed to avoid month/day swaps.</description></item>
13+
/// <item><description><b>DateTime</b> → ISO 8601 round-trip <c>"O"</c> (e.g., <c>2025-09-03T12:34:56.7890123+00:00</c>).</description></item>
14+
/// <item><description><b>Double/Float</b> → standard numeric format <c>"N"</c> using en-US (group separators + decimals; e.g., <c>1,234.00</c>).</description></item>
15+
/// <item><description><b>Long/Integer</b> → general numeric format <c>"G"</c> using en-US (no group separators, no decimals; e.g., <c>1234</c>).</description></item>
16+
/// <item><description><b>Null</b> → the literal <c>"null"</c>.</description></item>
17+
/// <item><description><b>String/Password</b> → empty → <c>"string.Empty"</c>; otherwise the raw value (unquoted).</description></item>
18+
/// </list>
19+
/// <para>
20+
/// Culture is fixed to <see cref="GlobalizationConstants.EnglishCultureInfo"/> (en-US) to ensure consistent output across environments.
21+
/// </para>
22+
/// </remarks>
23+
/// <param name="openApiAny">The <see cref="IOpenApiAny"/> value to format (e.g., <see cref="OpenApiBoolean"/>, <see cref="OpenApiDate"/>, <see cref="OpenApiDateTime"/>, <see cref="OpenApiDouble"/>, <see cref="OpenApiFloat"/>, <see cref="OpenApiLong"/>, <see cref="OpenApiInteger"/>, <see cref="OpenApiNull"/>, <see cref="OpenApiPassword"/>, <see cref="OpenApiString"/>).</param>
24+
/// <returns>
25+
/// The formatted string representation of <paramref name="openApiAny"/>; <see langword="null"/> if <paramref name="openApiAny"/> is <see langword="null"/>.
26+
/// </returns>
27+
/// <exception cref="NotImplementedException">
28+
/// Thrown when <paramref name="openApiAny"/> is an <see cref="IOpenApiAny"/> subtype not handled by this method.
29+
/// </exception>
30+
/// <example>
31+
/// <code>
32+
/// IOpenApiAny v1 = new OpenApiDouble(1234);
33+
/// string? s1 = v1.GetDefaultValueAsString(); // "1,234.00"
34+
///
35+
/// IOpenApiAny v2 = new OpenApiDate(new DateOnly(2025, 9, 3));
36+
/// string? s2 = v2.GetDefaultValueAsString(); // "2025-09-03"
37+
///
38+
/// IOpenApiAny v3 = new OpenApiString(string.Empty);
39+
/// string? s3 = v3.GetDefaultValueAsString(); // "string.Empty"
40+
/// </code>
41+
/// </example>
1642
public static string? GetDefaultValueAsString(
1743
this IOpenApiAny? openApiAny)
1844
{

src/Atc.Rest.ApiGenerator.OpenApi/Extensions/OpenApiParameterExtensions.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ public static bool ContainsEnumInSchemaOrProperties(
4747
var defaultValueInitializer = openApiParameter.Schema.GetDefaultValueAsString();
4848

4949
if (!string.IsNullOrEmpty(defaultValueInitializer) &&
50-
openApiParameter.ContainsEnumInSchemaOrProperties())
50+
openApiParameter.ContainsEnumInSchemaOrProperties() &&
51+
dataType != "long" &&
52+
dataType != "string")
5153
{
5254
defaultValueInitializer = dataType.Equals(parameterName, StringComparison.Ordinal)
5355
? $"{contractNamespaceWithoutApiGroupName}.{dataType}.{defaultValueInitializer.PascalCase(ApiOperationExtractor.ModelNameSeparators, removeSeparators: true)}"

src/Atc.Rest.ApiGenerator.OpenApi/Extractors/ApiOperationExtractor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,9 @@ private static void CollectSchema(
168168
httpOperation,
169169
parentApiSchema,
170170
result);
171-
}
172171

173-
return;
172+
return;
173+
}
174174
}
175175

176176
(var schemaKey, apiSchema) = ConsolidateSchemaObjectTypes(apiSchema);

test/Atc.Rest.ApiGenerator.CLI.Tests/Scenarios/Monta/VerifyClient/WCEM/src/Monta.ApiClient.Generated/Contracts/_Shared/Pricing.verified.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public class Pricing
5757
/// <summary>
5858
/// Used by Spot Price. It will multiply the fallback price by this percentage.
5959
/// </summary>
60-
public double? Percentage { get; set; }
60+
public float? Percentage { get; set; }
6161

6262
/// <summary>
6363
/// The id of the selected Tariff.

0 commit comments

Comments
 (0)