Skip to content

Commit

Permalink
Fix: Validating cross namespace (microsoft#4304)
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheeguerin authored and sarangan12 committed Sep 16, 2024
1 parent 490b0ee commit e2c91c0
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
changeKind: internal
packages:
- "@typespec/versioning"
---

12 changes: 11 additions & 1 deletion packages/versioning/src/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,17 @@ function validateTargetVersionCompatible(
) {
const sourceAvailability = resolveAvailabilityForStack(program, source);
const [sourceNamespace] = getVersions(program, sourceAvailability.type);

// If we cannot get source availability check if there is some different versioning across the stack which would mean we verify across namespace and is causing issues.
if (sourceAvailability.map === undefined) {
const sources = Array.isArray(source) ? source : [source];
const baseNs = getVersions(program, sources[0]);
for (const type of sources) {
const ns = getVersions(program, type);
if (ns !== baseNs) {
return undefined;
}
}
}
const targetAvailability = resolveAvailabilityForStack(program, target);
const [targetNamespace] = getVersions(program, targetAvailability.type);
if (!targetAvailability.map || !targetNamespace) return;
Expand Down
26 changes: 26 additions & 0 deletions packages/versioning/test/versioned-dependencies.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,32 @@ describe("versioning: dependencies", () => {
runner = await createVersioningTestRunner();
});

it("cross namespace operation", async () => {
const diagnostics = await runner.diagnose(`
@versioned(Versions)
namespace Service {
enum Versions {
v1,
v2,
}
@added(Versions.v2)
op test(purpose: FilePurpose): void;
@added(Versions.v2)
model FilePurpose {
a: string;
}
}
@useDependency(Service.Versions.v2)
namespace Client {
op testClient is Service.test;
}
`);
expectDiagnosticEmpty(diagnostics);
});

it("use model defined in non versioned library spreading properties", async () => {
const { MyService, Test } = (await runner.compile(`
namespace NonVersionedLib {
Expand Down

0 comments on commit e2c91c0

Please sign in to comment.