Azure / autorest.az

Azure CLI Code Generator
MIT License
22 stars 20 forks source link

Allow option to generate parameter names based on their json body path #868

Open hivyas opened 3 years ago

hivyas commented 3 years ago

Current behavior

This is how our video analyzer entity is defined:

"parameters": {
    "subscriptionId": "00000000-0000-0000-0000-000000000000",
    "resourceGroupName": "contoso",
    "accountName": "contosotv",
    "api-version": "2021-05-01-preview",
    "parameters": {
      "location": "South Central US",
      "tags": {
        "tag1": "value1",
        "tag2": "value2"
      },
      "properties": {
       "encryption": {
            "type": "CustomerKey",
            "keyVaultProperties": {
              "keyIdentifier": "https://keyvault.vault.azure.net/keys/userkeys/0000000000000000000000000000000",
              "currentKeyIdentifier": "https://keyvault.vault.azure.net/keys/userkeys/0000000000000000000000000000000"
            },
            "identity": {
              "userAssignedIdentity": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/id2"
            },
            "status": "enabled"
        },
        "storageAccounts": [
          {
            "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg/providers/Microsoft.Storage/storageAccounts/storage1",
            "identity": {
              "userAssignedIdentity": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/id2"
            }
          }
        ]
      },
      "identity": {
        "type": "UserAssigned",
        "userAssignedIdentities": {
          "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/id1": {},
          "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/id2": {},
          "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/id3": {}
        }
      }
    }
  }

And this is what the generated parameters look like: image

Issues with current behavior

Proposal for new generation option for parameter names

In order to combat these issues, we would like to propose a generation option that can define parameters using their fully qualified json path. To clarify, we are not asking for this to be the default mode during generation; rather have it be enabled through a flag.

What I mean by fully qualified json path:

And so on.. this naming structure would apply for every property. This will create more clear names and be less confusing to the user as to which group the parameters belong to. This will also avoid breaking changes if the order of the swagger changes.

It appears the capabilities for this feature does exist since currently if Autorest.Az comes across a repeated property name it will append the entity name (--video-analyzer-identity-type)