[wip] add naming normalization for dates - #11664
[wip] add naming normalization for dates#11664Jorge Rangel (jorgerangel-msft) wants to merge 27 commits into
Conversation
commit: |
|
No changes needing a change description found. |
There was a problem hiding this comment.
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 notIsExactName). - Updated generated sample output to rename
CreatedAt→CreatedOnwhile keeping the XML element namecreatedAt. - 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.
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Jorge Rangel (jorgerangel-msft)
left a comment
There was a problem hiding this comment.
Copilot there's some issues I found when regenerating the azure libraries:
- Azure.Compute.Batch BatchClient no longer passes in the requestDate param in several ops
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Fixed the dropped Root cause: normalization was only applied to Both C# generator suites pass (1962 core, 1572 ClientModel) and regenerating the Local/Spector test projects produces no diff. If there was a second issue in your list (the bullet appears truncated), let me know and I'll address it. |
Jorge Rangel (jorgerangel-msft)
left a comment
There was a problem hiding this comment.
Copilot pull latest from main and address merge conflicts
…unbranded-date-suffixes # Conflicts: # packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/ParameterProviderTests.cs # packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/PropertyProviderTests.cs Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Merged the latest |
Copilot there's still issues on regenerating the batch compute client https://github.com/Azure/azure-sdk-for-net/pull/62202/changes#diff-6481de7a0feb164ee708af825b4648989fa868e33f5559e5efc15cb4dbbcedf8. The etag params are now being generated individually, instead of the expected requestConditions type. In addition, there's several call sites where there's a diff in regards to passing args by name. This is unexpected |
…enience calls Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Both symptoms trace back to the same root cause, which is already fixed on this branch by Root cause: normalization was originally applied only to Why the regen shows it: the regen commit in Azure/azure-sdk-for-net#62202 ( Verification: I added public virtual ClientResult TestMethod(DateTimeOffset? requestDate, string ifMatch, RequestOptions options)
public virtual ClientResult TestMethod(DateTimeOffset? requestDate = default, string ifMatch = default, CancellationToken cancellationToken = default)
{
return this.TestMethod(requestDate, ifMatch, cancellationToken.ToRequestOptions());
}I confirmed this test reproduces your report when the pre- |
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
|
Copilot pull the latest from main and address the merge conflicts |
|
regen preview: Azure/azure-sdk-for-net#62202 |
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Jorge Rangel (jorgerangel-msft)
left a comment
There was a problem hiding this comment.
Copilot from testing, I'm seeing at least 1 library introducing a breaking change https://github.com/jorgerangel-msft/azure-sdk-for-net/blob/8b18010fc3d8a195003d54940df3d1cac29c656a/sdk/apimanagement/Azure.ResourceManager.ApiManagement/src/Generated/Models/ApiManagementSubscriptionPatch.cs.
The previous GA shape was :
public class ApiManagementSubscriptionPatch : IJsonModel<ApiManagementSubscriptionPatch>, IPersistableModel<ApiManagementSubscriptionPatch> {
public ApiManagementSubscriptionPatch();
public bool? AllowTracing { get; set; }
public string DisplayName { get; set; }
public DateTimeOffset? ExpireOn { get; set; }
public string OwnerId { get; set; }
public string PrimaryKey { get; set; }
public string Scope { get; set; }
public string SecondaryKey { get; set; }
public SubscriptionState? State { get; set; }
public string StateComment { get; set; }
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
}Yet ExpireOn was renamed
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Fixed in 05e8a3f. Root cause: {"Creation", "Created"}, {"Deletion", "Deleted"}, {"Expiration", "Expire"}, {"Modification", "Modified"}So Fix: Added test cases for all four mapped nouns plus the non-exact-prefix negative case. Core suite (1981) and ClientModel suite (1576) pass; no diff when regenerating the Local/Spector test projects. |
fixes: Azure/azure-sdk-for-net#61943