diff --git a/CHANGELOG.md b/CHANGELOG.md index 4dcf248d0..39e90632e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to the Imperative package will be documented in this file. +## Recent Changes + +- Enhancement: Added `inSchema` property for ProfileInfo to indicate if argument is a known schema argument [#899](https://github.com/zowe/imperative/issues/899) + ## `5.16.0` - Enhancement: Handled unique cookie identifier in the form of dynamic token types. [#966](https://github.com/zowe/imperative/pull/996) diff --git a/packages/config/__tests__/ProfileInfo.TeamConfig.test.ts b/packages/config/__tests__/ProfileInfo.TeamConfig.test.ts index bbb33f7b5..cd05cc12a 100644 --- a/packages/config/__tests__/ProfileInfo.TeamConfig.test.ts +++ b/packages/config/__tests__/ProfileInfo.TeamConfig.test.ts @@ -308,20 +308,20 @@ describe("TeamConfig ProfileInfo tests", () => { describe("getAllProfiles", () => { it("should return all profiles if no type is specified", async () => { - const length = 7; const expectedDefaultProfiles = 4; const expectedDefaultProfileNameZosmf = "LPAR1"; const expectedDefaultProfileNameTso = "LPAR1.tsoProfName"; const expectedDefaultProfileNameBase = "base_glob"; const expectedDefaultProfileNameDummy = "LPAR4"; let actualDefaultProfiles = 0; - let expectedProfileNames = ["LPAR1", "LPAR2", "LPAR3", "LPAR1.tsoProfName", "LPAR1.tsoProfName.tsoSubProfName", "base_glob", "LPAR4"]; + let expectedProfileNames = ["LPAR1", "LPAR2", "LPAR3", "LPAR1.tsoProfName", "LPAR1.tsoProfName.tsoSubProfName", + "base_glob", "LPAR4", "LPAR5"]; const profInfo = createNewProfInfo(teamProjDir); await profInfo.readProfilesFromDisk(); const profAttrs = profInfo.getAllProfiles(); - expect(profAttrs.length).toEqual(length); + expect(profAttrs.length).toEqual(expectedProfileNames.length); for (const prof of profAttrs) { if (prof.isDefaultProfile) { let expectedName = ""; @@ -355,7 +355,7 @@ describe("TeamConfig ProfileInfo tests", () => { const desiredProfType = "zosmf"; const expectedName = "LPAR1"; const expectedDefaultProfiles = 1; - let expectedProfileNames = ["LPAR1", "LPAR2", "LPAR3", "LPAR2_home"]; + let expectedProfileNames = ["LPAR1", "LPAR2", "LPAR3", "LPAR2_home", "LPAR5"]; let actualDefaultProfiles = 0; const profInfo = createNewProfInfo(teamProjDir); @@ -389,7 +389,7 @@ describe("TeamConfig ProfileInfo tests", () => { const desiredProfType = "zosmf"; const expectedName = "LPAR1"; const expectedDefaultProfiles = 1; - let expectedProfileNames = ["LPAR1", "LPAR2", "LPAR3"]; + let expectedProfileNames = ["LPAR1", "LPAR2", "LPAR3", "LPAR5"]; let actualDefaultProfiles = 0; const profInfo = createNewProfInfo(teamProjDir); @@ -753,6 +753,28 @@ describe("TeamConfig ProfileInfo tests", () => { } }); + it("should find correct inSchema args", async () => { + const profInfo = createNewProfInfo(teamProjDir); + await profInfo.readProfilesFromDisk(); + const profAttrs = profInfo.getAllProfiles()[7] as IProfAttrs; + const mergedArgs = profInfo.mergeArgsForProfile(profAttrs); + + const expectedArgs = [ + { argName: "host", inSchema: true }, + { argName: "port", inSchema: true }, + { argName: "responseFormatHeader", inSchema: false }, + { argName: "fakeOffSchemaArg", inSchema: false }, + { argName: "user", inSchema: true }, + { argName: "password", inSchema: true }, + { argName: "rejectUnauthorized", inSchema: true }, + ]; + + expect(mergedArgs.knownArgs.length).toBe(expectedArgs.length); + for (const [idx, arg] of mergedArgs.knownArgs.entries()) { + expect(arg.inSchema).toEqual(expectedArgs[idx].inSchema); + } + }); + it("should throw if schema fails to load", async () => { const profInfo = createNewProfInfo(teamProjDir); await profInfo.readProfilesFromDisk(); diff --git a/packages/config/__tests__/__resources__/ProfInfoApp_team_config_proj/ProfInfoApp.config.json b/packages/config/__tests__/__resources__/ProfInfoApp_team_config_proj/ProfInfoApp.config.json index 9d85bf752..9eea51ef1 100644 --- a/packages/config/__tests__/__resources__/ProfInfoApp_team_config_proj/ProfInfoApp.config.json +++ b/packages/config/__tests__/__resources__/ProfInfoApp_team_config_proj/ProfInfoApp.config.json @@ -60,6 +60,15 @@ "host": "LPAR4.your.domain.net", "responseFormatHeader": true } + }, + "LPAR5": { + "type": "zosmf", + "properties": { + "host": "LPAR4.your.domain.net", + "port": 1234, + "responseFormatHeader": true, + "fakeOffSchemaArg": "fakeArg" + } } }, "defaults": { diff --git a/packages/config/src/ProfileInfo.ts b/packages/config/src/ProfileInfo.ts index e85ad1038..0e1f3a197 100644 --- a/packages/config/src/ProfileInfo.ts +++ b/packages/config/src/ProfileInfo.ts @@ -623,7 +623,8 @@ export class ProfileInfo { dataType: this.argDataType(typeof propVal), // TODO Is using `typeof` bad for "null" values that may be int or bool? argValue: propVal, argLoc, - secure + secure, + inSchema: false }); } } @@ -654,7 +655,8 @@ export class ProfileInfo { dataType: this.argDataType(typeof propVal), argValue: propVal, argLoc, - secure + secure, + inSchema: false }); } } @@ -746,6 +748,7 @@ export class ProfileInfo { dataType: this.argDataType(propInfoInSchema.type), argValue: (propInfoInSchema as ICommandProfileProperty).optionDefinition?.defaultValue, argLoc, + inSchema: true, // See https://github.com/zowe/imperative/issues/739 secure: foundInSecureArray || propInfoInSchema.secure }; @@ -760,6 +763,7 @@ export class ProfileInfo { if (!argFound) { mergedArgs.missingArgs.push({ argName: propName, + inSchema: true, dataType: this.argDataType(propInfoInSchema.type), argValue: (propInfoInSchema as ICommandProfileProperty).optionDefinition?.defaultValue, argLoc: { locType: ProfLocType.DEFAULT }, @@ -767,6 +771,7 @@ export class ProfileInfo { }); } } else { + knownArg.inSchema = true; knownArg.secure = knownArg.secure ?? propInfoInSchema.secure; if (knownArg.secure) { delete knownArg.argValue; diff --git a/packages/config/src/doc/IProfArgAttrs.ts b/packages/config/src/doc/IProfArgAttrs.ts index f227b2bed..70c80512a 100644 --- a/packages/config/src/doc/IProfArgAttrs.ts +++ b/packages/config/src/doc/IProfArgAttrs.ts @@ -35,4 +35,7 @@ export interface IProfArgAttrs { /** Whether the argument value is stored securely */ secure?: boolean; + + /** Whether the argument value is defined in the schema file */ + inSchema?: boolean; }