Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Validating cross namespace #4304

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading