Skip to content

Commit

Permalink
Fix: @withVisibility decorator (#2544)
Browse files Browse the repository at this point in the history
fix #2517
  • Loading branch information
timotheeguerin authored Oct 13, 2023
1 parent e762230 commit f110040
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@typespec/compiler",
"comment": "Fix: Properties filtered with `@withVisibility` will have their visibility removed. This prevent visibility from being applied twice and rendering invalid models",
"type": "none"
}
],
"packageName": "@typespec/compiler"
}
5 changes: 5 additions & 0 deletions packages/compiler/src/lib/decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -811,12 +811,17 @@ export function getVisibility(program: Program, target: Type): string[] | undefi
return program.stateMap(visibilitySettingsKey).get(target);
}

function clearVisibilities(program: Program, target: Type) {
program.stateMap(visibilitySettingsKey).delete(target);
}

export function $withVisibility(
context: DecoratorContext,
target: Model,
...visibilities: string[]
) {
filterModelPropertiesInPlace(target, (p) => isVisible(context.program, p, visibilities));
[...target.properties.values()].forEach((p) => clearVisibilities(context.program, p));
}

export function isVisible(
Expand Down

0 comments on commit f110040

Please sign in to comment.