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): optimize "None Auth", special media type, AC card gen #11946

Merged
merged 5 commits into from
Jul 4, 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
6 changes: 3 additions & 3 deletions packages/fx-core/resource/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,9 @@
"core.TabSPFxOption.detailNew": "Build UI with SharePoint Framework",
"core.TabNonSso.label": "Basic Tab",
"core.TabNonSso.detail": "A simple implementation of a web app that's ready to customize",
"core.copilotPlugin.api.noAuth": "None auth",
"core.copilotPlugin.api.apiKeyAuth": "API key auth(Bearer token auth)",
"core.copilotPlugin.api.oauth": "OAuth(Auth code flow)",
"core.copilotPlugin.api.noAuth": "No authentication",
"core.copilotPlugin.api.apiKeyAuth": "API Key authentication(Bearer token authentication)",
"core.copilotPlugin.api.oauth": "OAuth(Authorization code flow)",
"core.copilotPlugin.validate.apiSpec.summary": "Teams Toolkit has checked your OpenAPI description document:\n\nSummary:\n%s.\n%s\n%s",
"core.copilotPlugin.validate.summary.validate.failed": "%s failed",
"core.copilotPlugin.validate.summary.validate.warning": "%s warning",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ const V3Version = MetadataV3.projectVersion;
assert.isTrue(res.isErr() && res.error.name === "test");
});

it("create API Plugin with none auth (feature flag enabled)", async () => {
it("create API Plugin with No authentication (feature flag enabled)", async () => {
const v3ctx = createContext();
v3ctx.userInteraction = new MockedUserInteraction();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ describe("OpenAPISpecGenerator", function () {
assert.equal(downloadTemplate.args[0][2], "copilot-plugin-existing-api");
});

it("success with api key auth", async function () {
it("success with API Key authentication", async function () {
const inputs: Inputs = {
platform: Platform.VSCode,
projectPath: "path",
Expand Down
18 changes: 9 additions & 9 deletions packages/fx-core/tests/question/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ describe("scaffold question", () => {
]);
});

it("traverse in vscode me from new api (none auth)", async () => {
it("traverse in vscode me from new api (No authentication)", async () => {
const inputs: Inputs = {
platform: Platform.VSCode,
};
Expand Down Expand Up @@ -1580,7 +1580,7 @@ describe("scaffold question", () => {
]);
});

it("traverse in vscode Copilot Plugin from new API with api key auth", async () => {
it("traverse in vscode Copilot Plugin from new API with API Key authentication", async () => {
const inputs: Inputs = {
platform: Platform.VSCode,
};
Expand Down Expand Up @@ -2380,7 +2380,7 @@ describe("scaffold question", () => {
{
id: "get operation1",
label: "get operation1",
detail: "API key auth(Bearer token auth)",
detail: "API Key authentication(Bearer token authentication)",
groupName: "GET",
data: {
authName: "bearerAuth",
Expand All @@ -2391,7 +2391,7 @@ describe("scaffold question", () => {
{
id: "get operation2",
label: "get operation2",
detail: "None auth",
detail: "No authentication",
groupName: "GET",
data: {
serverUrl: "https://server2",
Expand All @@ -2400,7 +2400,7 @@ describe("scaffold question", () => {
{
id: "get operation3",
label: "get operation3",
detail: "OAuth(Auth code flow)",
detail: "OAuth(Authorization code flow)",
groupName: "GET",
data: {
serverUrl: "https://server",
Expand Down Expand Up @@ -2466,7 +2466,7 @@ describe("scaffold question", () => {
{
id: "get operation1",
label: "get operation1",
detail: "API key auth(Bearer token auth)",
detail: "API Key authentication(Bearer token authentication)",
groupName: "GET",
data: {
authName: "bearerAuth",
Expand All @@ -2477,7 +2477,7 @@ describe("scaffold question", () => {
{
id: "get operation2",
label: "get operation2",
detail: "None auth",
detail: "No authentication",
groupName: "GET",
data: {
serverUrl: "https://server2",
Expand Down Expand Up @@ -2673,7 +2673,7 @@ describe("scaffold question", () => {
{
id: "GET /store/order",
label: "GET /store/order",
detail: "None auth",
detail: "No authentication",
groupName: "GET",
data: {
serverUrl: "https://server2",
Expand Down Expand Up @@ -2795,7 +2795,7 @@ describe("scaffold question", () => {
serverUrl: "https://server",
},
groupName: "GET",
detail: "None auth",
detail: "No authentication",
id: "GET /user/{userId}",
label: "GET /user/{userId}",
},
Expand Down
33 changes: 20 additions & 13 deletions packages/spec-parser/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,21 @@ export class Utils {
for (const code of ConstantString.ResponseCodeFor20X) {
const responseObject = operationObject?.responses?.[code] as OpenAPIV3.ResponseObject;

if (responseObject?.content?.["application/json"]) {
multipleMediaType = false;
json = responseObject.content["application/json"];
if (Utils.containMultipleMediaTypes(responseObject)) {
multipleMediaType = true;
if (!allowMultipleMediaType) {
json = {};
if (responseObject?.content) {
for (const contentType of Object.keys(responseObject.content)) {
// json media type can also be "application/json; charset=utf-8"
if (contentType.indexOf("application/json") >= 0) {
multipleMediaType = false;
json = responseObject.content[contentType];
if (Utils.containMultipleMediaTypes(responseObject)) {
multipleMediaType = true;
if (!allowMultipleMediaType) {
json = {};
}
} else {
return { json, multipleMediaType };
}
}
} else {
break;
}
}
}
Expand Down Expand Up @@ -479,10 +484,12 @@ export class Utils {

currentCount += items.length;
} else {
if (currentCount < maxCount) {
result.push(element);
currentCount++;
}
result.push(element);
currentCount++;
}

if (currentCount >= maxCount) {
break;
}
}

Expand Down
Loading
Loading