Azure / autorest.az

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

[Question] No Translations of Nested Arrays #799

Closed qwordy closed 3 years ago

qwordy commented 3 years ago

Why do you need this feature? There is No Translations of Nested Arrays. JSON is hard to use.

Is your feature request related to a problem? Please describe.

A snippet of request body

"secrets": [
            {
              "sourceVault": {
                "id": "/subscriptions/{subscription-id}/resourceGroups/ConstosoRG/providers/Microsoft.KeyVault/vaults/{keyvault-name}"
              },
              "vaultCertificates": [
                {
                  "certificateUrl": "https://{keyvault-name}.vault.azure.net:443/secrets/ContosoCertificate/{secret-id}"
                }
              ]
            }
          ]

Generated parameter definition for it

        c.argument('secrets', type=validate_file_or_dict, help='Specifies set of certificates that should be installed '
                   'onto the role instances. Expected value: json-string/@json-file.', arg_group='Os Profile')

I find that if the property has nested arrays, then autorest will define it as a string. Users need to pass the JSON string to it. It is super hard for users to input JSON string in terminal because " should be escaped in order to pass the " character. For example,

az cloud-service create --name "{cs-name}" --location "westus" --configuration "{ServiceConfiguration}" \
--extensions "[{\\"name\\":\\"RDPExtension\\",\\"properties\\":{\\"type\\":\\"RDP\\",\\"autoUpgradeMinorVersion\\":fals\
e,\\"protectedSettings\\":\\"<PrivateConfig><Password>{password}</Password></PrivateConfig>\\",\\"publisher\\":\\"Micro\
soft.Windows.Azure.Extensions\\",\\"settings\\":\\"<PublicConfig><UserName>UserAzure</UserName><Expiration>10/22/2021 \
15:05:45</Expiration></PublicConfig>\\",\\"typeHandlerVersion\\":\\"1.2.1\\"}}]" --load-balancer-configurations \
"[{\\"name\\":\\"contosolb\\",\\"properties\\":{\\"frontendIPConfigurations\\":[{\\"name\\":\\"contosofe\\",\\"properti\
es\\":{\\"publicIPAddress\\":{\\"id\\":\\"/subscriptions/{subscription-id}/resourceGroups/ConstosoRG/providers/Microsof\
t.Network/publicIPAddresses/contosopublicip\\"}}}]}}]" --package-url "{PackageUrl}" --roles \
"[{\\"name\\":\\"ContosoFrontend\\",\\"sku\\":{\\"name\\":\\"Standard_D1_v2\\",\\"capacity\\":1,\\"tier\\":\\"Standard\
\\"}}]" --upgrade-mode "Auto" --resource-group "ConstosoRG"

What is the best practice for this kind of property when using autorest?

Describe the solution you'd like

It is an open question.

Describe alternatives you've considered

Additional context

jsntcy commented 3 years ago

dup: https://github.com/Azure/autorest.az/issues/632 https://github.com/Azure/autorest.az/issues/806

changlong-liu commented 3 years ago

dup with #806