Skip to content

Commit

Permalink
Remove reference to projections (#2336)
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheeguerin authored Mar 7, 2025
1 parent c049424 commit 7fc6c6b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
9 changes: 9 additions & 0 deletions .chronus/changes/remove-projections-2025-2-7-19-30-56.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
changeKind: feature
packages:
- "@azure-tools/typespec-autorest"
- "@azure-tools/typespec-azure-core"
---

Remove reference to deleted projection feature
8 changes: 2 additions & 6 deletions packages/typespec-autorest/src/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,7 @@ export async function getOpenAPIForService(
prop.type.kind === "Scalar" &&
ignoreDiagnostics(
program.checker.isTypeAssignableTo(
// eslint-disable-next-line @typescript-eslint/no-deprecated
prop.type.projectionBase ?? prop.type,
prop.type,
program.checker.getStdType("url"),
prop.type,
),
Expand Down Expand Up @@ -759,8 +758,7 @@ export async function getOpenAPIForService(
}

function isBytes(type: Type) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
const baseType = type.projectionBase ?? type;
const baseType = type;
return ignoreDiagnostics(
program.checker.isTypeAssignableTo(baseType, program.checker.getStdType("bytes"), type),
);
Expand Down Expand Up @@ -1106,8 +1104,6 @@ export async function getOpenAPIForService(

function getJsonName(type: Type & { name: string }): string {
const encodedName = resolveEncodedName(program, type, "application/json");
// Pick the value set via `encodedName` or default back to the legacy projection otherwise.
// `resolveEncodedName` will return the original name if no @encodedName so we have to do that check
return encodedName === type.name ? type.name : encodedName;
}

Expand Down
30 changes: 16 additions & 14 deletions packages/typespec-azure-core/test/test-host.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import {
Diagnostic,
listServices,
Model,
Namespace,
Program,
projectProgram,
} from "@typespec/compiler";
import { Diagnostic, listServices, Model, Namespace, Program } from "@typespec/compiler";
import { unsafe_mutateSubgraphWithNamespace } from "@typespec/compiler/experimental";
import { BasicTestRunner, createTestHost, createTestWrapper } from "@typespec/compiler/testing";
import {
getAllHttpServices,
Expand All @@ -17,8 +11,9 @@ import {
import { HttpTestLibrary } from "@typespec/http/testing";
import { OpenAPITestLibrary } from "@typespec/openapi/testing";
import { RestTestLibrary } from "@typespec/rest/testing";
import { buildVersionProjections } from "@typespec/versioning";
import { getVersioningMutators } from "@typespec/versioning";
import { VersioningTestLibrary } from "@typespec/versioning/testing";
import { strictEqual } from "assert";
import { AzureCoreTestLibrary } from "../src/testing/index.js";

export async function createAzureCoreTestHost() {
Expand Down Expand Up @@ -118,12 +113,19 @@ export async function getSimplifiedOperations(

export function getServiceForVersion(program: Program, version: string): Namespace {
const services = listServices(program);
const versions = buildVersionProjections(program, services[0].type);
const versionRecord = versions.find((v) => v.version === version);
const result = getVersioningMutators(program, services[0].type);
strictEqual(result?.kind, "versioned");
const snapshot = result.snapshots.find(
(v) => v.version.value === version || v.version.name === version,
);

if (versionRecord) {
const projectedProgram = projectProgram(program, versionRecord.projections);
return projectedProgram.projector.projectedTypes.get(services[0].type) as Namespace;
if (snapshot) {
const subgraph = unsafe_mutateSubgraphWithNamespace(
program,
[snapshot.mutator],
services[0].type,
);
return subgraph.type as Namespace;
}

throw new Error(`Version '${version}' not found!`);
Expand Down

0 comments on commit 7fc6c6b

Please sign in to comment.