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

Upgrade compiler to v0.62.x and tcgc in Nov. #2892

Merged
merged 22 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
3f595fb
upgrade tcgc cadl-ranch and compiler to latest
v-jiaodi Nov 6, 2024
6441656
Merge branch 'main' into upgrade-116
MaryGao Nov 11, 2024
14f5f8d
Fix the build issue for upgrading
MaryGao Nov 11, 2024
9619310
Report warnings for cookie parameter in RLC
MaryGao Nov 11, 2024
eea815e
update the ut for rlc and modular
MaryGao Nov 11, 2024
01bfa0a
Merge to main
MaryGao Nov 11, 2024
cfca3e5
Merge remote-tracking branch 'origin/main' into upgrade-116
MaryGao Nov 11, 2024
c0e1011
Update the lock file
MaryGao Nov 11, 2024
753e773
Update the nextlink to azure core's one
MaryGao Nov 11, 2024
f0e432f
Fix RLC ut failure
MaryGao Nov 11, 2024
2486e5d
Update the comments
MaryGao Nov 11, 2024
de610d4
Update the ruleset dependency
MaryGao Nov 11, 2024
3bcbdbf
update @nextLink to @Azure.core.nextLink
v-jiaodi Nov 11, 2024
df13414
Merge branch 'upgrade-116' of https://github.com/v-jiaodi/autorest.ty…
v-jiaodi Nov 11, 2024
6977fc2
Merge branch 'main' of https://github.com/Azure/autorest.typescript i…
v-jiaodi Nov 11, 2024
f255359
Update the failure for todo-non-branded.api
MaryGao Nov 11, 2024
410d2af
Remove the list decorator with error thrown
MaryGao Nov 11, 2024
11070e5
Merge remote-tracking branch 'v-jiaodi/upgrade-116' into pr/v-jiaodi/…
MaryGao Nov 11, 2024
88e9365
Update the smoke test
MaryGao Nov 11, 2024
1ede9b9
Downgrade the cadl ranch version
MaryGao Nov 11, 2024
ce2e07c
Revert cadl-ranch version
MaryGao Nov 11, 2024
6aaa7be
Merge branch 'main' into upgrade-116
MaryGao Nov 13, 2024
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
399 changes: 193 additions & 206 deletions common/config/rush/pnpm-lock.yaml

Large diffs are not rendered by default.

