Skip to content

Commit

Permalink
perf(spec-parser): fix type b reference id not correct issue (#11422)
Browse files Browse the repository at this point in the history
Co-authored-by: rentu <rentu@microsoft.com>
  • Loading branch information
SLdragon and SLdragon authored Apr 22, 2024
1 parent 231f84d commit 46de1cf
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
1 change: 0 additions & 1 deletion packages/spec-parser/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export class ConstantString {
static readonly ImageType = "Image";
static readonly ContainerType = "Container";
static readonly RegistrationIdPostfix = "REGISTRATION_ID";
static readonly OAuthRegistrationIdPostFix = "OAUTH_REGISTRATION_ID";
static readonly ResponseCodeFor20X = [
"200",
"201",
Expand Down
19 changes: 10 additions & 9 deletions packages/spec-parser/src/manifestUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,11 @@ export class ManifestUpdater {
}

if (pluginAuthObj.type !== "None") {
pluginAuthObj.reference_id = `${Utils.getSafeRegistrationIdEnvName(
authInfo.name
)}_REGISTRATION_ID`;
const safeRegistrationIdName = Utils.getSafeRegistrationIdEnvName(
`${authInfo.name}_${ConstantString.RegistrationIdPostfix}`
);

pluginAuthObj.reference_id = `\${{${safeRegistrationIdName}}}`;
}
}

Expand Down Expand Up @@ -375,25 +377,24 @@ export class ManifestUpdater {

if (authInfo) {
const auth = authInfo.authScheme;
const safeRegistrationIdName = Utils.getSafeRegistrationIdEnvName(
`${authInfo.name}_${ConstantString.RegistrationIdPostfix}`
);
if (Utils.isAPIKeyAuth(auth) || Utils.isBearerTokenAuth(auth)) {
const safeApiSecretRegistrationId = Utils.getSafeRegistrationIdEnvName(
`${authInfo.name}_${ConstantString.RegistrationIdPostfix}`
);
(composeExtension as any).authorization = {
authType: "apiSecretServiceAuth",
apiSecretServiceAuthConfiguration: {
apiSecretRegistrationId: `\${{${safeApiSecretRegistrationId}}}`,
apiSecretRegistrationId: `\${{${safeRegistrationIdName}}}`,
},
};
} else if (Utils.isOAuthWithAuthCodeFlow(auth)) {
const safeOAuth2RegistrationId = Utils.getSafeRegistrationIdEnvName(
`${authInfo.name}_${ConstantString.OAuthRegistrationIdPostFix}`
);

(composeExtension as any).authorization = {
authType: "oAuth2.0",
oAuthConfiguration: {
oauthConfigurationId: `\${{${safeOAuth2RegistrationId}}}`,
oauthConfigurationId: `\${{${safeRegistrationIdName}}}`,
},
};

Expand Down
1 change: 0 additions & 1 deletion packages/spec-parser/src/validators/copilotValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
SpecValidationResult,
} from "../interfaces";
import { Validator } from "./validator";
import { Utils } from "../utils";

export class CopilotValidator extends Validator {
constructor(spec: OpenAPIV3.Document, options: ParseOptions) {
Expand Down
6 changes: 3 additions & 3 deletions packages/spec-parser/test/manifestUpdater.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ describe("updateManifestWithAiPlugin", () => {
type: "OpenApi",
auth: {
type: "OAuthPluginVault",
reference_id: "OAUTH_REGISTRATION_ID",
reference_id: "${{OAUTH_REGISTRATION_ID}}",
},
spec: {
url: "spec/outputSpec.yaml",
Expand Down Expand Up @@ -750,7 +750,7 @@ describe("updateManifestWithAiPlugin", () => {
type: "OpenApi",
auth: {
type: "ApiKeyPluginVault",
reference_id: "APIKEY_REGISTRATION_ID",
reference_id: "${{APIKEY_REGISTRATION_ID}}",
},
spec: {
url: "spec/outputSpec.yaml",
Expand Down Expand Up @@ -3700,7 +3700,7 @@ describe("manifestUpdater", () => {
authorization: {
authType: "oAuth2.0",
oAuthConfiguration: {
oauthConfigurationId: "${{OAUTH_AUTH_OAUTH_REGISTRATION_ID}}",
oauthConfigurationId: "${{OAUTH_AUTH_REGISTRATION_ID}}",
},
},
commands: [
Expand Down

0 comments on commit 46de1cf

Please sign in to comment.