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 to ts http runtime #2083

Merged
merged 47 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
1276523
Merge remote-tracking branch 'origin/main' into upgrade-to-ts-http-ru…
MaryGao Oct 26, 2023
09b83cb
Add the branded option and add utils to build imports details
MaryGao Oct 26, 2023
20a4f0a
Refactor code for the latest changes
MaryGao Oct 26, 2023
0b0dd87
Update the init functions
MaryGao Oct 26, 2023
5b4751f
Update the lint issue
MaryGao Oct 26, 2023
9a406cc
Update the repo for import
MaryGao Oct 26, 2023
824ff0f
Update the generated code in non-azure client
MaryGao Oct 26, 2023
945f4e7
Refactor the integration test file position
MaryGao Oct 26, 2023
60aaaf3
Update the scripts for generation
MaryGao Oct 26, 2023
c24ed86
refactor code
MaryGao Oct 27, 2023
72e9624
Update the logger changes
MaryGao Oct 27, 2023
cf54ebd
Merge branch 'main' into upgrade-to-ts-http-runtime
MaryGao Nov 2, 2023
bb8b24e
Update the logger dependency
MaryGao Nov 2, 2023
245e624
Fix the bug for ` addCredentials: false`
MaryGao Nov 3, 2023
b96103a
Update the rlc-generate-swaggers gen
MaryGao Nov 3, 2023
9a9ba45
Fix lint issue
MaryGao Nov 3, 2023
776f03e
update fixes
MaryGao Nov 3, 2023
d75f670
update fixes
MaryGao Nov 3, 2023
45bd67d
Update the config files
MaryGao Nov 3, 2023
d35ba18
Fix the dependency for @azure/core-util in non branded sdk
MaryGao Nov 3, 2023
67ff447
Disable eslint in non branded
MaryGao Nov 3, 2023
4c01378
Merge remote-tracking branch 'origin/main' into upgrade-to-ts-http-ru…
MaryGao Nov 6, 2023
2ee216e
Fix build issue
MaryGao Nov 6, 2023
b8557b9
Update the files
MaryGao Nov 6, 2023
a71720a
Enable smoke testing for non azure open ai
MaryGao Nov 6, 2023
f7b4270
Remove the OpenAI RLC
MaryGao Nov 6, 2023
cc0c6b6
Update the integration testing for non-branded
MaryGao Nov 6, 2023
108227e
Update the package name
MaryGao Nov 6, 2023
0d01c30
Update the package name
MaryGao Nov 6, 2023
0851c33
Update the OpenAI RLC to the latest
MaryGao Nov 7, 2023
5aa3c35
Revert the settings
MaryGao Nov 7, 2023
36e686a
Revert changes
MaryGao Nov 7, 2023
52213de
Revert changes
MaryGao Nov 7, 2023
3b60ab1
Refactor the codes
MaryGao Nov 7, 2023
bc591c4
Remove the microsoft copyright in non-branded sdk
MaryGao Nov 7, 2023
8ae42bd
Update the microsoft ones
MaryGao Nov 7, 2023
ce68bfe
Fix linter issues
MaryGao Nov 7, 2023
6643e6b
Fix specifier wrong issues
MaryGao Nov 7, 2023
649a339
Update the files
MaryGao Nov 7, 2023
4909e51
Update the files
MaryGao Nov 7, 2023
aa48d91
Remove useless config
MaryGao Nov 7, 2023
6dab365
Fix the ci issues
MaryGao Nov 7, 2023
9d53385
Merge remote-tracking branch 'origin/main' into upgrade-to-ts-http-ru…
MaryGao Nov 7, 2023
0c2ed2f
Update the core util dependencies
MaryGao Nov 7, 2023
7a1bb0f
Refactor the package json generation
MaryGao Nov 8, 2023
fcc89db
Update the testing code
MaryGao Nov 8, 2023
5b3ff24
Fix UT issues
MaryGao Nov 8, 2023
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
14 changes: 14 additions & 0 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/autorest.typescript/src/autorestSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export interface AutorestOptions {
dependencyInfo?: DependencyInfo;
lenientModelDeduplication?: boolean;
useLegacyLro?: boolean;
branded?: boolean;
}

let host: AutorestExtensionHost;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
import {
CodeModel,
ImplementationLocation,
ParameterLocation,
Protocol
ParameterLocation
} from "@autorest/codemodel";
import {
ImportKind,
RLCModel,
HelperFunctionDetails,
UrlInfo,
ApiVersionInfo,
extractPathApiVersion,
extractDefinedPosition
extractDefinedPosition,
buildRuntimeImports,
initInternalImports
} from "@azure-tools/rlc-common";
import { getAutorestOptions } from "../../autorestSession";
import { transformBaseUrl } from "../../transforms/urlTransforms";
Expand All @@ -38,7 +38,7 @@ import { transformRLCSampleData } from "../../generators/samples/rlcSampleGenera

