Skip to content

Commit

Permalink
perf(spec-parser): do not generate response_semantics when response i…
Browse files Browse the repository at this point in the history
…s empty (#11453)

* perf(spec-parser): do not generate response_semantics when response is empty

* perf: update test case

---------

Co-authored-by: rentu <rentu@microsoft.com>
  • Loading branch information
SLdragon and SLdragon authored Apr 24, 2024
1 parent 6f1aa09 commit 942bc0a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 43 deletions.
14 changes: 9 additions & 5 deletions packages/spec-parser/src/manifestUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,15 @@ export class ManifestUpdater {
}

if (options.allowResponseSemantics) {
const [card, jsonPath] = AdaptiveCardGenerator.generateAdaptiveCard(operationItem);
const responseSemantic = wrapResponseSemantics(card, jsonPath);
funcObj.capabilities = {
response_semantics: responseSemantic,
};
const { json } = Utils.getResponseJson(operationItem);
if (json.schema) {
const [card, jsonPath] =
AdaptiveCardGenerator.generateAdaptiveCard(operationItem);
const responseSemantic = wrapResponseSemantics(card, jsonPath);
funcObj.capabilities = {
response_semantics: responseSemantic,
};
}
}

if (options.allowConfirmation && method !== ConstantString.GetMethod) {
Expand Down
61 changes: 23 additions & 38 deletions packages/spec-parser/test/manifestUpdater.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe("updateManifestWithAiPlugin", () => {
});

describe("responseSemantics", () => {
it("should generate default response semantics", async () => {
it("should not generate response semantics when response is empty", async () => {
const spec: any = {
openapi: "3.0.2",
info: {
Expand Down Expand Up @@ -89,23 +89,6 @@ describe("updateManifestWithAiPlugin", () => {
},
required: ["limit"],
},
capabilities: {
response_semantics: {
data_path: "$",
static_template: {
$schema: "http://adaptivecards.io/schemas/adaptive-card.json",
body: [
{
text: "success",
type: "TextBlock",
wrap: true,
},
],
type: "AdaptiveCard",
version: "1.5",
},
},
},
},
],
runtimes: [
Expand Down Expand Up @@ -1167,6 +1150,22 @@ describe("updateManifestWithAiPlugin", () => {
},
},
},
responses: {
200: {
content: {
"application/json": {
schema: {
type: "object",
properties: {
name: {
type: "string",
},
},
},
},
},
},
},
},
},
},
Expand Down Expand Up @@ -1209,23 +1208,6 @@ describe("updateManifestWithAiPlugin", () => {
},
required: ["limit"],
},
capabilities: {
response_semantics: {
data_path: "$",
static_template: {
$schema: "http://adaptivecards.io/schemas/adaptive-card.json",
type: "AdaptiveCard",
version: "1.5",
body: [
{
type: "TextBlock",
text: "success",
wrap: true,
},
],
},
},
},
},
{
name: "createPet",
Expand All @@ -1248,17 +1230,20 @@ describe("updateManifestWithAiPlugin", () => {
},
response_semantics: {
data_path: "$",
properties: {
title: "$.name",
},
static_template: {
$schema: "http://adaptivecards.io/schemas/adaptive-card.json",
type: "AdaptiveCard",
version: "1.5",
body: [
{
text: "name: ${if(name, name, 'N/A')}",
type: "TextBlock",
text: "success",
wrap: true,
},
],
type: "AdaptiveCard",
version: "1.5",
},
},
},
Expand Down

0 comments on commit 942bc0a

Please sign in to comment.