From b3075f0fbb5715bc498e58c4fcec42ab329b4958 Mon Sep 17 00:00:00 2001 From: Travis Prescott Date: Wed, 22 Nov 2023 10:38:30 -0800 Subject: [PATCH] Fix issue with operation parameter versioning (#2691) Fixes #2688. --- .../versioning-OpParams_2023-11-22-18-08.json | 10 ++++ packages/versioning/src/validate.ts | 18 -------- .../test/incompatible-versioning.test.ts | 46 ------------------- packages/versioning/test/versioning.test.ts | 28 +++++++++++ 4 files changed, 38 insertions(+), 64 deletions(-) create mode 100644 common/changes/@typespec/versioning/versioning-OpParams_2023-11-22-18-08.json diff --git a/common/changes/@typespec/versioning/versioning-OpParams_2023-11-22-18-08.json b/common/changes/@typespec/versioning/versioning-OpParams_2023-11-22-18-08.json new file mode 100644 index 0000000000..3c8fd8571b --- /dev/null +++ b/common/changes/@typespec/versioning/versioning-OpParams_2023-11-22-18-08.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@typespec/versioning", + "comment": "", + "type": "none" + } + ], + "packageName": "@typespec/versioning" +} \ No newline at end of file diff --git a/packages/versioning/src/validate.ts b/packages/versioning/src/validate.ts index 03205a6391..5b77adb082 100644 --- a/packages/versioning/src/validate.ts +++ b/packages/versioning/src/validate.ts @@ -532,24 +532,6 @@ function validateOperationParameter( return; } } - - if (paramAvailability !== undefined) { - validateAvailabilityForContains( - program, - operationAvailability, - paramAvailability, - operation, - parameter - ); - } else if (paramTypeAvailability !== undefined) { - validateAvailabilityForRef( - program, - operationAvailability, - paramTypeAvailability, - operation, - parameter.type - ); - } } /** diff --git a/packages/versioning/test/incompatible-versioning.test.ts b/packages/versioning/test/incompatible-versioning.test.ts index e3365de289..30fa5787bd 100644 --- a/packages/versioning/test/incompatible-versioning.test.ts +++ b/packages/versioning/test/incompatible-versioning.test.ts @@ -146,52 +146,6 @@ describe("versioning: validate incompatible references", () => { }); }); - it("emit diagnostic when when op was added before parameter type", async () => { - const diagnostics = await runner.diagnose(` - @added(Versions.v2) - model Foo {} - - @added(Versions.v1) - op test(param: Foo): void; - `); - expectDiagnostics(diagnostics, { - code: "@typespec/versioning/incompatible-versioned-reference", - message: - "'TestService.test' was added in version 'v1' but referencing type 'TestService.Foo' added in version 'v2'.", - }); - }); - - it("emit diagnostic when op based on a template was added before parameter type", async () => { - const diagnostics = await runner.diagnose(` - @added(Versions.v2) - model Foo {} - - op Template(param: T): void; - - @added(Versions.v1) - op test is Template; - `); - expectDiagnostics(diagnostics, { - code: "@typespec/versioning/incompatible-versioned-reference", - message: - "'TestService.test' was added in version 'v1' but referencing type 'TestService.Foo' added in version 'v2'.", - }); - }); - - it("emit diagnostic when when parameter was added before op", async () => { - const diagnostics = await runner.diagnose(` - model Foo {} - - @added(Versions.v2) - op test(@added(Versions.v1) param: Foo): void; - `); - expectDiagnostics(diagnostics, { - code: "@typespec/versioning/incompatible-versioned-reference", - message: - "'TestService.test' was added in version 'v2' but contains type 'TestService.(anonymous model).param' added in version 'v1'.", - }); - }); - it("emit diagnostic when type changed to types that don't exist", async () => { const diagnostics = await runner.diagnose(` @added(Versions.v3) diff --git a/packages/versioning/test/versioning.test.ts b/packages/versioning/test/versioning.test.ts index a9af49eedc..2872c3de63 100644 --- a/packages/versioning/test/versioning.test.ts +++ b/packages/versioning/test/versioning.test.ts @@ -912,6 +912,34 @@ describe("versioning: logic", () => { w2.operations.get("create")?.parameters.properties.size === 2; }); + it("can share a model reference between operations with different versions", async () => { + const code = ` + @test("MyService") + @versioned(Versions) + namespace MyService; + + enum Versions { v1, v2, v3 }; + + model Foo { + prop: string; + } + + model Parameters { + name: string; + + @added(Versions.v2) + age: Foo; + } + + @added(Versions.v1) + op oldOp(...Parameters): void; + + @added(Versions.v3) + op newOp(...Parameters): void; + `; + ok(await runner.compile(code)); + }); + it("can be removed", async () => { const { projections: [v1, v2],