Azure / Azure/autorest.powershell
When the request body has nested objects , ToJson() method is failing to deserialize the object .
- Dominant language
- C#
- Stars
- 123
- Forks
- 99
- PR merge metrics
- No merged PRs in 30d
Description
**Specs URI :**
https://github.com/Azure/azure-rest-api-specs/tree/master/specification/azsadmin/resource-manager/deployment/Microsoft.Deployment.Admin/
Please refer to this readme.md file for the changes required before generating the PS cmdlets :
https://github.com/kegangum/azurestack-powershell/blob/users/kegangum/autorest/src/Azs.Deployment.Admin/readme.md#autorest-configuration
To generate PS cmdlets , navigate into the 'azurestack-powershell\src\Azs.Deployment.Admin' folder and run :
autorest
pwsh
.\build-module.ps1
The cmdlet which is causing the issue is :
Invoke-AzsProductDeployAction -Product 'microsoft.nullprovider' -Version '1.1' -Parameter @{}
This PS cmdlet is calling the DeployActionProduct method in the '\azurestack-powershell\src\Azs.Deployment.Admin\generated\api\DeploymentAdminClient.cs' . Please find this method in the attached screenshot.
DeployActionProduct method is formulating the request.Content :
request.Content = new global::System.Net.Http.StringContent(null != body ? **body.ToJson(null)**.ToString() : @"{}", global::System.Text.Encoding.UTF8);
The object 'body' is of type 'DeployActionParameters' . This body has nested object 'Parameter' of type 'DeployActionParameters1' and a 'version' of type 'string'. Request.Content is obtained by deserialzing the body, with this expression body.ToJson() .
This expression , body.ToJson() is removing the nested object(DeployActionParameters1) and returning a Json which has only 'version' in it .
But , I'm able to read the nested object with this expression : body.Parameter.ToJson() .
Example :
body is {"Parameter" : {object of DeployActionParameters1 type } , "version" : "1.1"}
The output from the body.ToJson()
Actual :
{"version" : '1.1'}
Expected :
{"Parameter" : @{} , "version":"1.1"}
Please make ToJson() method to return the nested objects .
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.