Skip to content

[wip] add naming normalization for dates - #11664

Draft
Jorge Rangel (jorgerangel-msft) wants to merge 4 commits into
mainfrom
jorgerangel-msft-fix-unbranded-date-suffixes
Draft

[wip] add naming normalization for dates#11664
Jorge Rangel (jorgerangel-msft) wants to merge 4 commits into
mainfrom
jorgerangel-msft-fix-unbranded-date-suffixes

Conversation

@jorgerangel-msft

@jorgerangel-msft Jorge Rangel (jorgerangel-msft) commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

@jorgerangel-msft Jorge Rangel (jorgerangel-msft) changed the title add acaornym naming for dates add naming normalization for dates Aug 13, 2026
@microsoft-github-policy-service microsoft-github-policy-service Bot added the emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp label Aug 13, 2026
@pkg-pr-new

pkg-pr-new Bot commented Aug 13, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/http-client-csharp@11664

commit: 9b0729d

@github-actions

Copy link
Copy Markdown
Contributor

No changes needing a change description found.

@jorgerangel-msft Jorge Rangel (jorgerangel-msft) changed the title add naming normalization for dates [wip] add naming normalization for dates Aug 13, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces date/time naming normalization in the C# generator so *Time/*Date/*At/*Timestamp/*DateTime-suffixed date-like shapes are surfaced with an On suffix (and some noun adjustments like Creation* -> CreatedOn), while preserving wire names.

Changes:

  • Added NormalizeDateTimeSuffix(name, inputType) and applied it during property and method-parameter naming (when not IsExactName).
  • Updated generated sample output to rename CreatedAtCreatedOn while keeping the XML element name createdAt.
  • Added/updated unit tests and golden test data to validate the new naming behavior.

Reviewed changes

Copilot reviewed 9 out of 12 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/http-client-csharp/generator/TestProjects/Local/Sample-TypeSpec/src/Generated/SampleTypeSpecModelFactory.cs Updates factory method parameter naming to createdOn to match new normalization.
packages/http-client-csharp/generator/TestProjects/Local/Sample-TypeSpec/src/Generated/Models/XmlAdvancedModel.Serialization.cs Switches serialization/deserialization to use CreatedOn while keeping wire element name createdAt.
packages/http-client-csharp/generator/TestProjects/Local/Sample-TypeSpec/src/Generated/Models/XmlAdvancedModel.cs Renames model property/ctor parameter from CreatedAt to CreatedOn.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/PropertyProviderTests.cs Adds coverage for property name normalization for date/time suffix patterns.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/ParameterProviderTests.cs Adds coverage for method parameter name normalization for date/time suffix patterns.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Shared/CSharpNameExtensions.cs Implements the new NormalizeDateTimeSuffix and date/time type detection.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Providers/PropertyProvider.cs Applies date/time suffix normalization before acronym normalization (when allowed).
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Providers/ParameterProvider.cs Applies date/time suffix normalization to non-exact method parameters.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/XmlSerializationTests.cs Updates assertions to reflect normalized property naming in generated XML serialization.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/XmlDeserializationTests.cs Updates assertions to reflect normalized property naming in generated XML deserialization.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/XmlSerializationTests/XmlSerializationHandlesNullableDateTimeOffsetProperty.cs Updates expected generated output for nullable DateTimeOffset serialization to use On.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/ModelReaderWriterValidation/TestProjects/Sample_TypeSpec/XmlAdvancedModelXmlTests.cs Updates validation to use CreatedOn after renaming.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines 336 to 339
var methodBody = xmlSerializationMethod!.BodyStatements!.ToDisplayString();

Assert.IsTrue(methodBody.Contains("WriteStringValue") && methodBody.Contains("Timestamp"),
Assert.IsTrue(methodBody.Contains("writer.WriteStringValue(On.Value, \"O\")"),
$"DateTimeOffset property should be serialized with WriteStringValue. Actual:\n{methodBody}");
Comment on lines 262 to 265
var methodBody = xmlDeserializationMethod!.BodyStatements!.ToDisplayString();

Assert.IsTrue(methodBody.Contains("timestamp = child.GetDateTimeOffset(\"O\")"),
Assert.IsTrue(methodBody.Contains("@on = child.GetDateTimeOffset(\"O\")"),
$"DateTimeOffset property should use child.GetDateTimeOffset(\"O\") with RFC3339 format. Actual:\n{methodBody}");
Comment on lines +66 to +68
Name = inputParameter is InputMethodParameter && !inputParameter.IsExactName
? inputParameter.Name.NormalizeDateTimeSuffix(inputParameter.Type)
: inputParameter.Name;
private static readonly HashSet<string> _dateTimePrefixExclusions = new(StringComparer.OrdinalIgnoreCase)
{
"From",
"To"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot lets add PointInTime to this hashset

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added PointInTime to the date-time name exclusion set and used the set for suffix matching in 8bde832.

Comment on lines +68 to +85
public static string NormalizeDateTimeSuffix(this string name, InputType inputType)
{
if (!IsDateTimeInputType(inputType) ||
HasExcludedDateTimePrefix(name) ||
name.EndsWith("PointInTime", StringComparison.OrdinalIgnoreCase))
{
return name;
}

var suffixLength = GetDateTimeSuffixLength(name);
if (suffixLength == 0)
{
return name;
}

var prefix = name[..^suffixLength];
var onSuffix = prefix.Length == 0 && char.IsLower(name[0]) ? "on" : "On";
return prefix + onSuffix;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot would a stringbuilder approach be more effective here or is the perf bump not worth the complexity ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existing concatenation emits a single string.Concat allocation on the rename path; a StringBuilder would add complexity and typically an extra allocation for this two-part result, so it is not beneficial here.

@@ -20,6 +22,12 @@ private static readonly (string Source, string Replacement)[] _acronymRenamingRu
("Os", "OS")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot per the issue's guidelines, shouldn't we add "date" here to be replaced by On ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

date was already handled by GetDateTimeSuffixLength; 8bde832 adds direct unit coverage confirming it normalizes to on.

@@ -2,8 +2,10 @@
// Licensed under the MIT License.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot I'd like to see some unit tests for these new extension methods. If a current test suite doesn't exist, create it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added direct NormalizeDateTimeSuffix unit tests in 8bde832.

Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Complete deterministic date-time naming in the management generator

3 participants