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

Enable the batch tsp & chat api tsp #2090

Merged
merged 23 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
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
5 changes: 4 additions & 1 deletion packages/autorest.typescript/src/utils/schemaHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,10 @@ export function getSecurityInfoFromModel(security: Security) {
const { addCredentials } = getAutorestOptions();
const credentialScopes: Set<string> = new Set<string>();
let credentialKeyHeaderName: string = "";
let hasOAuth2Defined = false;
for (const securitySchema of security.schemes) {
if (securitySchema.type === "OAuth2") {
hasOAuth2Defined = true;
(securitySchema as OAuth2SecurityScheme).scopes.forEach(scope => {
const scopes = scope.split(",");
for (const scope of scopes) {
Expand Down Expand Up @@ -273,7 +275,8 @@ export function getSecurityInfoFromModel(security: Security) {
}
return {
addCredentials: refinedAddCredentials,
credentialScopes: scopes,
credentialScopes:
!hasOAuth2Defined && scopes.length === 0 ? undefined : scopes,
credentialKeyHeaderName: credentialKeyHeaderName
};
}
14 changes: 5 additions & 9 deletions packages/rlc-common/src/buildClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ export function buildClient(model: RLCModel): File | undefined {
credentialKeyHeaderName,
customHttpAuthHeaderName
} = model.options;
const credentialTypes =
credentialScopes && credentialScopes.length > 0 ? ["TokenCredential"] : [];
const credentialTypes = credentialScopes ? ["TokenCredential"] : [];
MaryGao marked this conversation as resolved.
Show resolved Hide resolved

if (credentialKeyHeaderName || customHttpAuthHeaderName) {
credentialTypes.push("KeyCredential");
Expand Down Expand Up @@ -211,9 +210,7 @@ function isSecurityInfoDefined(
customHttpAuthHeaderName?: string
) {
return (
(credentialScopes && credentialScopes.length > 0) ||
credentialKeyHeaderName ||
customHttpAuthHeaderName
credentialScopes || credentialKeyHeaderName || customHttpAuthHeaderName
);
}

Expand Down Expand Up @@ -311,10 +308,9 @@ export function getClientFactoryBody(

const { credentialScopes, credentialKeyHeaderName } = model.options;

const scopesString =
credentialScopes && credentialScopes.length
? credentialScopes.map((cs) => `"${cs}"`).join(", ")
: "";
const scopesString = (credentialScopes ?? [])
.map((cs) => `"${cs}"`)
.join(", ");
const scopes = scopesString
? `scopes: options.credentials?.scopes ?? [${scopesString}],`
: "";
Expand Down
5 changes: 5 additions & 0 deletions packages/rlc-common/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ export interface RLCOptions {
batch?: any[];
packageDetails?: PackageDetails;
addCredentials?: boolean;
/** Three possiblie values:
* - undefined, no credentialScopes and relevant settings would be generated
* - [], which means we would generate TokenCredential but no credentialScopes and relevant settings
* - ["..."], which means we would generate credentialScopes and relevant settings with the given values
*/
Copy link
Contributor Author

@MaryGao MaryGao Oct 30, 2023

Choose a reason for hiding this comment

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

Now we handle the undefined and empty array as different cases.

undefined means we don't have OAuth2 defined;

[] means we have OAuth2 defined but with empty scopes.

Previously we treat the above two cases the same so all of them will not generate TokenCredential in constructor. But now they are different. The first would not but the latter would generate.

Please notice that we will not set the credentialScopes default value as []. If the value is absent the core would populate with {endpoint}/.default automatically.

Copy link
Member

Choose a reason for hiding this comment

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

This is another place where we should consider if we are generating an Azure SDK or not since the {endpoint}/.default value only makes sense for Azure services.

Copy link
Contributor Author

@MaryGao MaryGao Oct 31, 2023

Choose a reason for hiding this comment

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

Haha, there may be another question - how to handle the empty scopes for non-Azure? How about explicitly set this as an empty array? Do we need to change the default logic for in @typespec/ts-http-runtime?

credentialScopes: []

But I think this topic would not block current pr considering we have a on-going one for integration #2083.

credentialScopes?: string[];
credentialKeyHeaderName?: string;
customHttpAuthHeaderName?: string;
Expand Down
4 changes: 1 addition & 3 deletions packages/rlc-common/src/transformSampleGroups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,7 @@ function convertClientLevelParameters(
model.options;
const hasUrlParameter = !!urlParameters,
hasCredentials =
addCredentials &&
((credentialScopes && credentialScopes.length > 0) ||
credentialKeyHeaderName);
addCredentials && (credentialScopes || credentialKeyHeaderName);

if (hasUrlParameter) {
// convert the host parameters in url
Expand Down
Loading
Loading