Skip to content

Commit

Permalink
Deprecate projected name (#2910)
Browse files Browse the repository at this point in the history
fix [#2832](#2832)
  • Loading branch information
timotheeguerin authored Mar 13, 2024
1 parent 00996bb commit 6d42ca6
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .chronus/changes/deprecate-projected-name-2024-1-12-21-5-53.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
changeKind: deprecation
packages:
- "@typespec/compiler"
---

Deprecate `@projectedName` decorator. `@encodedName` should be used instead.

Example:
```diff
-@projectedName("json", "exp")
+@encodedName("application/json", "exp")
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
changeKind: internal
packages:
- "@typespec/openapi3"
---
1 change: 1 addition & 0 deletions packages/compiler/lib/decorators.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ extern dec overload(target: Operation, overloadbase: Operation);
* }
* ```
*/
#deprecated "Use `@encodedName` instead for changing the name over the wire."
extern dec projectedName(
target: unknown,
targetName: valueof string,
Expand Down
6 changes: 6 additions & 0 deletions packages/compiler/test/projected-names.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe("compiler: projected-names", () => {
it("@projectName updates the name when running projection", async () => {
const { expireAt } = (await runner.compile(`
model Foo {
#suppress "deprecated" "for testing"
@projectedName("json", "exp")
@test expireAt: int32;
}
Expand All @@ -24,6 +25,7 @@ describe("compiler: projected-names", () => {
it("@projectName doesn't affect a different target", async () => {
const { expireAt } = (await runner.compile(`
model Foo {
#suppress "deprecated" "for testing"
@projectedName("json", "exp")
@test expireAt: int32;
}
Expand All @@ -35,6 +37,7 @@ describe("compiler: projected-names", () => {
it("can project to different targets", async () => {
const { expireAt } = (await runner.compile(`
model Foo {
#suppress "deprecated" "for testing"
@projectedName("json", "exp")
@projectedName("csharp", "ExpireAtCS")
@test expireAt: int32;
Expand All @@ -49,6 +52,7 @@ describe("compiler: projected-names", () => {
it("can project a different target on top of a projected one", async () => {
const { expireAt } = (await runner.compile(`
model Foo {
#suppress "deprecated" "for testing"
@projectedName("json", "exp")
@projectedName("csharp", "ExpireAtCS")
@test expireAt: int32;
Expand Down Expand Up @@ -93,7 +97,9 @@ describe("compiler: projected-names", () => {
it("projectedName overrides a previous renaming", async () => {
const { expireAt, renamedProperty } = (await runner.compile(`
model Foo {
#suppress "deprecated" "for testing"
@projectedName("json", "jsonExpireAt") @test expireAt: int32;
#suppress "deprecated" "for testing"
@projectedName("json", "jsonRenamedProperty") @test renamedProperty: string;
}
Expand Down
2 changes: 2 additions & 0 deletions packages/openapi3/test/models.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe("openapi3: models", () => {
const res = await oapiForModel(
"Foo",
`model Foo {
#suppress "deprecated" "for testing"
@projectedName("json", "xJson")
x: int32;
};`
Expand Down Expand Up @@ -60,6 +61,7 @@ describe("openapi3: models", () => {
const res = await oapiForModel(
"Foo",
`model Foo {
#suppress "deprecated" "for testing"
@encodedName("application/json", "xJson")
@projectedName("json", "projectedJson")
x: int32;
Expand Down

0 comments on commit 6d42ca6

Please sign in to comment.