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

perf(spec-parser): fix type b reference id not correct issue #11422

Merged
merged 2 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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
Loading