Skip to content

Commit 63cb176

Browse files
Deprecate known values (#3094)
fix #3009 --------- Co-authored-by: Mark Cowlishaw <markcowl@microsoft.com>
1 parent 29aa4a5 commit 63cb176

File tree

5 files changed

+29
-0
lines changed

5 files changed

+29
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
changeKind: deprecation
3+
packages:
4+
- "@typespec/compiler"
5+
---
6+
7+
Deprecate `@knownValues` decorator. Use a named union of string literal with a string variant to achieve the same result without a decorator
8+
9+
Example:
10+
```diff
11+
-enum FooKV { a, b, c}
12+
-@knownValues(FooKV)
13+
-scalar foo extends string;
14+
+union Foo { "a", "b", "c", string }
15+
```
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
3+
changeKind: internal
4+
packages:
5+
- "@typespec/openapi3"
6+
---

packages/compiler/lib/decorators.tsp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ extern dec friendlyName(target: unknown, name: valueof string, formatArgs?: unkn
321321
* }
322322
* ```
323323
*/
324+
#deprecated "This decorator has been deprecated. Use a named union of string literals with a string variant to achieve the same result without a decorator."
324325
extern dec knownValues(target: string | numeric | ModelProperty, values: Enum);
325326

326327
/**

packages/compiler/test/decorators/decorators.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ describe("compiler: built-in decorators", () => {
416416
it("assign the known values to string scalar", async () => {
417417
const { Bar } = (await runner.compile(`
418418
enum Foo {one: "one", two: "two"}
419+
#suppress "deprecated" "For testing"
419420
@test
420421
@knownValues(Foo)
421422
scalar Bar extends string;
@@ -433,6 +434,7 @@ describe("compiler: built-in decorators", () => {
433434
one: 1;
434435
two: 2;
435436
}
437+
#suppress "deprecated" "For testing"
436438
@test
437439
@knownValues(Foo)
438440
scalar Bar extends int32;
@@ -447,6 +449,7 @@ describe("compiler: built-in decorators", () => {
447449
it("emit diagnostics when used on non model", async () => {
448450
const diagnostics = await runner.diagnose(`
449451
enum Foo {one, two}
452+
#suppress "deprecated" "For testing"
450453
@knownValues(Foo)
451454
enum Bar {}
452455
`);
@@ -464,6 +467,7 @@ describe("compiler: built-in decorators", () => {
464467
one: 1;
465468
two: 2;
466469
}
470+
#suppress "deprecated" "For testing"
467471
@knownValues(Foo)
468472
scalar Bar extends string;
469473
`);
@@ -476,6 +480,7 @@ describe("compiler: built-in decorators", () => {
476480

477481
it("emit diagnostics when used on non string model", async () => {
478482
const diagnostics = await runner.diagnose(`
483+
#suppress "deprecated" "For testing"
479484
enum Foo {one, two}
480485
@knownValues(Foo)
481486
model Bar {}
@@ -491,6 +496,7 @@ describe("compiler: built-in decorators", () => {
491496
it("emit diagnostics when known values is not an enum", async () => {
492497
const diagnostics = await runner.diagnose(`
493498
model Foo {}
499+
#suppress "deprecated" "For testing"
494500
@knownValues(Foo)
495501
scalar Bar extends string;
496502
`);

packages/openapi3/test/models.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ describe("openapi3: models", () => {
549549
Dog, Cat
550550
}
551551
552+
#suppress "deprecated" "For testing"
552553
@knownValues(KnownPetType)
553554
scalar PetType extends string;
554555
model Pet { type: PetType };

0 commit comments

Comments
 (0)