report the key error when user is using action

This commit is contained in:
t-yuminghe 2020-10-19 19:38:00 +08:00
Родитель e394612004 3d04a77fde
Коммит 5e1357b92e
9 изменённых файлов: 134 добавлений и 67 удалений

Просмотреть файл

@ -9,7 +9,7 @@ import { CodeModel, Operation, OperationGroup, Parameter, ParameterLocation, Pro
import { values } from "@azure-tools/linq";
import { isArray, isNullOrUndefined } from "util";
import { Capitalize, deepCopy, MergeSort, parseResourceId, ToCamelCase, ToJsonString, ToSnakeCase, changeCamelToDash } from '../../utils/helper';
import { GenerationMode } from "../models";
import { EXCLUDED_PARAMS, GenerationMode } from "../models";
import { CodeModelAz, CommandExample, ExampleParam, MethodParam } from "./CodeModelAz";
import { azOptions, GenerateDefaultTestScenario, GenerateDefaultTestScenarioByDependency, PrintTestScenario, ResourcePool, ObjectStatus } from './templates/tests/ScenarioTool';
@ -266,10 +266,16 @@ export class CodeModelCliImpl implements CodeModelAz {
if (isNullOrUndefined(childParam.language['az']['alias'])) {
childParam.language['az']['alias'] = [];
}
if (typeof(child.language['cli']['alias']) == "string") {
if (typeof (child.language['cli']['alias']) == "string") {
if (EXCLUDED_PARAMS.indexOf(child.language['cli']['alias']) > -1) {
child.language['cli']['alias'] = 'gen_' + child.language['cli']['alias'];
}
childParam.language['az']['alias'].push(changeCamelToDash(child.language['cli']['alias']));
} else if (isArray(child.language['cli']['alias'])) {
for(let alias of child.language['cli']['alias']) {
for (let alias of child.language['cli']['alias']) {
if (EXCLUDED_PARAMS.indexOf(alias) > -1) {
alias = 'gen_' + alias;
}
childParam.language['az']['alias'].push(changeCamelToDash(alias));
}
}
@ -488,15 +494,15 @@ export class CodeModelCliImpl implements CodeModelAz {
return this.codeModel.info['extensionMode'];
}
public get CommandGroup_ExtensionMode(){
public get CommandGroup_ExtensionMode() {
return this.CommandGroup?.language?.['cli']?.['groupExtensionMode'];
}
public get Command_ExtensionMode(){
public get Command_ExtensionMode() {
return this.Command?.language?.['cli']?.['commandExtensionMode'];
}
public get MethodParameter_ExtensionMode(){
public get MethodParameter_ExtensionMode() {
return this.MethodParameter?.language?.['cli']?.['methodExtensionMode'];
}
@ -1123,6 +1129,9 @@ export class CodeModelCliImpl implements CodeModelAz {
}
public Parameter_MapsTo(param: Parameter = this.MethodParameter): string {
if (EXCLUDED_PARAMS.indexOf(param.language['az'].mapsto) > -1) {
param.language['az'].mapsto = 'gen_' + param.language['az'].mapsto;
}
return param.language['az'].mapsto;
}
@ -1523,7 +1532,7 @@ export class CodeModelCliImpl implements CodeModelAz {
parameter.language['az']['default-config-key'] = parameter.language['cli']['default-config-key'];
}
}
return parameter.language['az']['default-config-key'];
return parameter.language['az']['default-config-key'];
}
public Parameter_Description(param: Parameter = this.MethodParameter): string {
@ -2411,19 +2420,19 @@ export class CodeModelCliImpl implements CodeModelAz {
}
public get IsCliCore() {
return this.codeModel.language['az']?.['isCliCore']? true: false;
return this.codeModel.language['az']?.['isCliCore'] ? true : false;
}
public get SDK_NeedSDK() {
return this.codeModel.language['az']?.['sdkNeeded']? true: false;
return this.codeModel.language['az']?.['sdkNeeded'] ? true : false;
}
public get SDK_IsTrack1() {
return this.codeModel.language['az']?.['sdkTrack1']? true: false;
return this.codeModel.language['az']?.['sdkTrack1'] ? true : false;
}
public get SDK_NoFlatten() {
return this.codeModel.language['az']?.['sdkNoFlatten']? true: false;
return this.codeModel.language['az']?.['sdkNoFlatten'] ? true : false;
}
}

Просмотреть файл

@ -4,6 +4,7 @@ import { serialize, deserialize } from "@azure-tools/codegen";
import { values, items, length, Dictionary } from "@azure-tools/linq";
import { changeCamelToDash } from '../utils/helper';
import { isNullOrUndefined, isArray } from "util";
import { EXCLUDED_PARAMS } from "./models";
import { PassThrough } from "stream";
import { type } from "os";
@ -19,20 +20,20 @@ export class AzNamer {
httpProtocol = httpProtocol.toLowerCase();
let subOperationGroupName = "";
let ons: Array<string> = [];
if(operationNameOri.indexOf('#') > -1) {
if (operationNameOri.indexOf('#') > -1) {
ons = operationNameOri.split('#');
if(ons && ons.length == 2) {
if (ons && ons.length == 2) {
subOperationGroupName = changeCamelToDash(ons[1]);
operationName = ons[0].toLowerCase();
}
}
if(operationName.startsWith("create") && httpProtocol == "put") {
return subOperationGroupName == ""? "create": subOperationGroupName + " " + "create";
} else if(operationName == "update" && (httpProtocol == "put" || httpProtocol == "patch")) {
return subOperationGroupName == ""? "update": subOperationGroupName + " " + "update";
} else if(operationName == "get" && httpProtocol == "get") {
return subOperationGroupName == ""? "show": subOperationGroupName + " " + "show";
} else if(operationName.startsWith("list") && httpProtocol == "get") {
if (operationName.startsWith("create") && httpProtocol == "put") {
return subOperationGroupName == "" ? "create" : subOperationGroupName + " " + "create";
} else if (operationName == "update" && (httpProtocol == "put" || httpProtocol == "patch")) {
return subOperationGroupName == "" ? "update" : subOperationGroupName + " " + "update";
} else if (operationName == "get" && httpProtocol == "get") {
return subOperationGroupName == "" ? "show" : subOperationGroupName + " " + "show";
} else if (operationName.startsWith("list") && httpProtocol == "get") {
// for list scenarios like kusto, if there's list, listbyresourcegroup, listsku, listskubyresource
// we should divide it into two groups
// group list contains list and listbyresourcegroup
@ -42,16 +43,16 @@ export class AzNamer {
const regex = /^(?<list>List[a-zA-Z0-9]*)(?<by>By[A-Z].*)$/;
let groups = operationNameOri.match(regex);
let list = "list";
if(groups && groups.length > 2) {
if (groups && groups.length > 2) {
list = changeCamelToDash(groups[1]);
} else {
list = changeCamelToDash(operationNameOri);
}
return subOperationGroupName == ""? list: subOperationGroupName + " " + list;
} else if(operationName.startsWith("delete") && httpProtocol == "delete") {
return subOperationGroupName == ""? "delete": subOperationGroupName + " " + "delete";
return subOperationGroupName == "" ? list : subOperationGroupName + " " + list;
} else if (operationName.startsWith("delete") && httpProtocol == "delete") {
return subOperationGroupName == "" ? "delete" : subOperationGroupName + " " + "delete";
}
if(subOperationGroupName != "") {
if (subOperationGroupName != "") {
return subOperationGroupName + " " + changeCamelToDash(ons[0]);
}
return changeCamelToDash(operationNameOri);
@ -67,21 +68,21 @@ export class AzNamer {
getAzName(obj) {
if(obj.language['az']) {
if (obj.language['az']) {
return;
}
obj.language['az'] = new Language();
obj.language['az']['name'] = obj.language['cli']?.['name']? obj.language['cli']['name']: obj.language['python']['name'];
obj.language['az']['name'] = obj.language['cli']?.['name'] ? obj.language['cli']['name'] : obj.language['python']['name'];
obj.language['az']['name'] = changeCamelToDash(obj.language['az']['name']);
obj.language['az']['mapsto'] = obj.language['az']['name'].replace(/-/g, '_');
obj.language['az']['description'] = obj.language['cli']? obj.language['cli']['description']: obj.language['python']['description'];
if(!isNullOrUndefined(obj.language['cli']['id_part'])) {
obj.language['az']['description'] = obj.language['cli'] ? obj.language['cli']['description'] : obj.language['python']['description'];
if (!isNullOrUndefined(obj.language['cli']['id_part'])) {
obj.language['az']['id_part'] = obj.language['cli']['id_part'];
}
}
}
processGlobalParam() {
for(let para of values(this.codeModel.globalParameters)) {
for (let para of values(this.codeModel.globalParameters)) {
this.getAzName(para);
}
}
@ -96,39 +97,39 @@ export class AzNamer {
}
}
for(let dict of values(schemas.dictionaries)) {
for (let dict of values(schemas.dictionaries)) {
this.getAzName(dict);
this.getAzName(dict.elementType);
}
for(let enumn of values(schemas.choices)) {
for (let enumn of values(schemas.choices)) {
this.getAzName(enumn);
for(let item of values(enumn.choices)) {
for (let item of values(enumn.choices)) {
this.getAzName(item);
}
}
for(let enumn of values(schemas.sealedChoices)) {
for (let enumn of values(schemas.sealedChoices)) {
this.getAzName(enumn);
for(let item of values(enumn.choices)) {
for (let item of values(enumn.choices)) {
this.getAzName(item);
}
}
for(let arr of values(schemas.arrays)) {
for (let arr of values(schemas.arrays)) {
this.getAzName(arr);
this.getAzName(arr.elementType);
}
for(let cons of values(schemas.constants)) {
for (let cons of values(schemas.constants)) {
this.getAzName(cons);
}
for(let num of values(schemas.numbers)) {
for (let num of values(schemas.numbers)) {
this.getAzName(num);
}
for(let str of values(schemas.strings)) {
for (let str of values(schemas.strings)) {
this.getAzName(str);
}
}
@ -137,12 +138,12 @@ export class AzNamer {
let azSettings = await this.session.getValue('az');
let extensionName = azSettings['extensions'];
//console.error(extensionName);
if(extensionName == '' || extensionName == undefined) {
this.session.message({Channel:Channel.Error, Text:"probably missing readme.az.md possible settings are:\naz:\n extensions: managed-network\n namespace: azure.mgmt.managednetwork\n package-name: azure-mgmt-managednetwork\npython-sdk-output-folder: \"$(output-folder)/src/managed-network/azext_managed_network/vendored_sdks/managed-network\"\n"})
if (extensionName == '' || extensionName == undefined) {
this.session.message({ Channel: Channel.Error, Text: "probably missing readme.az.md possible settings are:\naz:\n extensions: managed-network\n namespace: azure.mgmt.managednetwork\n package-name: azure-mgmt-managednetwork\npython-sdk-output-folder: \"$(output-folder)/src/managed-network/azext_managed_network/vendored_sdks/managed-network\"\n" })
}
this.codeModel.operationGroups.forEach(operationGroup => {
let operationGroupName = "";
if(!isNullOrUndefined(operationGroup.language['cli'])) {
if (!isNullOrUndefined(operationGroup.language['cli'])) {
operationGroup.language['az'] = new Language();
operationGroup.language['az']['name'] = operationGroup.language['cli']['name'];
operationGroup.language['az']['description'] = operationGroup.language['cli']['description'];
@ -159,34 +160,40 @@ export class AzNamer {
}
operation.requests.forEach(request => {
let operationName = "";
if(!isNullOrUndefined(operation.language['cli'])) {
if (!isNullOrUndefined(operation.language['cli'])) {
operation.language['az'] = new Language();
let commandName = this.methodMap(operation.language['cli']['name'], request.protocol.http.method);
operation.language['az']['name'] = commandName;
if(commandName == "show") {
if (commandName == "show") {
operationGroup.language['az']['hasShowCommand'] = true;
}
operation.language['az']['description'] = operation.language['cli']['description'];
operationName = operationGroupName + " " + changeCamelToDash(operation.language['az']['name']);
operationName = operationGroupName + " " + changeCamelToDash(operation.language['az']['name']);
operation.language['az']['command'] = operationName;
if(commandName.indexOf(" ") > -1) {
if (commandName.indexOf(" ") > -1) {
operation.language['az']['subCommandGroup'] = operationGroupName + " " + commandName.split(' ')[0];
}
if(operation.language['az'].command.endsWith(' update') && !isNullOrUndefined(operation.extensions?.['cli-split-operation-original-operation'])) {
if (operation.language['az'].command.endsWith(' update') && !isNullOrUndefined(operation.extensions?.['cli-split-operation-original-operation'])) {
operation.language['az']['isSplitUpdate'] = true;
}
} else {
this.session.message({Channel:Channel.Warning, Text: "OperationGroup " + operationGroup.language.default.name + " operation " + operation.language.default.name + " doesn't have cli"});
this.session.message({ Channel: Channel.Warning, Text: "OperationGroup " + operationGroup.language.default.name + " operation " + operation.language.default.name + " doesn't have cli" });
}
operation.parameters.forEach(parameter => {
if(!isNullOrUndefined(parameter.language['cli'])) {
if (!isNullOrUndefined(parameter.language['cli'])) {
this.getAzName(parameter);
if (!isNullOrUndefined(parameter.language['cli']['alias'])) {
parameter.language['az']['alias'] = []
if (typeof(parameter.language['cli']['alias']) == "string") {
parameter.language['az']['alias'] = [];
if (typeof (parameter.language['cli']['alias']) == "string") {
if (EXCLUDED_PARAMS.indexOf(parameter.language['cli']['alias']) > -1) {
parameter.language['cli']['alias'] = 'gen_' + parameter.language['cli']['alias'];
}
parameter.language['az']['alias'].push(changeCamelToDash(parameter.language['cli']['alias']));
} else if (isArray(parameter.language['cli']['alias'])) {
for(let alias of parameter.language['cli']['alias']) {
for (let alias of parameter.language['cli']['alias']) {
if (EXCLUDED_PARAMS.indexOf(alias) > -1) {
alias = 'gen_' + alias;
}
parameter.language['az']['alias'].push(changeCamelToDash(alias));
}
}
@ -195,31 +202,43 @@ export class AzNamer {
if (isNullOrUndefined(parameter.language['az']['alias'])) {
parameter.language['az']['alias'] = []
}
if (typeof(parameter.schema.language['cli']['alias']) == "string") {
if (typeof (parameter.schema.language['cli']['alias']) == "string") {
if (EXCLUDED_PARAMS.indexOf(parameter.language['cli']['alias']) > -1) {
parameter.language['cli']['alias'] = 'gen_' + parameter.language['cli']['alias'];
}
parameter.language['az']['alias'].push(changeCamelToDash(parameter.schema.language['cli']['alias']));
} else if (isArray(parameter.schema.language['cli']['alias'])) {
for(let alias of parameter.schema.language['cli']['alias']) {
for (let alias of parameter.schema.language['cli']['alias']) {
if (EXCLUDED_PARAMS.indexOf(alias) > -1) {
alias = 'gen_' + alias;
}
parameter.language['az']['alias'].push(changeCamelToDash(alias));
}
}
}
if (!isNullOrUndefined(parameter.language['cli']['m4FlattenedFrom'])) {
for(let param of parameter.language['cli']['m4FlattenedFrom']) {
for (let param of parameter.language['cli']['m4FlattenedFrom']) {
this.getAzName(param);
}
}
}
});
if(request.parameters) {
if (request.parameters) {
request.parameters.forEach(parameter => {
if(!isNullOrUndefined(parameter.language['cli'])) {
if (!isNullOrUndefined(parameter.language['cli'])) {
this.getAzName(parameter);
if (!isNullOrUndefined(parameter.language['cli']['alias'])) {
parameter.language['az']['alias'] = []
if (typeof(parameter.language['cli']['alias']) == "string") {
if (typeof (parameter.language['cli']['alias']) == "string") {
if (EXCLUDED_PARAMS.indexOf(parameter.language['cli']['alias']) > -1) {
parameter.language['cli']['alias'] = 'gen_' + parameter.language['cli']['alias'];
}
parameter.language['az']['alias'].push(changeCamelToDash(parameter.language['cli']['alias']));
} else if (isArray(parameter.language['cli']['alias'])) {
for(let alias of parameter.language['cli']['alias']) {
for (let alias of parameter.language['cli']['alias']) {
if (EXCLUDED_PARAMS.indexOf(alias) > -1) {
alias = 'gen_' + alias;
}
parameter.language['az']['alias'].push(changeCamelToDash(alias));
}
}
@ -228,21 +247,27 @@ export class AzNamer {
if (isNullOrUndefined(parameter.language['az']['alias'])) {
parameter.language['az']['alias'] = []
}
if (typeof(parameter.schema.language['cli']['alias']) == "string") {
if (typeof (parameter.schema.language['cli']['alias']) == "string") {
if (EXCLUDED_PARAMS.indexOf(parameter.language['cli']['alias']) > -1) {
parameter.language['cli']['alias'] = 'gen_' + parameter.language['cli']['alias'];
}
parameter.language['az']['alias'].push(changeCamelToDash(parameter.schema.language['cli']['alias']));
} else if (isArray(parameter.schema.language['cli']['alias'])) {
for(let alias of parameter.schema.language['cli']['alias']) {
for (let alias of parameter.schema.language['cli']['alias']) {
if (EXCLUDED_PARAMS.indexOf(alias) > -1) {
alias = 'gen_' + alias;
}
parameter.language['az']['alias'].push(changeCamelToDash(alias));
}
}
}
if (!isNullOrUndefined(parameter.language['cli']['m4FlattenedFrom'])) {
for(let param of parameter.language['cli']['m4FlattenedFrom']) {
for (let param of parameter.language['cli']['m4FlattenedFrom']) {
this.getAzName(param);
}
}
}
});
});
}
});
@ -263,7 +288,7 @@ export class AzNamer {
foundGeneric = true;
if (isNullOrUndefined(parameter['flattened']) || !isNullOrUndefined(parameter.language['cli']?.['cli-flattened']) && !isNullOrUndefined(parameter['nameBaseParam']) && isNullOrUndefined(parameter['nameBaseParam']['flattened'])) {
operation.extensions['cli-split-operation-original-operation']['genericSetterParam'] = parameter;
}
}
m++;
while (m < request.parameters.length) {
let param = request.parameters[m];

Просмотреть файл

@ -36,6 +36,18 @@ export enum SystemType {
windows = "windows"
}
export let EXCLUDED_PARAMS = [
'self',
'raw',
'polling',
'custom_headers',
'operation_config',
'content_version',
'kwargs',
'client',
'no_wait'
];
export class PathConstants {
public static readonly generatedFolder: string = "generated";
public static readonly testFolder: string = "tests";

Просмотреть файл

@ -51,6 +51,13 @@
},
{
"$ref": "#/parameters/api-version"
},
{
"name": "customHeaders",
"in": "query",
"description": "Test the ability to rename ignoring attributes.",
"type": "string",
"required": false
}
],
"responses": {

Просмотреть файл

@ -31,6 +31,7 @@ def load_arguments(self, _):
with self.argument_context('datafactory list') as c:
c.argument('resource_group_name', resource_group_name_type)
c.argument('gen_custom_headers', type=str, help='Test the ability to rename ignoring attributes.')
with self.argument_context('datafactory show') as c:
c.argument('resource_group_name', resource_group_name_type)

Просмотреть файл

@ -15,10 +15,11 @@ from azure.cli.core.util import sdk_no_wait
def datafactory_list(client,
resource_group_name=None):
resource_group_name=None,
gen_custom_headers=None):
if resource_group_name:
return client.list_by_resource_group(resource_group_name=resource_group_name)
return client.list()
return client.list(custom_headers=gen_custom_headers)
def datafactory_show(client,

Просмотреть файл

@ -43,10 +43,13 @@ class FactoryOperations:
def list(
self,
custom_headers: Optional[str] = None,
**kwargs
) -> AsyncIterable["models.FactoryListResponse"]:
"""Lists factories under the specified subscription.
:param custom_headers: Test the ability to rename ignoring attributes.
:type custom_headers: str
:keyword callable cls: A custom type or function that will be passed the direct response
:return: An iterator like instance of either FactoryListResponse or the result of cls(response)
:rtype: ~azure.core.async_paging.AsyncItemPaged[~dfaz_management_client.models.FactoryListResponse]
@ -72,6 +75,8 @@ class FactoryOperations:
# Construct parameters
query_parameters = {} # type: Dict[str, Any]
query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str')
if custom_headers is not None:
query_parameters['customHeaders'] = self._serialize.query("custom_headers", custom_headers, 'str')
request = self._client.get(url, query_parameters, header_parameters)
else:

Просмотреть файл

@ -47,11 +47,14 @@ class FactoryOperations(object):
def list(
self,
custom_headers=None, # type: Optional[str]
**kwargs # type: Any
):
# type: (...) -> Iterable["models.FactoryListResponse"]
"""Lists factories under the specified subscription.
:param custom_headers: Test the ability to rename ignoring attributes.
:type custom_headers: str
:keyword callable cls: A custom type or function that will be passed the direct response
:return: An iterator like instance of either FactoryListResponse or the result of cls(response)
:rtype: ~azure.core.paging.ItemPaged[~dfaz_management_client.models.FactoryListResponse]
@ -77,6 +80,8 @@ class FactoryOperations(object):
# Construct parameters
query_parameters = {} # type: Dict[str, Any]
query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str')
if custom_headers is not None:
query_parameters['customHeaders'] = self._serialize.query("custom_headers", custom_headers, 'str')
request = self._client.get(url, query_parameters, header_parameters)
else:

Просмотреть файл

@ -87,6 +87,8 @@ az datafactory list
##### <a name="ParametersFactoriesList">Parameters</a>
|Option|Type|Description|Path (SDK)|Swagger name|
|------|----|-----------|----------|------------|
|**--gen-custom-headers**|string|Test the ability to rename ignoring attributes.|custom_headers|customHeaders|
#### <a name="FactoriesGet">Command `az datafactory show`</a>
##### <a name="ExamplesFactoriesGet">Example</a>