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

error serializing empty arm objects #653

Closed
ctaggart opened this issue May 27, 2020 · 4 comments
Closed

error serializing empty arm objects #653

ctaggart opened this issue May 27, 2020 · 4 comments

Comments

@ctaggart
Copy link

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.

@lmazuel
Copy link
Member

lmazuel commented May 29, 2020

You can't use flattening if the properties are optional, removing that line would solve the problem:
https://github.com/Azure/azure-rest-api-specs-pr/commit/19b97045d676c8aa7823f60bf0bc1c206ed72dce#diff-af746ebd35d755d9dede114e799b6465R1314

Flattening by definition removes a lot of granularity and expressiveness (with the benefits of being less verbose).

Just to confirm one thing, your PUT calls required a body {} ? All the time? Why are you even putting a complex body definition then?

@ctaggart
Copy link
Author

@lmazuel, yes, the PUT calls require a body of {}. What would you recommend using to get that?

@lmazuel
Copy link
Member

lmazuel commented May 29, 2020

I would create a class ExpressRouteAuthorizationCreateParameters that contains no properties, and use this one input of the method. When output and input are not consistent, that's the kind of approach we try to take (example)

At least you get your settable property (even if it's always set to {} which is not super user-friendly)

There might be a way to make it a constant and remove it from the signature, but I would have to try and I can't right now, I'll add a note to try that early next week.

@ctaggart
Copy link
Author

ctaggart commented May 29, 2020

Thanks! I set it to "type": "object" and that seemed to work.
https://github.com/Azure/azure-rest-api-specs-pr/pull/1205/commits/d3b8b26ac7ddb8d13929977e54cfa3e07977d6c4

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

No branches or pull requests

2 participants