Skip to content

Commit

Permalink
proper sequence of options hack
Browse files Browse the repository at this point in the history
  • Loading branch information
Zim Kalinowski committed Nov 3, 2019
1 parent 3b6e2e8 commit a615150
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 6 deletions.
2 changes: 2 additions & 0 deletions AzureCli/CodeModelCli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions Common/MapFlattener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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)
Expand Down
22 changes: 22 additions & 0 deletions Common/MapGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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");
Expand Down
1 change: 1 addition & 0 deletions dist/AzureCli/CodeModelCli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 5 additions & 3 deletions dist/Common/MapFlattener.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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") {
Expand Down
15 changes: 15 additions & 0 deletions dist/Common/MapGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a615150

Please sign in to comment.