21 changes: 10 additions & 11 deletions packages/typespec-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@
"type": "module",
"dependencies": {
"@azure-tools/typespec-ts": "workspace:^0.33.0",
"@typespec/openapi": ">=0.61.0 <1.0.0",
"@azure-tools/typespec-autorest": ">=0.47.0 <1.0.0",
"@typespec/openapi3": ">=0.61.0 <1.0.0",
"@azure-tools/typespec-azure-core": ">=0.47.0 <1.0.0",
"@azure-tools/typespec-client-generator-core": ">=0.47.4 <1.0.0",
"@azure-tools/typespec-azure-resource-manager": ">=0.47.0 <1.0.0",
"@azure-tools/typespec-azure-rulesets": ">=0.47.0 <1.0.0",
"@typespec/compiler": ">=0.61.2 <1.0.0",
"@typespec/http": ">=0.61.0 <1.0.0",
"@typespec/rest": ">=0.61.0 <1.0.0",
"@typespec/versioning": ">=0.61.0 <1.0.0",
"@typespec/openapi": ">=0.62.0 <1.0.0",
"@azure-tools/typespec-autorest": ">=0.48.0 <1.0.0",
"@typespec/openapi3": ">=0.62.0 <1.0.0",
"@azure-tools/typespec-azure-core": ">=0.48.0 <1.0.0",
"@azure-tools/typespec-client-generator-core": ">=0.48.0 <1.0.0",
"@azure-tools/typespec-azure-resource-manager": ">=0.48.0 <1.0.0",
"@typespec/compiler": ">=0.62.0 <1.0.0",
"@typespec/http": ">=0.62.0 <1.0.0",
"@typespec/rest": ">=0.62.0 <1.0.0",
"@typespec/versioning": ">=0.62.0 <1.0.0",
"prettier": "^3.1.0"
},
"devDependencies": {
Expand Down
36 changes: 18 additions & 18 deletions packages/typespec-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@
"license": "MIT",
"devDependencies": {
"@azure-rest/core-client": "^2.3.1",
"@azure-tools/cadl-ranch-expect": "^0.15.5",
"@azure-tools/cadl-ranch-specs": "^0.38.0",
"@azure-tools/cadl-ranch": "^0.15.0",
"@azure-tools/cadl-ranch-expect": "^0.15.6",
"@azure-tools/cadl-ranch-specs": "^0.39.1",
"@azure-tools/cadl-ranch": "^0.16.1",
"@azure-tools/cadl-ranch-api": "^0.5.0",
"@azure-tools/typespec-autorest": ">=0.47.0 <1.0.0",
"@azure-tools/typespec-azure-core": ">=0.47.0 <1.0.0",
"@azure-tools/typespec-azure-resource-manager": ">=0.47.0 <1.0.0",
"@azure-tools/typespec-client-generator-core": ">=0.47.4 <1.0.0",
"@azure-tools/typespec-autorest": ">=0.48.0 <1.0.0",
"@azure-tools/typespec-azure-core": ">=0.48.0 <1.0.0",
"@azure-tools/typespec-azure-resource-manager": ">=0.48.0 <1.0.0",
"@azure-tools/typespec-client-generator-core": ">=0.48.0 <1.0.0",
"@azure/abort-controller": "^2.1.2",
"@azure/core-auth": "^1.6.0",
"@azure/core-lro": "^3.1.0",
Expand All @@ -85,12 +85,12 @@
"@types/node": "^18.0.0",
"@typescript-eslint/eslint-plugin": "^6.8.0",
"@typescript-eslint/parser": "^6.8.0",
"@typespec/compiler": ">=0.61.2 <1.0.0",
"@typespec/http": ">=0.61.0 <1.0.0",
"@typespec/openapi": ">=0.61.0, <1.0.0",
"@typespec/rest": ">=0.61.0 <1.0.0",
"@typespec/compiler": ">=0.62.0 <1.0.0",
"@typespec/http": ">=0.62.0 <1.0.0",
"@typespec/openapi": ">=0.62.0, <1.0.0",
"@typespec/rest": ">=0.62.0 <1.0.0",
"@typespec/ts-http-runtime": "1.0.0-alpha.20240314.2",
"@typespec/versioning": ">=0.61.0 <1.0.0",
"@typespec/versioning": ">=0.62.0 <1.0.0",
"chai": "^4.3.6",
"chalk": "^4.0.0",
"cross-env": "^7.0.3",
Expand All @@ -110,12 +110,12 @@
"tsx": "^4.16.5"
},
"peerDependencies": {
"@azure-tools/typespec-azure-core": ">=0.47.0 <1.0.0",
"@azure-tools/typespec-client-generator-core": ">=0.47.4 <1.0.0",
"@typespec/compiler": ">=0.61.2 <1.0.0",
"@typespec/http": ">=0.61.0 <1.0.0",
"@typespec/rest": ">=0.61.0 <1.0.0",
"@typespec/versioning": ">=0.61.0 <1.0.0"
"@azure-tools/typespec-azure-core": ">=0.48.0 <1.0.0",
"@azure-tools/typespec-client-generator-core": ">=0.48.0 <1.0.0",
"@typespec/compiler": ">=0.62.0 <1.0.0",
"@typespec/http": ">=0.62.0 <1.0.0",
"@typespec/rest": ">=0.62.0 <1.0.0",
"@typespec/versioning": ">=0.62.0 <1.0.0"
},
"dependencies": {
"@azure-tools/rlc-common": "workspace:^0.33.0",
Expand Down
6 changes: 6 additions & 0 deletions packages/typespec-ts/src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,12 @@ const libDef = {
messages: {
default: paramMessage`Path parameter '${"paramName"}' cannot be optional.`
}
},
"parameter-type-not-supported": {
severity: "warning",
messages: {
default: paramMessage`Parameter '${"paramName"}' with type '${"paramType"}' is not supported and we would ignore this parameter.`
}
}
},
emitter: {
Expand Down
19 changes: 18 additions & 1 deletion packages/typespec-ts/src/modular/buildCodeModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,18 @@ function emitParameter(
context: SdkContext,
parameter: HttpOperationParameter | HttpServerParameter,
implementation: string
): Parameter {
): Parameter | undefined {
if (parameter.type === "cookie") {
reportDiagnostic(context.program, {
code: "parameter-type-not-supported",
format: {
paramType: parameter.type,
paramName: parameter.name
},
target: NoTarget
});
return undefined;
}
const base = emitParamBase(context, parameter.param);
let type = getType(context, parameter.param.type, {
usage: UsageFlags.Input
Expand Down Expand Up @@ -857,6 +868,9 @@ function emitBasicOperation(
continue;
}
const emittedParam = emitParameter(context, param, "Method");
if (emittedParam === undefined) {
continue;
}
if (isApiVersion(context, param)) {
emittedParam.isApiVersion = true;
methodApiVersionParam = emittedParam;
Expand Down Expand Up @@ -1719,6 +1733,9 @@ function emitServerParams(
serverParameter,
"Client"
);
if (emittedParameter === undefined) {
continue;
}
endpointPathParameters.push(emittedParameter);
if (isApiVersion(context, serverParameter as any)) {
emittedParameter.isApiVersion = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export function getOperationApiVersion(
relevantProperty: p.param
});
required.add(!p.param.optional);
if (p.type !== "header") {
if (p.type === "query" || p.type === "path") {
locations.add(p.type);
}
const typeString = JSON.stringify(trimUsage(type));
Expand Down Expand Up @@ -127,7 +127,7 @@ export function getOperationApiVersion(
relevantProperty: p.param
});
required.add(!p.param.optional);
if (p.type !== "header") {
if (p.type === "query" || p.type === "path") {
locations.add(p.type);
}
const typeString = JSON.stringify(trimUsage(type));
Expand Down
24 changes: 23 additions & 1 deletion packages/typespec-ts/src/transform/transformParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
listOperationGroups,
listOperationsInOperationGroup
} from "@azure-tools/typespec-client-generator-core";
import { Type, isVoidType } from "@typespec/compiler";
import { NoTarget, Type, isVoidType } from "@typespec/compiler";
import {
getBodyType,
getFormattedPropertyDoc,
Expand All @@ -46,6 +46,7 @@ import {
} from "../utils/operationUtil.js";

import { SdkContext } from "../utils/interfaces.js";
import { reportDiagnostic } from "../lib.js";

export function transformToParameterTypes(
client: SdkClient,
Expand Down Expand Up @@ -99,6 +100,8 @@ export function transformToParameterTypes(
);
// transform path param
const pathParams = transformPathParameters();
// TODO: support cookie parameters, https://github.com/Azure/autorest.typescript/issues/2898
transformCookieParameters(dpgContext, parameters);
// transform header param including content-type
const headerParams = transformHeaderParameters(
dpgContext,
Expand Down Expand Up @@ -200,6 +203,25 @@ function getParameterName(name: string) {
return `"${name}"`;
}

function transformCookieParameters(
dpgContext: SdkContext,
parameters: HttpOperationParameters
) {
// TODO: support cookie parameters, https://github.com/Azure/autorest.typescript/issues/2898
parameters.parameters
.filter((p) => p.type === "cookie")
.forEach((p) => {
reportDiagnostic(dpgContext.program, {
code: "parameter-type-not-supported",
format: {
paramName: p.name,
paramType: p.type
},
target: NoTarget
});
});
}

function transformQueryParameters(
dpgContext: SdkContext,
parameters: HttpOperationParameters,
Expand Down
2 changes: 1 addition & 1 deletion packages/typespec-ts/test/modularUnit/operations.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ describe("operations", () => {
model Bar {
@items
lists: string[];
@nextLink
@Azure.Core.nextLink
MaryGao marked this conversation as resolved.
Show resolved Hide resolved
nextLink: string;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Should ignore cookie parameters for now

// TODO: https://github.com/Azure/autorest.typescript/issues/2898

## TypeSpec

This is tsp definition.

```tsp
op test(@cookie token: string): string;
```

Should ingore the warning `@azure-tools/typespec-ts/parameter-type-not-supported`:

```yaml
mustEmptyDiagnostic: false
```

## Provide generated operations to call rest-level methods

## Operations

Should normal path parameter:

```ts operations
import { TestingContext as Client } from "./index.js";
import {
StreamableMethod,
PathUncheckedResponse,
createRestError,
operationOptionsToRequestParameters
} from "@azure-rest/core-client";

export function _testSend(
context: Client,
options: TestOptionalParams = { requestOptions: {} }
): StreamableMethod {
return context
.path("/")
.get({ ...operationOptionsToRequestParameters(options) });
}

export async function _testDeserialize(
result: PathUncheckedResponse
): Promise<string> {
const expectedStatuses = ["200"];
if (!expectedStatuses.includes(result.status)) {
throw createRestError(result);
}

return result.body;
}

export async function test(
context: Client,
options: TestOptionalParams = { requestOptions: {} }
): Promise<string> {
const result = await _testSend(context, options);
return _testDeserialize(result);
}
```
25 changes: 25 additions & 0 deletions packages/typespec-ts/test/unit/parametersGenerator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,31 @@ import {
import { assertEqualContent } from "../util/testUtil.js";

describe("Parameters.ts", () => {
describe("cookie parameters", () => {
it("should report warning for cookie parameter", async () => {
try {
await emitParameterFromTypeSpec(
`
op test(@cookie token: string): string;
`
);
assert.fail("should throw error");
} catch (e: any) {
assert.strictEqual("Parameter 'token' with type 'cookie' is not supported and we would ignore this parameter.", e[0].message);
}
});

it("should not include cookie parameter", async () => {
const parameters = await emitParameterFromTypeSpec(
`
op test(@cookie token: string): string;
`
, {
mustEmptyDiagnostic: false
});
assert.notDeepInclude(parameters?.content, "token");
});
});
describe("query parameters", () => {
describe("apiVersion in query", () => {
it("should not generate apiVersion if there's a client level apiVersion but without default value", async () => {
Expand Down
Loading