export function transform(model: CodeModel): RLCModel {
const { srcPath } = getAutorestOptions();
const importDetails = new Map<ImportKind, Set<string>>();
const importDetails = initInternalImports();
const urlInfo = transformUrlInfo(model);
const rlcModel: RLCModel = {
libraryName: normalizeName(
Expand All @@ -50,11 +50,14 @@ export function transform(model: CodeModel): RLCModel {
options: transformOptions(model),
schemas: transformSchemas(model),
responses: transformResponseTypes(model, importDetails),
importSet: importDetails,
parameters: transformParameterTypes(model, importDetails),
helperDetails: transformHelperDetails(model),
urlInfo: transformUrlInfo(model),
apiVersionInfo: transformApiVersion(model, urlInfo)
apiVersionInfo: transformApiVersion(model, urlInfo),
importInfo: {
internalImports: importDetails,
runtimeImports: buildRuntimeImports()
}
};
rlcModel.sampleGroups = transformRLCSampleData(model, rlcModel);
return rlcModel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export function transformOptions(model: CodeModel): RLCOptions {
azureSdkForJs,
dependencyInfo,
productDocLink,
azureArm
azureArm,
branded
} = getAutorestOptions();
const options: RLCOptions = {};
options.includeShortcuts = rlcShortcut;
Expand All @@ -31,6 +32,7 @@ export function transformOptions(model: CodeModel): RLCOptions {
options.dependencyInfo = dependencyInfo;
options.productDocLink = productDocLink;
options.azureArm = azureArm;
options.branded = branded;
options.serviceInfo = {
title: model.info.title ?? model.language.default.name,
description: model.info.description
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import {
Request as M4OperationRequest
} from "@autorest/codemodel";
import {
ImportKind,
ObjectSchema,
OperationParameter,
ParameterBodyMetadata,
ParameterMetadata,
Schema
Schema,
Imports as InnerImports
} from "@azure-tools/rlc-common";
import { transformObject } from "./transformSchemas";
import { getLanguageMetadata } from "../../utils/languageHelpers";
Expand All @@ -28,7 +28,7 @@ import { getElementType, primitiveSchemaToType } from "../schemaHelpers";

export function transformParameterTypes(
model: CodeModel,
importDetails: Map<ImportKind, Set<string>>
importDetails: InnerImports
) {
const rlcParameters: OperationParameter[] = [];
let importedModels = new Set<string>();
Expand Down Expand Up @@ -81,9 +81,7 @@ export function transformParameterTypes(
}
rlcParameters.push(rlcParameter);
}
if (importedModels.size > 0) {
importDetails.set(ImportKind.ParameterInput, importedModels);
}
importDetails.parameter.importsSet = importedModels;
return rlcParameters;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import {
SchemaResponse
} from "@autorest/codemodel";
import {
ImportKind,
OperationResponse,
ResponseMetadata,
ResponseBodySchema,
ResponseHeaderSchema
ResponseHeaderSchema,
Imports as InnerImports
} from "@azure-tools/rlc-common";
import { getLanguageMetadata } from "../../utils/languageHelpers";
import { responseToSchemaResponse } from "../operationHelpers";
Expand All @@ -27,7 +27,7 @@ import { isSchemaResponse } from "../../utils/schemaHelpers";

export function transformResponseTypes(
model: CodeModel,
importDetails: Map<ImportKind, Set<string>>
importDetails: InnerImports
): OperationResponse[] {
const operations = getAllOperationRequests(model);
const rlcResponses: OperationResponse[] = [];
Expand All @@ -53,7 +53,7 @@ export function transformResponseTypes(
// transform body
let body = undefined;
if (isSchemaResponse(response) || (response as any).binary) {
body = transformBody(response, importedModels);
body = transformBody(response, importedModels);
}
const rlcResponseUnit: ResponseMetadata = {
statusCode: getStatusCode(schemaResponse),
Expand All @@ -65,9 +65,7 @@ export function transformResponseTypes(
}
rlcResponses.push(rlcOperationUnit);
}
if (importedModels.size > 0) {
importDetails.set(ImportKind.ResponseOutput, importedModels);
}
importDetails.response.importsSet = importedModels;
return rlcResponses;
}

Expand Down
8 changes: 7 additions & 1 deletion packages/autorest.typescript/src/utils/autorestOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export async function extractAutorestOptions(): Promise<AutorestOptions> {
const coreHttpCompatMode = await getCoreHttpCompatMode(host);
const azureSdkForJs = await getAzureSdkForJs(host);
const dependencyInfo = await getDependencyInfo(host);
const branded = await getBranded(host);

return {
azureArm,
Expand Down Expand Up @@ -75,7 +76,8 @@ export async function extractAutorestOptions(): Promise<AutorestOptions> {
productDocLink,
coreHttpCompatMode,
dependencyInfo,
useLegacyLro
useLegacyLro,
branded
};
}

Expand Down Expand Up @@ -335,6 +337,10 @@ async function getCoreHttpCompatMode(
return (await host.getValue("core-http-compat-mode")) || false;
}

async function getBranded(host: AutorestExtensionHost): Promise<boolean> {
return (await host.getValue("branded")) ?? true;
}

async function getDependencyInfo(
host: AutorestExtensionHost
): Promise<DependencyInfo | undefined> {
Expand Down
53 changes: 35 additions & 18 deletions packages/rlc-common/src/buildClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
getClientName,
getImportModuleName
} from "./helpers/nameConstructors.js";
import { getImportSpecifier } from "./helpers/importsUtil.js";

function getClientOptionsInterface(
clientName: string,
Expand Down Expand Up @@ -84,7 +85,8 @@ export function buildClient(model: RLCModel): File | undefined {
addCredentials,
credentialScopes,
credentialKeyHeaderName,
customHttpAuthHeaderName
customHttpAuthHeaderName,
branded
} = model.options;
const credentialTypes = credentialScopes ? ["TokenCredential"] : [];

Expand Down Expand Up @@ -160,19 +162,26 @@ export function buildClient(model: RLCModel): File | undefined {
clientFile.addImportDeclarations([
{
namedImports: ["getClient", "ClientOptions"],
moduleSpecifier: "@azure-rest/core-client"
},
{
namedImports: ["logger"],
moduleSpecifier: getImportModuleName(
{
cjsName: loggerPath,
esModulesName: `${loggerPath}.js`
},
model
moduleSpecifier: getImportSpecifier(
"restClient",
model.importInfo.runtimeImports
)
}
]);
if (branded !== false) {
clientFile.addImportDeclarations([
{
namedImports: ["logger"],
moduleSpecifier: getImportModuleName(
{
cjsName: loggerPath,
esModulesName: `${loggerPath}.js`
},
model
)
}
]);
}

if (
addCredentials &&
Expand All @@ -185,7 +194,10 @@ export function buildClient(model: RLCModel): File | undefined {
clientFile.addImportDeclarations([
{
namedImports: credentialTypes,
moduleSpecifier: "@azure/core-auth"
moduleSpecifier: getImportSpecifier(
"coreAuth",
model.importInfo.runtimeImports
)
}
]);
}
Expand Down Expand Up @@ -221,7 +233,8 @@ export function getClientFactoryBody(
if (!model.options || !model.options.packageDetails || !model.urlInfo) {
return "";
}
const { includeShortcuts, packageDetails } = model.options;
const { includeShortcuts, packageDetails, branded, addCredentials } =
model.options;
let clientPackageName =
packageDetails!.nameWithoutScope ?? packageDetails?.name ?? "";
const packageVersion = packageDetails.version;
Expand Down Expand Up @@ -308,9 +321,16 @@ export function getClientFactoryBody(
const apiKeyHeaderName = credentialKeyHeaderName
? `apiKeyHeaderName: options.credentials?.apiKeyHeaderName ?? "${credentialKeyHeaderName}",`
: "";
const loggerOptions =
branded !== false
? `,
loggingOptions: {
logger: options.loggingOptions?.logger ?? logger.info
}`
: "";

const credentialsOptions =
scopes || apiKeyHeaderName
(scopes || apiKeyHeaderName) && addCredentials
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Offline dicussed with @joheredi We may prefer to remove the option addCredentials from TypeSpec generation because TypeSpec could express no credential defined.

I will have a separated pr for this.

? `,
credentials: {
${scopes}
Expand All @@ -321,10 +341,7 @@ export function getClientFactoryBody(
...options,
userAgentOptions: {
userAgentPrefix
},
loggingOptions: {
logger: options.loggingOptions?.logger ?? logger.info
}${customHeaderOptions}${credentialsOptions}
}${loggerOptions}${customHeaderOptions}${credentialsOptions}
}`;

const getClient = `const client = getClient(
Expand Down
6 changes: 5 additions & 1 deletion packages/rlc-common/src/buildClientDefinitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
getClientName,
getImportModuleName
} from "./helpers/nameConstructors.js";
import { getImportSpecifier } from "./helpers/importsUtil.js";

export function buildClientDefinitions(model: RLCModel) {
const options = {
Expand Down Expand Up @@ -115,7 +116,10 @@ export function buildClientDefinitions(model: RLCModel) {
clientDefinitionsFile.addImportDeclarations([
{
namedImports: [...options.clientImports],
moduleSpecifier: "@azure-rest/core-client"
moduleSpecifier: getImportSpecifier(
"restClient",
model.importInfo.runtimeImports
)
}
]);

Expand Down
4 changes: 4 additions & 0 deletions packages/rlc-common/src/buildLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ export function buildLogger(model: RLCModel) {
if (!model.options) {
return undefined;
}
// Disable logger for non-branded packages
if (model.options.branded === false) {
lirenhe marked this conversation as resolved.
Show resolved Hide resolved
return undefined;
}
const project = new Project();
const { srcPath } = model;
const { packageDetails } = model.options;
Expand Down
Loading
Loading