Azure / autorest.az

Azure CLI Code Generator
MIT License
22 stars 20 forks source link

fix invalid custom generated issue #864

Closed kairu-ms closed 3 years ago

kairu-ms commented 3 years ago

closed https://github.com/Azure/autorest.az/issues/863 closed https://github.com/Azure/autorest.az/issues/861

The custom function for update is invalid in latest released autorest

autorest --version=3.0.6370 --az --use=https://github.com/Azure/autorest.az/releases/download/1.7.3-b.20210610.1/autorest-az-1.7.3.tgz ..\..\azure-rest-api-specs\specification\hybridcompute\resource-manager\readme.md --azure-cli-extension-folder=..\..\azure-cli-extensions

The output has syntax issue.

def connectedmachine_private_link_scope_update(instance,
                                               resource_group_name,
                                               scope_name,
                                               location,
                                               tags=None,
                                               public_network_access=None):
    if public_network_access is None:
        public_network_access = "Disabled"
    if location is not None:
        instance.location = location
    if tags is not None:
        instance.tags = tags
    if "Disabled" is not None:,        instance.properties.public_network_access = "Disabled" if public_network_access is None else public_network_access
    return instance

The fixed output is

def connectedmachine_private_link_scope_update(instance,
                                               resource_group_name,
                                               scope_name,
                                               location,
                                               tags=None,
                                               public_network_access=None):
    if public_network_access is None:
        public_network_access = "Disabled"
    if location is not None:
        instance.location = location
    if tags is not None:
        instance.tags = tags
    if public_network_access is not None:
        instance.properties.public_network_access = "Disabled" if public_network_access is None else public_network_access
    return instance
kairu-ms commented 3 years ago

@qiaozha, Please review this PR. Thanks.

qiaozha commented 3 years ago

there's dup logic in your expected output

    if public_network_access is None:
        public_network_access = "Disabled"

and

    if public_network_access is not None:
        instance.properties.public_network_access = "Disabled" if public_network_access is None else public_network_access
qiaozha commented 3 years ago

Also, I wonder why there's a ',' in the original wrong code.