[wip] add naming normalization for dates - #11664
[wip] add naming normalization for dates#11664Jorge Rangel (jorgerangel-msft) wants to merge 13 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 are test failures we need to address. We should never push changes that have build or test failures
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Fixed the back-compat parameter-name regression and validated it with the full C# generator test suite (all tests pass) in 3e406047. |
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
| /// </summary> | ||
| public InputParameter? InputParameter { get; private set; } | ||
|
|
||
| internal bool NameIsInitializedFromInputParameter { get; private set; } |
There was a problem hiding this comment.
Copilot why is this new property needed. The name will always be initialized from InputParameter if InputParameter is not null. CAn't we just use that property ?
There was a problem hiding this comment.
Removed the redundant state in 06f7bd6. InputParameter is now retained only by parameters directly initialized from input; synthesized request-content parameters no longer carry unrelated input metadata, so back-compat lookup can rely on InputParameter directly.
There was a problem hiding this comment.
Copilot there's several test failures again. DO NOT push changes if ANY of the tests are failing
Jorge Rangel (jorgerangel-msft)
left a comment
There was a problem hiding this comment.
Copilot pull latest main and address merge conflicts
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
…unbranded-date-suffixes # Conflicts: # packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/PropertyProviderTests.cs Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
fixes: Azure/azure-sdk-for-net#61943