fix(http-server-csharp): fix model file name when @friendlyName contains unresolved template placeholders - #11459
fix(http-server-csharp): fix model file name when @friendlyName contains unresolved template placeholders#11459abatishchev with Copilot wants to merge 5 commits into
Conversation
|
Azure Pipelines: Successfully started running 1 pipeline(s). 1 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
commit: |
|
You can try these changes here
|
… in model file names Co-authored-by: abatishchev <351644+abatishchev@users.noreply.github.com>
… is a TemplateParameter
When `@friendlyName` is applied to a template model with a template parameter
as the sourceObject (e.g., `@friendlyName("{name}TagsUpdate", T)` on `Model<T>`),
the decorator is called on the template declaration with `sourceObject` being a
`TemplateParameter`. In that case, `replaceTemplatedStringFromProperties` leaves
the `{name}` placeholders unresolved in the stored friendly name.
Fix: in `$friendlyName`, return early when `sourceObject.kind === "TemplateParameter"`
rather than storing an unresolved format string. The decorator is re-applied when the
template is instantiated with a concrete type, which correctly resolves the placeholders.
Also:
- Revert the downstream workaround in `getModelEmitName` in http-server-csharp
- Update the http-server-csharp test to use the actual ARM-style template pattern
- Add a compiler test verifying template declarations don't get unresolved friendly names
Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
a7939a0 to
dfd71f3
Compare
|
All changed packages have been documented.
Show changes
|
Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
Add a safety net in `applyDecoratorToType` (checker.ts) that skips running a decorator when any of its arguments is an unresolved `TemplateParameter` or `TemplateParameterAccess`. The checker already ensures decorators are not applied to template declarations via `skipDecorators: true`, but this explicit guard at the call site makes the protection robust and self-documenting. Also: - Revert the incorrect guard from `decorators.ts` (wrong layer) - Revert the `getModelEmitName` sanitization workaround (not needed) - Update test description in `decorators.test.ts` to accurately reflect the mechanism (skipDecorators, not a guard in the decorator itself) - Update the `generation.test.ts` test to use the real ARM-style pattern Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
…defaults
Operations resolved template parameter defaults before entering the
template declaration scope, unlike models/interfaces. A decorated
template used as a parameter default (e.g. the ARM
`Properties = TagsUpdateModel<Resource>` pattern) therefore ran its
decorators with the still-unresolved template parameter, storing
unresolved `{name}` friendly names.
Move the InTemplateDeclaration flag before checkTemplateDeclaration in
checkOperation and drop the applyDecoratorToType band-aid guard.
Fixes #11454
|
Superseded by #11477, which contains only the root-cause compiler fix (operations now enter the template declaration scope before resolving template parameter defaults, so decorators no longer run with unresolved template parameters). This PR had diverged from its original purpose across several earlier attempts, so closing in favor of the clean replacement. |
When
@friendlyNamestores a format string with{paramName}placeholders that weren't substituted (e.g.{name}TagsUpdate), the generated file was named{name}TagsUpdate.cswhile the class inside was correctly namedNameTagsUpdate— a discrepancy caused by the class name going throughpascalCase()(which treats{/}as word separators) while the file path used the raw string.Changes
src/components/models/model-helpers.ts— IngetModelEmitName, sanitize the@friendlyNamereturn value by replacing{paramName}placeholders with their PascalCase equivalents before using the name as a file path:{name}TagsUpdate→NameTagsUpdate.cs, matching the emitted class name.test/generation.test.ts— Regression test: verifies that a model decorated with@friendlyName("{name}TagsUpdate")producesNameTagsUpdate.cswith no literal{name}in the output path.