Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature request] Add support to distinguish null and {} object #920

Open
BethanyZhou opened this issue Mar 18, 2022 · 4 comments
Open

[feature request] Add support to distinguish null and {} object #920

BethanyZhou opened this issue Mar 18, 2022 · 4 comments

Comments

@BethanyZhou
Copy link
Contributor

BethanyZhou commented Mar 18, 2022

Reported by Azure/azure-powershell#17410

Autorest.powershell will treat {} as null object. And do not send {} to backend.

Beside, we are suspecting service side may report {} is invalid value if we pass {} for some other parameters (from other RPs). We are unable to predict what will be caused if we distinguish {} with null and send {} to backend. We are investigating whether we need a flag from swagger to let us know this parameter whether distinguish ‘{}’ and null.

"volumes": [
          {
            "name": "emptydir1",
            "emptyDir": {}
          }
        ]
@BethanyZhou BethanyZhou changed the title Add support to distinguish null and {} object [feature request] Add support to distinguish null and {} object Mar 18, 2022
@dolauli
Copy link
Contributor

dolauli commented Apr 6, 2022

Explain in more details.
Let's say we have an input parameter in swagger as below.

"tags": {
    "type": "object",
     "additionalProperties": true
}

We will generate a parameter as below in the cmdlet.

xxx-cmdlet [-Tag <Hashtable>]

Right now, no matter if the user calls xxx-cmdlet or xxx-cmdlet -Tag @{}, we will not send tags to services.
And the requirement here is we should send {} for the latter.

@dingmeng-xue
Copy link
Member

We need to figure out a general solution. Let's consider customization for the time being.

@dolauli
Copy link
Contributor

dolauli commented Apr 12, 2022

Let's use tags here example.
We may support it through custom code as below.

namespace Microsoft.Azure.PowerShell.Cmdlets.Databricks.Models.Api20180401
{

    /// <summary>The resource model definition for a ARM tracked top level resource</summary>
    public partial class TrackedResource
    {
        partial void AfterToJson(ref Microsoft.Azure.PowerShell.Cmdlets.Databricks.Runtime.Json.JsonObject container) {
            if (this._tag != null && this._tag.Count == 0) {
                container.Add("tags", new Microsoft.Azure.PowerShell.Cmdlets.Databricks.Runtime.Json.JsonObject());
            }
        }
    }
}

@BethanyZhou
Copy link
Contributor Author

Thanks @dolauli ,

This customization works for me. I'm applying this method to EmptyDir: Azure/azure-powershell#17802

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants