Azure / autorest.powershell

AutoRest PowerShell Generator
MIT License
113 stars 86 forks source link

Need to set ValuefromPipelineByPropertyName for path parameter #616

Open Sowmyacv opened 4 years ago

Sowmyacv commented 4 years ago

Autorest by default sets Valuefrompipeline property for all body parameters. We want to set ValuefromPipelineByPropertyName for path parameter so we can use our Get cmdlet as Input object for Update cmdlet we need like below as we have Entity ID as input to update cmdlet and get Provides it

    [global::System.Management.Automation.Parameter(Mandatory = true, HelpMessage = "Id of the Entityto update", ### ValueFromPipelineByPropertyName = true)]

[PowerShell.API.Runtime.Info( Required = true, ReadOnly = false, Description = @"Id of the Entity to update", SerializedName = @"EntityId", PossibleTypes = new [] { typeof(int) })] [global::Powershell.API.Category(global::Powershell.API.ParameterCategory.Path)]

daviwil commented 4 years ago

Hi @Sowmyacv, this seems to be specifically related to the PowerShell generator so I've transferred it to the Azure/autorest.powershell repository.

dolauli commented 1 year ago

@Sowmyacv @peombwa No, it is not set for all the body parameters. It is designed to pipe an resource(Id) you want to update/delete/etc. But it will need support from service too. When you use get cmdlet, the output is from the response, and path is a part of the request(input), so path info by default is not in the output of a get cmdlet. And there are two solutions from service side.

  1. You will need to put the path parameter as part of the response, e.g. {"database": "abc", "table":"def"}. And then we will combine the path for you. See here for how we do it.
  2. Suggest you could follow the practice of Azure Service, which return the resourceId(path) as a property called Id in the response(See here for an example). As a result, we will generate something like this. This solution is only supported for Azure service(azure: true in readme.md) in autorest.powershell now. But it should be easy to extend support by adding a configuration to tell the generator which property in the response is the resource Id(path).
peombwa commented 1 year ago

Thanks for the suggestions.

For our scenario, the response object already has an Id property, that we would like to bind to the entityId path parameter of the input command. i.e., Get-Application | Get-ApplicationOwner where:

  1. Get-Application returns a collection of object with [{"Id": "12345", "displayName": "My app" }]:
  2. Get-ApplicationOwner requires a parameter named -ApplicationId - GET /applications/{application-id}/owner.

Something like https://learn.microsoft.com/en-us/powershell/module/az.resources/get-azadgroupmember?view=azps-9.4.0#example-2-list-members-by-pipeline-input.

We are interested in supporting piping for all parameter sets (list, get, delete, create, update etc.) We would like piping to work with any top-level path parameter that's provided as the input.:

  1. Get-Parent(s) | Get-Children or Get-Child
    • GET /applications | GET /applications/{application-id}/owners
    • GET /applications | GET /applications/{application-id}/logo
  2. Get-Parent(s) | Remove-Child
    • GET /applications | DELETE /applications/{application-id}/logo
    • GET /applications | DELETE /applications/{application-id}/owners/{member-id}

Also, ViaIdentity does not currently support list parameter sets.

The thinking on our end was to have AutoREST.PowerShell mark top-level path parameters with ValueFromPipelineByPropertyName = true attribute, then alias the top-level parameters to id.