Azure / autorest.powershell

AutoRest PowerShell Generator
MIT License
112 stars 80 forks source link

Parameter Capability is an array, enum is the items, value should be generated #1303

Closed JoyerJin closed 7 months ago

JoyerJin commented 8 months ago

Sphere stable vesion 2024-04-01 https://github.com/Azure/azure-rest-api-specs/blob/5ce42348a1344b3f00bc3b9256c946780f924001/specification/sphere/resource-manager/Microsoft.AzureSphere/stable/2024-04-01/azuresphere.json line 3768

    "GenerateCapabilityImageRequest": {
      "type": "object",
      "description": "Request of the action to create a signed device capability image",
      "properties": {
        "capabilities": {
          "type": "array",
          "description": "List of capabilities to create",
          "items": {
            "$ref": "#/definitions/CapabilityType"
          }
        }
      },
      "required": [
        "capabilities"
      ]
    }
line 3134
    "CapabilityType": {
      "type": "string",
      "description": "Capability image type",
      "enum": [
        "ApplicationDevelopment",
        "FieldServicing"
      ],
      "x-ms-enum": {
        "name": "CapabilityType",
        "modelAsString": true,
        "values": [
          {
            "name": "ApplicationDevelopment",
            "value": "ApplicationDevelopment",
            "description": "Application development capability"
          },
          {
            "name": "FieldServicing",
            "value": "FieldServicing",
            "description": "Field servicing capability"
          }
        ]
      }
    }

readme code:

# pin the swagger version by using the commit id instead of branch name
branch: ebce1c690af6060f0e5a72d875edf752d41d5769
tag: package-2024-04-01
require:
# readme.azure.noprofile.md is the common configuration file
  - $(this-folder)/../../readme.azure.noprofile.md
  - $(repo)/specification/sphere/resource-manager/readme.md
# If the swagger has not been put in the repo, you may uncomment the following line and refer to it locally
# - (this-folder)/relative-path-to-your-local-readme.md

try-require: 
  - $(repo)/specification/sphere/resource-manager/readme.powershell.md

# For new RP, the version is 0.1.0
module-version: 0.1.0
# Normally, title is the service name
title: Sphere
subject-prefix: $(service-name)

directive:
  - from: swagger-document
    where: $.definitions.ImageProperties.properties.image
    transform: >-
      return {
          "type": "string",
          "format": "byte",
          "description": "Image as a UTF-8 encoded base 64 string on image create. This field contains the image URI on image reads.",
          "x-ms-mutability": [
            "read",
            "create"
          ]
      }
  - where:
      variant: ^(Create|Update|Generate|Claim)(?!.*?Expanded)
    remove: true
  - where:
      variant: List
      subject: CatalogDeviceGroup
    hide: true
  - where:
      variant: ^(Retrieve)(?!.*?Expanded)
      subject: CertificateProof
    hide: true
  # Remove the set-* cmdlet
  - where:
      verb: Set
    hide: true

generated: \azure-powershell\src\Sphere\Sphere.Autorest\exports\New-AzSphereDeviceCapabilityImage.ps1 line 164-169:

    [Parameter(Mandatory)]
    [AllowEmptyCollection()]
    [Microsoft.Azure.PowerShell.Cmdlets.Sphere.Category('Body')]
    [System.String[]]
    # List of capabilities to create
    ${Capability},

missing [Microsoft.Azure.PowerShell.Cmdlets.Sphere.PSArgumentCompleterAttribute("ApplicationDevelopment", "FieldServicing")]

autorest
AutoRest code generation utility [cli version: 3.7.1; node: v14.20.1]
(C) 2018 Microsoft Corporation.
https://aka.ms/autorest
info    |    Loading AutoRest core      'C:\Users\v-jiaji\.autorest\@autorestcore@3.10.1\nodemodules\@autorest\core\dist' (3.10.1)
info    | 
The default version of @autorest/powershell has been bumped from 3.0+ to 4.0+.
 > If you still want to use 3.0+ version, please specify it with --use:@autorest/powershell@3.0.{x}, e.g 3.0.512.

info    |    Loading AutoRest extension '@autorest/powershell' (4.x->4.0.674)
info    |    Loading AutoRest extension '@autorest/modelerfour' (~4.26.0->4.26.2)
warning | IgnoredPropertyNextToRef | Semantic violation: Sibling values alongside $ref will be ignored. See https://github.com/Azure/autorest/blob/main/docs/openapi/howto/$ref-siblings.md for allowed values (components > schemas > Resource > properties > systemData)
  keys: [ 'type' ]
warning | PreCheck/CheckDuplicateSchemas | Checking for duplicate schemas, this could take a (long) while.  Run with --verbose for more detail.
warning | UsingTemporaryFlag | modelerfour.treat-type-object-as-anything options is a temporary flag. It WILL be removed in the future.
info    | Autorest completed in 17.89s. 616 files generated.
dolauli commented 7 months ago

@BethanyZhou The issue is for the parameter, whose type is an enum array. We do not add the completer for it.

JoyerJin commented 7 months ago

Update readme:

# pin the swagger version by using the commit id instead of branch name
commit: ebce1c690af6060f0e5a72d875edf752d41d5769
tag: package-2024-04-01
require:
# readme.azure.noprofile.md is the common configuration file
  - $(this-folder)/../../readme.azure.noprofile.md
  - $(repo)/specification/sphere/resource-manager/readme.md
# If the swagger has not been put in the repo, you may uncomment the following line and refer to it locally
# - (this-folder)/relative-path-to-your-local-readme.md

try-require: 
  - $(repo)/specification/sphere/resource-manager/readme.powershell.md

# For new RP, the version is 0.1.0
module-version: 0.1.0
# Normally, title is the service name
title: Sphere
subject-prefix: $(service-name)

directive:
  - where:
      variant: ^(Create|Update|Generate)(?!.*?Expanded|ViaJsonString|ViaJsonFilePath)
    remove: true
  - where:
      verb: Remove
      subject: Device|Image|Deployment
    remove: true
  - where:
      verb: Update
      subject: Image
    remove: true
  - where:
      verb: Upload
      subject: UploadCatalogImage
    remove: true
  - where:
      variant: ^List(?!.*?Expanded)
      subject: CatalogDeviceGroup
    remove: true
  - where:
      variant: ^(Retrieve)(?!.*?Expanded)
      subject: CertificateProof
    remove: true
  - where:
      variant: ^Claim(?!.*?Expanded)
      subject: ClaimDeviceGroupDevice
    hide: true
  # Remove the set-* cmdlet
  - where:
      verb: Set
    hide: true

and code line 174-183: [Parameter(ParameterSetName='GenerateExpanded', Mandatory)] [Parameter(ParameterSetName='GenerateViaIdentityCatalogExpanded', Mandatory)] [Parameter(ParameterSetName='GenerateViaIdentityDeviceGroupExpanded', Mandatory)] [Parameter(ParameterSetName='GenerateViaIdentityExpanded', Mandatory)] [Parameter(ParameterSetName='GenerateViaIdentityProductExpanded', Mandatory)] [AllowEmptyCollection()] [Microsoft.Azure.PowerShell.Cmdlets.Sphere.Category('Body')] [System.String[]]

List of capabilities to create

${Capability},