Azure / autorest.cli

Autorest plugin to Azure CLI command modules and other tooling
MIT License
8 stars 12 forks source link

[MM] Generated go-enum values cannot contains hyphens or underscores #54

Open ArcturusZhang opened 5 years ago

ArcturusZhang commented 5 years ago

I am generating api.yaml file using autorest.cli with input file: azure-rest-api-specs\specification\compute\resource-manager\readme.md

Tag in use

package-2019-07.

Cli section added in readme.md

cli:
  cli-name: compute
  azure-arm: true
  license-header: MICROSOFT_MIT_NO_VERSION
  payload-flattening-threshold: 2
  namespace: azure.mgmt.compute
  package-name: azure-mgmt-compute
  clear-output-folder: false
  debug: true
  disable-azure-cli: true

Problem encountered

In the generated magic-module-input files computevirtualmachine, the generated values of go enum variable can contain hyphens or underscores or both. Golang will give warnings about snake cased variable names, so in the generation of Go SDK, hyphens and underscores in enum variables will be removed. For instance, in the generated api.yaml, in the representation of an enum variable

- !ruby/object:Api::Type::Enum
  name: 'storageAccountType'
  description: 'Specifies the storage account type for the managed disk. NOTE: UltraSSD_LRS can only be used with data disks, it cannot be used with OS Disk.'
  required: false
  sample_value: Standard_LRS
  azure_sdk_references: ['/storageProfile/osDisk/managedDisk/storageAccountType', '/properties/storageProfile/osDisk/managedDisk/storageAccountType']
  values:
    - :Standard_LRS
    - :Premium_LRS
    - :StandardSSD_LRS
    - :UltraSSD_LRS
  default_value: :Standard_LRS

All these underscores should be removed. In the definition of vmSize, there are more enum variables contained hyphens and underscores.

- !ruby/object:Api::Type::Enum
  name: 'vmSize'
  description: 'Specifies the size of the virtual machine. For more information about virtual machine sizes, see [Sizes for virtual machines](https://docs.microsoft.com/azure/virtual-machines/virtual-machines-windows-sizes?toc=%2fazure%2fvirtual-machines%2fwindows%2ftoc.json). <br><br> The available VM sizes depend on region and availability set. For a list of available sizes use these APIs:  <br><br> [List all available virtual machine sizes in an availability set](https://docs.microsoft.com/rest/api/compute/availabilitysets/listavailablesizes) <br><br> [List all available virtual machine sizes in a region](https://docs.microsoft.com/rest/api/compute/virtualmachinesizes/list) <br><br> [List all available virtual machine sizes for resizing](https://docs.microsoft.com/rest/api/compute/virtualmachines/listavailablesizes)'
  required: false
  sample_value: Standard_D2_v2
  azure_sdk_references: ['/hardwareProfile/vmSize', '/properties/hardwareProfile/vmSize']
  values:
ArcturusZhang commented 5 years ago

It turns out that some enum values can contain comma even space, these non-character and non-numeric character need to be removed in api.yaml