Azure / autorest.python

Extension for AutoRest (https://github.com/Azure/autorest) that generates Python code
MIT License
77 stars 55 forks source link

[typespec-python] Bug: Alias and Spread Capitalization Issue #2604

Closed l0lawrence closed 1 month ago

l0lawrence commented 1 month ago

I have changed a model to be an alias that I spread in EventGrid, and I am running into an emitter issue where the parameter within that alias is being capitalized incorrectly causing the operation to fail:

Old Tsp:

  models RejectOptions {
    @doc("Array of lock tokens.")
    lockTokens: string[];
  }

op blah( @bodyroot RejectOptions)

Generated the _content correctly as:

{"lockTokens": ["tokens"]}

New typespec looks like this:

  alias RejectOptions = {
    @doc("Array of lock tokens.")
    lockTokens: string[];
  };

op blah( ...RejectOptions)

Generated the _content as:

{"locktokens": ["tokens"]}

which gives me a service error


The service is expecting lockTokens. with the 'T' capitalized

Code currently being generated from the alias/spread with all lowercase locktokens:

        if body is _Unset:
            if lock_tokens is _Unset:
                raise TypeError("missing required argument: lock_tokens")
            body = {"locktokens": lock_tokens}
            body = {k: v for k, v in body.items() if v is not None}