From a615150859c3e65a29ba4e21183431bd92a8bd2f Mon Sep 17 00:00:00 2001 From: Zim Kalinowski Date: Mon, 4 Nov 2019 00:34:04 +0800 Subject: [PATCH] proper sequence of options hack --- AzureCli/CodeModelCli.ts | 2 ++ Common/MapFlattener.ts | 8 +++++--- Common/MapGenerator.ts | 22 ++++++++++++++++++++++ dist/AzureCli/CodeModelCli.js | 1 + dist/Common/MapFlattener.js | 8 +++++--- dist/Common/MapGenerator.js | 15 +++++++++++++++ 6 files changed, 50 insertions(+), 6 deletions(-) diff --git a/AzureCli/CodeModelCli.ts b/AzureCli/CodeModelCli.ts index 10f40c6..4491009 100644 --- a/AzureCli/CodeModelCli.ts +++ b/AzureCli/CodeModelCli.ts @@ -821,6 +821,8 @@ export class CodeModelCli { let optionName = methodOptionNames[optionNameIdx]; + this._log("OPTION NAME: " + optionName); + // this._log(" ---- CHECKING: " + optionName); let option = null; for (let optionIdx in this.ModuleOptions) diff --git a/Common/MapFlattener.ts b/Common/MapFlattener.ts index f5ca58e..8ac8989 100644 --- a/Common/MapFlattener.ts +++ b/Common/MapFlattener.ts @@ -43,7 +43,9 @@ export class MapFlattener { let option = options[i]; - if (option.Kind == ModuleOptionKind.MODULE_OPTION_PATH && option.NameAnsible.endsWith('_name')) + // OPTIONS ARE NOT SORTED CORRECTLY + // SO THERE'S option.NameAnsible != "resource_group_name" hack here + if (option.Kind == ModuleOptionKind.MODULE_OPTION_PATH && option.NameAnsible != "resource_group_name" && option.NameAnsible.endsWith('_name')) { option.NameAnsible = "name"; option.NameTerraform = "name"; @@ -55,8 +57,8 @@ export class MapFlattener } // if the option is already part of the resource URL and doesn't end with name, don't rename - if (option.IdPortion != null && option.IdPortion != "") - break; + //if (option.IdPortion != null && option.IdPortion != "") + // break; } for (let oi in options) diff --git a/Common/MapGenerator.ts b/Common/MapGenerator.ts index 4da6ff5..9eed98f 100644 --- a/Common/MapGenerator.ts +++ b/Common/MapGenerator.ts @@ -221,6 +221,7 @@ export class MapGenerator method.Url = NormalizeResourceId(rawMethod.url); method.HttpMethod = rawMethod.httpMethod.toLowerCase(); method.IsAsync = (rawMethod['extensions'] != undefined && rawMethod['extensions']['x-ms-long-running-operation'] != undefined) ? rawMethod['extensions']['x-ms-long-running-operation'] : false; + methods.push(method); } @@ -756,11 +757,32 @@ export class MapGenerator this._log(" MODULE: " + this.ModuleName + ", METHOD: " + methodName); this._log( " ... " + method.url); + // first just take option names from URL, as they need to be in that exact sequence + // and in the swagger definition they may be not + let parts: string[] = method.url.split("/"); + let position = 0; + parts.forEach(element => { + if (element.startsWith('{')) + { + let name: string = element.substr(1, element.length - 2); + if (name != "subscriptionId") + { + options.push(name); + } + } + }); + + if (method != null) { for (var pi in method.parameters) { let p = method.parameters[pi]; + + // path parameters are already added in first loop + if (p.location == "path") + continue; + if (p.name.raw != "subscriptionId" && p.name.raw != "api-version" && !p.name.raw.startsWith('$') && p.name.raw != "If-Match" && (p.isRequired == true || !required)) { this._log(" ... parameter: " + p.name.raw + " - INCLUDED"); diff --git a/dist/AzureCli/CodeModelCli.js b/dist/AzureCli/CodeModelCli.js index 0f80f9c..558170d 100644 --- a/dist/AzureCli/CodeModelCli.js +++ b/dist/AzureCli/CodeModelCli.js @@ -578,6 +578,7 @@ class CodeModelCli { let moduleOptions = []; for (let optionNameIdx in methodOptionNames) { let optionName = methodOptionNames[optionNameIdx]; + this._log("OPTION NAME: " + optionName); // this._log(" ---- CHECKING: " + optionName); let option = null; for (let optionIdx in this.ModuleOptions) { diff --git a/dist/Common/MapFlattener.js b/dist/Common/MapFlattener.js index b4e940e..a977535 100644 --- a/dist/Common/MapFlattener.js +++ b/dist/Common/MapFlattener.js @@ -27,7 +27,9 @@ class MapFlattener { ProcessTopLevelOptions(options) { for (let i = options.length - 1; i >= 0; i--) { let option = options[i]; - if (option.Kind == ModuleMap_1.ModuleOptionKind.MODULE_OPTION_PATH && option.NameAnsible.endsWith('_name')) { + // OPTIONS ARE NOT SORTED CORRECTLY + // SO THERE'S option.NameAnsible != "resource_group_name" hack here + if (option.Kind == ModuleMap_1.ModuleOptionKind.MODULE_OPTION_PATH && option.NameAnsible != "resource_group_name" && option.NameAnsible.endsWith('_name')) { option.NameAnsible = "name"; option.NameTerraform = "name"; break; @@ -36,8 +38,8 @@ class MapFlattener { this.ApplyOptionOverride(option); } // if the option is already part of the resource URL and doesn't end with name, don't rename - if (option.IdPortion != null && option.IdPortion != "") - break; + //if (option.IdPortion != null && option.IdPortion != "") + // break; } for (let oi in options) { if (options[oi].NameAnsible == "resource_group_name") { diff --git a/dist/Common/MapGenerator.js b/dist/Common/MapGenerator.js index bb443c6..ece881f 100644 --- a/dist/Common/MapGenerator.js +++ b/dist/Common/MapGenerator.js @@ -528,9 +528,24 @@ class MapGenerator { var method = this.ModuleFindMethod(methodName); this._log(" MODULE: " + this.ModuleName + ", METHOD: " + methodName); this._log(" ... " + method.url); + // first just take option names from URL, as they need to be in that exact sequence + // and in the swagger definition they may be not + let parts = method.url.split("/"); + let position = 0; + parts.forEach(element => { + if (element.startsWith('{')) { + let name = element.substr(1, element.length - 2); + if (name != "subscriptionId") { + options.push(name); + } + } + }); if (method != null) { for (var pi in method.parameters) { let p = method.parameters[pi]; + // path parameters are already added in first loop + if (p.location == "path") + continue; if (p.name.raw != "subscriptionId" && p.name.raw != "api-version" && !p.name.raw.startsWith('$') && p.name.raw != "If-Match" && (p.isRequired == true || !required)) { this._log(" ... parameter: " + p.name.raw + " - INCLUDED"); options.push(p.name.raw);