Skip to content

Commit

Permalink
perf(spec-parser): add namespace for plugin.json (#11377)
Browse files Browse the repository at this point in the history
* perf(spec-parser): add namespace for plugin.json

* perf: update schema version to 2.1

* perf: update test case

---------

Co-authored-by: rentu <rentu@microsoft.com>
  • Loading branch information
SLdragon and SLdragon authored Apr 16, 2024
1 parent 46b2d03 commit 587bbb4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 17 deletions.
11 changes: 10 additions & 1 deletion packages/spec-parser/src/manifestUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,10 @@ export class ManifestUpdater {
apiPlugin = await fs.readJSON(apiPluginFilePath);
} else {
apiPlugin = {
schema_version: "v2",
schema_version: "v2.1",
name_for_human: "",
description_for_human: "",
namespace: "",
functions: [],
runtimes: [],
};
Expand Down Expand Up @@ -249,6 +250,10 @@ export class ManifestUpdater {
apiPlugin.name_for_human = appName;
}

if (!apiPlugin.namespace) {
apiPlugin.namespace = ManifestUpdater.removeAllSpecialCharacters(appName);
}

if (!apiPlugin.description_for_human) {
apiPlugin.description_for_human =
spec.info.description ?? "<Please add description of the plugin>";
Expand Down Expand Up @@ -417,4 +422,8 @@ export class ManifestUpdater {
}
return newStr;
}

static removeAllSpecialCharacters(str: string): string {
return str.toLowerCase().replace(/[^a-z0-9]/g, "");
}
}
45 changes: 29 additions & 16 deletions packages/spec-parser/test/manifestUpdater.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ describe("updateManifestWithAiPlugin", () => {
};

const expectedPlugins: PluginManifestSchema = {
schema_version: "v2",
schema_version: "v2.1",
name_for_human: "Original Name",
namespace: "originalname",
description_for_human: "My API description",
functions: [
{
Expand Down Expand Up @@ -221,8 +222,9 @@ describe("updateManifestWithAiPlugin", () => {
};

const expectedPlugins: PluginManifestSchema = {
schema_version: "v2",
schema_version: "v2.1",
name_for_human: "Original Name",
namespace: "originalname",
description_for_human: "My API description",
functions: [
{
Expand Down Expand Up @@ -388,8 +390,9 @@ describe("updateManifestWithAiPlugin", () => {
};

const expectedPlugins: PluginManifestSchema = {
schema_version: "v2",
schema_version: "v2.1",
name_for_human: "Original Name",
namespace: "originalname",
description_for_human: "My API description",
functions: [
{
Expand Down Expand Up @@ -527,8 +530,9 @@ describe("updateManifestWithAiPlugin", () => {
};

const expectedPlugins: PluginManifestSchema = {
schema_version: "v2",
schema_version: "v2.1",
name_for_human: "Original Name",
namespace: "originalname",
description_for_human: "<Please add description of the plugin>",
functions: [
{
Expand Down Expand Up @@ -668,8 +672,9 @@ describe("updateManifestWithAiPlugin", () => {
};

const expectedPlugins: PluginManifestSchema = {
schema_version: "v2",
schema_version: "v2.1",
name_for_human: "Original Name",
namespace: "originalname",
description_for_human: "<Please add description of the plugin>",
capabilities: {
conversation_starters: [
Expand Down Expand Up @@ -817,8 +822,9 @@ describe("updateManifestWithAiPlugin", () => {
};

const expectedPlugins: PluginManifestSchema = {
schema_version: "v2",
schema_version: "v2.1",
name_for_human: "Original Name",
namespace: "originalname",
description_for_human: "<Please add description of the plugin>",
capabilities: {
conversation_starters: [
Expand Down Expand Up @@ -884,7 +890,7 @@ describe("updateManifestWithAiPlugin", () => {
.resolves(originalManifest)
.withArgs(pluginFilePath)
.resolves({
schema_version: "v2",
schema_version: "v2.1",
name_for_human: "",
description_for_human: "",
capabilities: {
Expand Down Expand Up @@ -988,8 +994,9 @@ describe("updateManifestWithAiPlugin", () => {
};

const expectedPlugins: PluginManifestSchema = {
schema_version: "v2",
schema_version: "v2.1",
name_for_human: "Original Name",
namespace: "originalname",
description_for_human: "My API description",
functions: [
{
Expand Down Expand Up @@ -1084,7 +1091,7 @@ describe("updateManifestWithAiPlugin", () => {
.resolves(originalManifest)
.withArgs(pluginFilePath)
.resolves({
schema_version: "v2",
schema_version: "v2.1",
name_for_human: "",
description_for_human: "",
functions: [
Expand Down Expand Up @@ -1219,8 +1226,9 @@ describe("updateManifestWithAiPlugin", () => {
};

const expectedPlugins: PluginManifestSchema = {
schema_version: "v2",
schema_version: "v2.1",
name_for_human: "exist_name",
namespace: "existnamespace",
description_for_human: "exist_description",
functions: [
{
Expand Down Expand Up @@ -1277,8 +1285,9 @@ describe("updateManifestWithAiPlugin", () => {
.resolves(originalManifest)
.withArgs(pluginFilePath)
.resolves({
schema_version: "v2",
schema_version: "v2.1",
name_for_human: "exist_name",
namespace: "existnamespace",
description_for_human: "exist_description",
});

Expand Down Expand Up @@ -1370,8 +1379,9 @@ describe("updateManifestWithAiPlugin", () => {
};

const expectedPlugins: PluginManifestSchema = {
schema_version: "v2",
schema_version: "v2.1",
name_for_human: "Original Name",
namespace: "originalname",
description_for_human: "My API description",
functions: [
{
Expand Down Expand Up @@ -1428,7 +1438,7 @@ describe("updateManifestWithAiPlugin", () => {
.resolves(originalManifest)
.withArgs(pluginFilePath)
.resolves({
schema_version: "v2",
schema_version: "v2.1",
name_for_human: "",
description_for_human: "",
functions: [
Expand Down Expand Up @@ -1572,8 +1582,9 @@ describe("updateManifestWithAiPlugin", () => {
};

const expectedPlugins: PluginManifestSchema = {
schema_version: "v2",
schema_version: "v2.1",
name_for_human: "Original Name",
namespace: "originalname",
description_for_human: "My API description",
functions: [
{
Expand Down Expand Up @@ -1719,8 +1730,9 @@ describe("updateManifestWithAiPlugin", () => {
};

const expectedPlugins: PluginManifestSchema = {
schema_version: "v2",
schema_version: "v2.1",
name_for_human: "Original Name",
namespace: "originalname",
description_for_human: "My API description",
functions: [
{
Expand Down Expand Up @@ -1826,8 +1838,9 @@ describe("updateManifestWithAiPlugin", () => {
};

const expectedPlugins: PluginManifestSchema = {
schema_version: "v2",
schema_version: "v2.1",
name_for_human: "Original Name",
namespace: "originalname",
description_for_human: "My API description",
functions: [],
runtimes: [
Expand Down

0 comments on commit 587bbb4

Please sign in to comment.