Azure / autorest.csharp

Extension for AutoRest (https://github.com/Azure/autorest) that generates C# code
MIT License
141 stars 166 forks source link

Parent class with no operations but subclass has wrong get subclient signature. #4081

Closed pshao25 closed 4 months ago

pshao25 commented 9 months ago

spec:

@server(
  "{endpoint}/client/structure/{client}",
  "",
  {
    @doc("Need to be set as 'http://localhost:3000' in client.")
    endpoint: url,

    @doc("Need to be set as 'default', 'multi-client', 'renamed-operation', 'two-operation-group' in client.")
    client: ClientType,
  }
)
@service({
  title: "MultiClient",
  version: "1.0.0",
})
namespace Client.Structure.Service;

namespace Baz {
  interface Foo {
    #suppress "@azure-tools/cadl-ranch-expect/missing-scenario" "This is by design those operations get defined as scenarios in the client"
    @route("/seven")
    @post
    seven(): void;
  }
}

In the Baz, there is no operations but there is a sub client Foo. And in the service there is a global parameter client.

Actual:

public virtual BazFoo GetBazFooClient(string client, string apiVersion = "1.0.0")
{
    Argument.AssertNotNullOrEmpty(client, nameof(client));
    Argument.AssertNotNull(apiVersion, nameof(apiVersion));

    return new BazFoo(ClientDiagnostics, _pipeline, _endpoint, client, apiVersion);
}

Expected:

private BazFoo _cachedBazFoo;

/// <summary> Initializes a new instance of BazFoo. </summary>
public virtual BazFoo GetBazFooClient()
{
    return Volatile.Read(ref _cachedBazFoo) ?? Interlocked.CompareExchange(ref _cachedBazFoo, new BazFoo(ClientDiagnostics, _pipeline, _endpoint, _client, _apiVersion), null) ?? _cachedBazFoo;
}
pshao25 commented 5 months ago

For swagger:

  1. If parameter is used in top client and optional, it should be a top client parameter and in Options.
  2. If parameter is not used in top client, it should not be a top client parameter.

So purview is by design and agrifood should change.