From 3d7fae9665718d57f3d31b188eb68f87b4357455 Mon Sep 17 00:00:00 2001 From: Qiaoqiao Zhang <55688292+qiaozha@users.noreply.github.com> Date: Sat, 9 May 2020 10:18:51 +0800 Subject: [PATCH] fix-issue-352 (#353) --- README.md | 2 +- src/plugins/azgenerator/CodeModelAzImpl.ts | 43 ++++++++++++++-------- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 528c2b284..08c97eeff 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ debug-output-folder: $(az-output-folder)/_az_debug use-extension: "@autorest/python": "5.0.0-preview.3" - "@autorest/clicommon": "0.4.7" + "@autorest/clicommon": "0.4.8" #"@autorest/python": "latest" cli: diff --git a/src/plugins/azgenerator/CodeModelAzImpl.ts b/src/plugins/azgenerator/CodeModelAzImpl.ts index 8165a45b8..e8b9663a2 100644 --- a/src/plugins/azgenerator/CodeModelAzImpl.ts +++ b/src/plugins/azgenerator/CodeModelAzImpl.ts @@ -84,30 +84,41 @@ export class CodeModelCliImpl implements CodeModelAz { } - private getOrder(op: string) { - if(op.indexOf(" ") > -1) { - op = op.split(" ")[1]; - } - let opOrder = ["list", "show", "create", "update", "delete"]; - let order = opOrder.indexOf(op.toLowerCase()) + 1; - if (order == 0) { - order = opOrder.length + 1; - } - return order; - } - private sortOperationByAzCommand() { for (let [idx, operationGroup] of this.codeModel.operationGroups.entries()) { - operationGroup.operations.sort((a, b) => { - let oa = this.getOrder(a.language['az']['name']) + "_" + a.language['az']['name'] + "_" + (100 - a.parameters.length); - let ob = this.getOrder(b.language['az']['name']) + "_" + b.language['az']['name'] + "_" + (100 - b.parameters.length); - return oa.localeCompare(ob); + operationGroup.operations.sort(function(a, b) { + function getOrder(op: string) { + if(op.indexOf(" ") > -1) { + op = op.split(" ").last; + } + let opOrder = ["list", "show", "create", "update", "delete"]; + let order = opOrder.indexOf(op.toLowerCase()) + 1; + if (order == 0) { + order = opOrder.length + 1; + } + return order; + } + let oa = getOrder(a.language['az']['name']); + let ob = getOrder(b.language['az']['name']); + if(oa < ob) { + return -1; + } else if(oa > ob) { + return 1; + } else { + let la = a.language['az']['name']; + let lb = b.language['az']['name']; + if(la != lb) { + return la.localeCompare(lb); + } + return a.parameters.length > b.parameters.length? -1: 1; + } }); this.codeModel.operationGroups[idx] = operationGroup; } } + public get RandomizeNames(): boolean { if (this.options?.['randomize-names']) return true; return false;