Skip to content

Commit

Permalink
refactor(spec-parser): generate command if optional parameters only (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
yuqizhou77 authored Sep 6, 2023
1 parent 8ebcf8a commit aa8d930
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
17 changes: 8 additions & 9 deletions packages/fx-core/src/common/spec-parser/manifestUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,6 @@ export async function generateCommands(

const adaptiveCardPath = path.join(adaptiveCardFolder, operationId + ".json");

if (parameters.length === 0) {
warnings.push({
type: WarningType.OperationOnlyContainsOptionalParam,
content: format(ConstantString.OperationOnlyContainsOptionalParam, operationId),
data: operationId,
});
continue;
}

const command: Command = {
context: ["compose"],
type: "query",
Expand All @@ -154,6 +145,14 @@ export async function generateCommands(
: "",
};
commands.push(command);

if (parameters.length === 0) {
warnings.push({
type: WarningType.OperationOnlyContainsOptionalParam,
content: format(ConstantString.OperationOnlyContainsOptionalParam, operationId),
data: operationId,
});
}
}
}
}
Expand Down
30 changes: 28 additions & 2 deletions packages/fx-core/tests/common/spec-parser/manifestUpdater.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,16 @@ describe("manifestUpdater", () => {
composeExtensions: [
{
apiSpecificationFile: "spec/outputSpec.yaml",
commands: [],
commands: [
{
apiResponseRenderingTemplateFile: "adaptiveCards/createPet.json",
context: ["compose"],
id: "createPet",
parameters: [],
title: "Create a pet",
type: "query",
},
],
composeExtensionType: "apiBased",
},
],
Expand Down Expand Up @@ -490,7 +499,24 @@ describe("generateCommands", () => {
sinon.stub(fs, "pathExists").resolves(true);

const [result, warnings] = await generateCommands(spec, adaptiveCardFolder, manifestPath);
expect(result).to.deep.equal([]);
expect(result).to.deep.equal([
{
apiResponseRenderingTemplateFile: "adaptiveCards/getPets.json",
context: ["compose"],
id: "getPets",
parameters: [],
title: "Get all pets",
type: "query",
},
{
apiResponseRenderingTemplateFile: "adaptiveCards/createPet.json",
context: ["compose"],
id: "createPet",
parameters: [],
title: "Create a pet",
type: "query",
},
]);
expect(warnings).to.deep.equal([
{
type: WarningType.OperationOnlyContainsOptionalParam,
Expand Down

0 comments on commit aa8d930

Please sign in to comment.