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

Update the compiler version to v0.49 #2061

Merged
merged 13 commits into from
Oct 21, 2023
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
"cwd": "${workspaceFolder}/packages/typespec-ts",
"runtimeArgs": [
"cross-env",
"TS_NODE_PROJECT=tsconfig.test.json",
"TS_NODE_PROJECT=tsconfig.integration.json",
"mocha",
"-r",
"ts-node/register",
Expand Down
320 changes: 152 additions & 168 deletions common/config/rush/pnpm-lock.yaml

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions packages/typespec-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
"version": "1.0.0",
"type": "module",
"dependencies": {
"@typespec/compiler": ">=0.48.0 <1.0.0",
"@azure-tools/typespec-ts": "workspace:^0.17.1",
"@typespec/http": ">=0.48.0 <1.0.0",
"@typespec/rest": ">=0.48.0 <1.0.0",
"@typespec/openapi": ">=0.48.0 <1.0.0",
"@typespec/versioning": ">=0.48.0 <1.0.0",
"@azure-tools/typespec-azure-core": ">=0.34.0 <1.0.0",
"@azure-tools/typespec-autorest": ">=0.34.0 <1.0.0",
"@azure-tools/typespec-client-generator-core": "0.35.0-dev.9",
"@typespec/openapi": ">=0.49.0 <1.0.0",
"@azure-tools/typespec-autorest": ">=0.35.0 <1.0.0",
"@typespec/openapi3": ">=0.48.0 <1.0.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we still using 0.48.0 for openapi3 and prettier-plugin-typespec ? also, do we really rely on prettier-plugin-typespec ?

Copy link
Member Author

@MaryGao MaryGao Oct 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated openapi3 to v0.49 now and remvoed the prettier-plugin-typespec, before I used this to format our tsp codes and I think we could remove this because we could do that by tsp format command.

"@typespec/prettier-plugin-typespec": ">=0.48.0 <1.0.0",
"@azure-tools/typespec-azure-core": ">=0.35.0 <1.0.0",
"@azure-tools/typespec-client-generator-core": ">=0.35.0 <1.0.0",
"@typespec/compiler": ">=0.49.0 <1.0.0",
"@typespec/http": ">=0.49.0 <1.0.0",
"@typespec/rest": ">=0.49.0 <1.0.0",
"@typespec/versioning": ">=0.49.0 <1.0.0",
"prettier": "2.7.1"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export async function _listWidgetsDeserialize(
return (result.body ?? []).map((p) => ({
id: p["id"],
weight: p["weight"],
color: p["color"],
color: p["color"] as any,
MaryGao marked this conversation as resolved.
Show resolved Hide resolved
}));
}

Expand Down Expand Up @@ -92,7 +92,7 @@ export async function _getWidgetDeserialize(
return {
id: result.body["id"],
weight: result.body["weight"],
color: result.body["color"],
color: result.body["color"] as any,
};
}

Expand Down Expand Up @@ -129,7 +129,7 @@ export async function _createWidgetDeserialize(
return {
id: result.body["id"],
weight: result.body["weight"],
color: result.body["color"],
color: result.body["color"] as any,
};
}

Expand Down Expand Up @@ -172,7 +172,7 @@ export async function _updateWidgetDeserialize(
return {
id: result.body["id"],
weight: result.body["weight"],
color: result.body["color"],
color: result.body["color"] as any,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export async function _listWidgetsDeserialize(
return (result.body ?? []).map((p) => ({
id: p["id"],
weight: p["weight"],
color: p["color"],
color: p["color"] as any,
}));
}

Expand Down Expand Up @@ -92,7 +92,7 @@ export async function _getWidgetDeserialize(
return {
id: result.body["id"],
weight: result.body["weight"],
color: result.body["color"],
color: result.body["color"] as any,
};
}

Expand Down Expand Up @@ -129,7 +129,7 @@ export async function _createWidgetDeserialize(
return {
id: result.body["id"],
weight: result.body["weight"],
color: result.body["color"],
color: result.body["color"] as any,
};
}

Expand Down Expand Up @@ -172,7 +172,7 @@ export async function _updateWidgetDeserialize(
return {
id: result.body["id"],
weight: result.body["weight"],
color: result.body["color"],
color: result.body["color"] as any,
};
}

Expand Down
18 changes: 9 additions & 9 deletions packages/typespec-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@
"ts-node": "^10.9.1",
"typescript": "~5.0.0",
"prettier": "~2.7.1",
"@azure-tools/cadl-ranch-specs": "^0.22.2",
"@azure-tools/cadl-ranch-expect": "^0.7.0",
"@azure-tools/cadl-ranch": "^0.8.2",
"@azure-tools/cadl-ranch-specs": "^0.24.0",
"@azure-tools/cadl-ranch-expect": "^0.8.0",
"@azure-tools/cadl-ranch": "^0.9.0",
"chalk": "^4.0.0",
"@azure-rest/core-client": "^1.1.4",
"@azure/core-auth": "^1.3.2",
Expand All @@ -67,12 +67,12 @@
"eslint-plugin-require-extensions": "0.1.3"
},
"peerDependencies": {
"@azure-tools/typespec-azure-core": ">=0.34.0 <1.0.0",
"@azure-tools/typespec-client-generator-core": "0.35.0-dev.9",
"@typespec/compiler": ">=0.48.0 <1.0.0",
"@typespec/http": ">=0.48.0 <1.0.0",
"@typespec/rest": ">=0.48.0 <1.0.0",
"@typespec/versioning": ">=0.48.0 <1.0.0"
"@azure-tools/typespec-azure-core": ">=0.35.0 <1.0.0",
"@azure-tools/typespec-client-generator-core": ">=0.35.0 <1.0.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we are using peerDependency, do we really need to change this version number here?

Copy link
Member Author

@MaryGao MaryGao Oct 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have the compatibility issue caused by tcgc which would fail to compile. So we have to upgrade to the latest.

Another point is we have to upgrade to the latest for new features.

"@typespec/compiler": ">=0.49.0 <1.0.0",
"@typespec/http": ">=0.49.0 <1.0.0",
"@typespec/rest": ">=0.49.0 <1.0.0",
"@typespec/versioning": ">=0.49.0 <1.0.0"
},
"dependencies": {
"prettier": "^2.6.1",
Expand Down
69 changes: 8 additions & 61 deletions packages/typespec-ts/src/transform/transformPaths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ import {
getParameterTypeName,
PathMetadata,
Paths,
ResponseTypes,
OperationMethod
} from "@azure-tools/rlc-common";
import { getDoc, ignoreDiagnostics, Program } from "@typespec/compiler";
import {
getHttpOperation,
HttpOperation,
HttpOperationParameters,
HttpOperationResponse
HttpOperationParameters
} from "@typespec/http";
import {
SdkClient,
Expand All @@ -25,12 +23,13 @@ import {
import { getSchemaForType } from "../utils/modelUtils.js";
import {
extractOperationLroDetail,
getOperationSuccessStatus,
getOperationGroupName,
getOperationName,
getOperationResponseTypes,
getOperationStatuscode,
isDefaultStatusCode,
isDefinedStatusCode,
isPagingOperation
isPagingOperation,
sortedOperationResponses
} from "../utils/operationUtil.js";
import { SdkContext } from "../utils/interfaces.js";

Expand Down Expand Up @@ -67,42 +66,6 @@ export function transformPaths(
return paths;
}

/**
* This function computes all the response types error and success
* an operation can end up returning.
*/
function getResponseTypes(
dpgContext: SdkContext,
operation: HttpOperation
): ResponseTypes {
const returnTypes: ResponseTypes = {
error: [],
success: []
};
function getResponseType(responses: HttpOperationResponse[]) {
return responses
.filter((r) => r.statusCode && r.statusCode.length)
.map((r) => {
const statusCode = getOperationStatuscode(r);
const responseName = getResponseTypeName(
getOperationGroupName(dpgContext, operation),
getOperationName(dpgContext.program, operation.operation),
statusCode
);
return responseName;
});
}
if (operation.responses && operation.responses.length) {
returnTypes.error = getResponseType(
operation.responses.filter((r) => isDefaultStatusCode(r.statusCode))
);
returnTypes.success = getResponseType(
operation.responses.filter((r) => isDefinedStatusCode(r.statusCode))
);
}
return returnTypes;
}

function transformOperation(
dpgContext: SdkContext,
route: HttpOperation,
Expand All @@ -111,15 +74,15 @@ function transformOperation(
const program = dpgContext.program;
const respNames = [];
const operationGroupName = getOperationGroupName(dpgContext, route);
for (const resp of route.responses) {
for (const resp of sortedOperationResponses(route.responses)) {
const respName = getResponseTypeName(
operationGroupName,
getOperationName(program, route.operation),
getOperationStatuscode(resp)
);
respNames.push(respName);
}
const responseTypes = getResponseTypes(dpgContext, route);
const responseTypes = getOperationResponseTypes(dpgContext, route);
const method: OperationMethod = {
description: getDoc(program, route.operation) ?? "",
hasOptionalOptions: !hasRequiredOptions(dpgContext, route.parameters),
Expand All @@ -129,7 +92,7 @@ function transformOperation(
),
responseTypes,
returnType: respNames.join(" | "),
successStatus: gerOperationSuccessStatus(route),
successStatus: getOperationSuccessStatus(route),
operationName: getOperationName(program, route.operation),
operationHelperDetail: {
lroDetails: extractOperationLroDetail(
Expand Down Expand Up @@ -191,19 +154,3 @@ function hasRequiredOptions(
.some((parameter) => parameter.param.optional === false);
return isRequiredBodyParam || containsRequiredNonBodyParam;
}

/**
* Extracts all success or defined status codes for a give operation
*/
export function gerOperationSuccessStatus(operation: HttpOperation): string[] {
const responses = operation.responses ?? [];
const status: string[] = [];

for (const response of responses) {
if (isDefinedStatusCode(response.statusCode)) {
status.push(response.statusCode);
}
}

return status;
}
5 changes: 3 additions & 2 deletions packages/typespec-ts/src/transform/transformResponses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ import {
getOperationStatuscode,
isBinaryPayload,
getOperationLroOverload,
getOperationName
getOperationName,
sortedOperationResponses
} from "../utils/operationUtil.js";
import { SdkContext } from "../utils/interfaces.js";

Expand Down Expand Up @@ -78,7 +79,7 @@ export function transformToResponseTypes(
path: route.path,
responses: []
};
for (const resp of route.responses) {
for (const resp of sortedOperationResponses(route.responses)) {
const statusCode = getOperationStatuscode(resp);
const rlcResponseUnit: ResponseMetadata = {
statusCode,
Expand Down
14 changes: 11 additions & 3 deletions packages/typespec-ts/src/utils/clientUtils.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
import { SdkClient } from "@azure-tools/typespec-client-generator-core";
import { Namespace, listServices } from "@typespec/compiler";
import {
Namespace,
getNamespaceFullName,
listServices
} from "@typespec/compiler";
import { SdkContext } from "./interfaces.js";

export function getRLCClients(dpgContext: SdkContext): SdkClient[] {
const services = listServices(dpgContext.program);

return services.map((service) => {
const clientName = service.type.name + "Client";
return {
kind: "SdkClient",
name: service.type.name + "Client",
name: clientName,
service: service.type,
type: service.type,
arm: isArm(service.type)
arm: isArm(service.type),
crossLanguageDefinitionId: `${getNamespaceFullName(
service.type
)}.${clientName}`
};
});
}
Expand Down
Loading
Loading