Skip to content

error serializing empty arm objects #653

@ctaggart

Description

@ctaggart

I'm using autorest.python 3.0.6.2 to generate the code for az-vmware-cli.

autorest --input-file=$spec --python --output-folder=azext_vmware --namespace=vendored_sdks --azure-arm=true --override-client-name=AVSClient --use=@microsoft.azure/autorest.python@3.0.62

I get this error:

azext_vmware/vendored_sdks/operations/authorizations_operations.py:204: in _create_or_update_initial
    body_content = self._serialize.body(authorization, 'ExpressRouteAuthorization')
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <msrest.serialization.Serializer object at 0x7f8e52b92390>, data = None, data_type = 'ExpressRouteAuthorization', kwargs = {}

    def body(self, data, data_type, **kwargs):
        """Serialize data intended for a request body.

        :param data: The data to be serialized.
        :param str data_type: The type to be serialized from.
        :rtype: dict
        :raises: SerializationError if serialization fails.
        :raises: ValueError if data is None
        """
        if data is None:
>           raise ValidationError("required", "body", True)
E           msrest.exceptions.ValidationError: Parameter 'body' can not be None.

Which I tracked down to this generated code:

    def _create_or_update_initial(
            self, resource_group_name, private_cloud_name, authorization_name, custom_headers=None, raw=False, **operation_config):
        authorization = None

If I add a settable property to the object, it then becomes:

    def _create_or_update_initial(
            self, resource_group_name, private_cloud_name, authorization_name, authorization, custom_headers=None, raw=False, **operation_config):

There are no settable properties in two of the new APIs. They both require just the name, which is passed in the URL. ARM does require an empty object of {} to be passed in.

Microsoft employees, this is the work-a-round I added:
https://github.com/Azure/azure-rest-api-specs-pr/pull/1205/commits/19b97045d676c8aa7823f60bf0bc1c206ed72dce

Which resulted in this valid code generation:
Azure/az-vmware-cli@159f682

That workaround shouldn't be in the spec. What are the options.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions