Skip to content

Commit

Permalink
Update the compiler version to v0.49 (#2061)
Browse files Browse the repository at this point in the history
* Update the compiler version to v0.49

* temp file

* Sorted the responses and handle status code range

* Regenerate after sorted

* Remove the internal test cases

* Update the latest special words spec

* Update the uts

* Update the constructor case

* update the config

* Update the comments
  • Loading branch information
MaryGao authored Oct 21, 2023
1 parent a1e0eab commit 6699351
Show file tree
Hide file tree
Showing 27 changed files with 3,758 additions and 725 deletions.
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
342 changes: 158 additions & 184 deletions common/config/rush/pnpm-lock.yaml

Large diffs are not rendered by default.

19 changes: 9 additions & 10 deletions packages/typespec-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@
"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/openapi3": ">=0.48.0 <1.0.0",
"@typespec/prettier-plugin-typespec": ">=0.48.0 <1.0.0",
"@typespec/openapi": ">=0.49.0 <1.0.0",
"@azure-tools/typespec-autorest": ">=0.35.0 <1.0.0",
"@typespec/openapi3": ">=0.49.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,
}));
}

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.2.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",
"@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

0 comments on commit 6699351

Please sign in to comment.