From f6e159d380593a438a6d786daf3154b3fd7d588a Mon Sep 17 00:00:00 2001 From: Travis Prescott Date: Mon, 20 Nov 2023 10:38:29 -0800 Subject: [PATCH] Add test for #2690. --- packages/versioning/src/validate.ts | 3 -- .../test/versioned-dependencies.test.ts | 29 ----------- packages/versioning/test/versioning.test.ts | 49 ++++++++++++++++++- 3 files changed, 47 insertions(+), 34 deletions(-) diff --git a/packages/versioning/src/validate.ts b/packages/versioning/src/validate.ts index 5748c727c1..61170b40b1 100644 --- a/packages/versioning/src/validate.ts +++ b/packages/versioning/src/validate.ts @@ -95,9 +95,6 @@ export function $onValidate(program: Program) { if (op.interface) { validateTargetVersionCompatible(program, op.interface, op, { isTargetADependent: true }); } - for (const prop of op.parameters.properties.values()) { - validateReference(program, op, prop.type); - } validateReference(program, op, op.returnType); }, interface: (iface) => { diff --git a/packages/versioning/test/versioned-dependencies.test.ts b/packages/versioning/test/versioned-dependencies.test.ts index 16f0cd132a..34fa6b4979 100644 --- a/packages/versioning/test/versioned-dependencies.test.ts +++ b/packages/versioning/test/versioned-dependencies.test.ts @@ -809,35 +809,6 @@ describe("versioning: dependencies", () => { const [v1] = runProjections(runner.program, MyService); ok(v1.projectedTypes.get(MyService)); }); - - it("allows an operation parameter to have versioned properties", async () => { - const { WidgetService } = (await runner.compile(` - @versioned(Versions) - @service({ - title: "Widget Service", - }) - @test("WidgetService") - namespace WidgetService; - - enum Versions { - v1, - v2, - } - - model Widget { - @key id: string; - @added(Versions.v2) name: string; - } - - @added(Versions.v1) - @post - @route("create") - op create(@body _: Widget): Widget; - `)) as { WidgetService: Namespace }; - - const [v1, v2] = runProjections(runner.program, WidgetService); - ok(v1.projectedTypes.get(WidgetService)); - }); }); function runProjections(program: Program, rootNs: Namespace) { diff --git a/packages/versioning/test/versioning.test.ts b/packages/versioning/test/versioning.test.ts index d2c1a06a19..d759b20d4e 100644 --- a/packages/versioning/test/versioning.test.ts +++ b/packages/versioning/test/versioning.test.ts @@ -5,17 +5,23 @@ import { Model, Namespace, Operation, + Program, ProjectionApplication, projectProgram, Scalar, Type, Union, } from "@typespec/compiler"; -import { BasicTestRunner, createTestWrapper, expectDiagnostics } from "@typespec/compiler/testing"; +import { + BasicTestRunner, + createTestWrapper, + expectDiagnosticEmpty, + expectDiagnostics, +} from "@typespec/compiler/testing"; import { fail, ok, strictEqual } from "assert"; import { Version } from "../src/types.js"; import { VersioningTimeline } from "../src/versioning-timeline.js"; -import { getVersions, indexTimeline } from "../src/versioning.js"; +import { buildVersionProjections, getVersions, indexTimeline } from "../src/versioning.js"; import { createVersioningTestHost } from "./test-host.js"; import { assertHasMembers, @@ -873,6 +879,39 @@ describe("versioning: logic", () => { assertHasProperties(v2.parameters, ["a"]); }); + it("can be added on the same version the underlying model is added", async () => { + const { MyService } = (await runner.compile( + ` + @test("MyService") + @versioned(Versions) + namespace MyService; + + enum Versions { v1, v2 }; + + @added(Versions.v1) + op create(body: Widget, @added(Versions.v2) newThing: NewThing): Widget; + + model Widget { + @key id: string; + @added(Versions.v2) name: string; + } + + @added(Versions.v2) + model NewThing { + name: string; + } + ` + )) as { MyService: Namespace }; + + const [v1, v2] = runProjections(runner.program, MyService); + const w1 = v1.projectedTypes.get(MyService) as Namespace; + const w2 = v2.projectedTypes.get(MyService) as Namespace; + w1.models.get("Widget")?.properties.size === 1; + w1.operations.get("create")?.parameters.properties.size === 1; + w2.models.get("Widget")?.properties.size === 2; + w2.operations.get("create")?.parameters.properties.size === 2; + }); + it("can be removed", async () => { const { projections: [v1, v2], @@ -1780,3 +1819,9 @@ describe("versioning: logic", () => { return projector.projectedTypes.get(target) as T; } }); +function runProjections(program: Program, rootNs: Namespace) { + const versions = buildVersionProjections(program, rootNs); + const projectedPrograms = versions.map((x) => projectProgram(program, x.projections)); + projectedPrograms.forEach((p) => expectDiagnosticEmpty(p.diagnostics)); + return projectedPrograms.map((p) => p.projector); +}