Skip to content

[core] Support renaming and caching in visibility transforms. #7200

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

witemple-msft
Copy link
Member

@witemple-msft witemple-msft commented May 1, 2025

This PR adds some features and fixes a couple of bugs in the visibility transforms.

  • @withVisibilityFilter now accepts a nameTemplate optional argument that is used to rename named types as they are transformed.
  • @withVisibilityFilter now correctly completely ignores any type that is not subject to visibility transforms. Previously, it was still mutating/cloning types that were not subject to the transform, like Scalar types, even if it didn't transform them.
  • @withVisibilityFilter now caches transforms so that applications of the same visibility filter with the same name template now return identical result objects, reducing the number of structurally equivalent models/unions that are created.
  • @withVisibilityFilter now correctly considers the indexer of Model types, allowing it to work correctly on Array and Record types.
  • @withLifecycleUpdate also receives the above modifications.

Confirmed that this addresses the following issues in a local playground instance.

Closes #7016
Closes #7072

TODO before merging:

  • Add tests for regressions based on the linked issues.

Copy link
Contributor

github-actions bot commented May 1, 2025

All changed packages have been documented.

  • @typespec/compiler
Show changes

@typespec/compiler - feature ✏️

Added an optional nameTemplate argument to @withVisibilityFilter, allowing the visibility filters to rename models as they are transformed. This template is applied by default in the Create, Read, Update, Delete, and Query visibility transform templates. This allows for more flexible renaming than simply using the @friendlyName decorator, as it will change the primary name of the transformed type, reducing the incidence of naming conflicts.,> ,> Cached the result of applying visibility filters to types. If the same visibility filter is applied to the same type with the same configuration, the model instance produced by the visibility filter will be object-identical. This should reduce the incidence of multiple models that are structurally equivalent in visibility filters and conflicts over the name of models.

@typespec/compiler - fix ✏️

Fixed an error in Model visibility filtering where the indexer of a model was ignored. This prevented the value of Array/Record instances from being transformed correctly, as they now should be.

@azure-sdk
Copy link
Collaborator

azure-sdk commented May 1, 2025

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

@witemple-msft witemple-msft enabled auto-merge May 5, 2025 18:21
@witemple-msft witemple-msft added this pull request to the merge queue May 5, 2025
Merged via the queue into microsoft:main with commit ccacf06 May 5, 2025
22 checks passed
@witemple-msft witemple-msft deleted the witemple-msft/visibility-cache-renaming branch May 5, 2025 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1_0_E2E compiler:core Issues for @typespec/compiler
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Visibility is ignored for items in an array [Bug]: Duplicate type name error when using withVisibilityFilter on models with nested types
4 participants