Azure / autorest.csharp

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

ClientOptions naming is incorrect when using client aliases #4806

Open JoshLove-msft opened 1 month ago

JoshLove-msft commented 1 month ago

In the Event Grid Namespaces library, the main.tsp defines an EventGridClient, but in our client.tsp we customize this into two separate clients, EventGridSenderClient and EventGridReceiverClient. I would expect the generator to generate two options types, EventGridSenderClientOptions and EventGridReceiverClientOptions. Instead, it generates one options type, AzureMessagingEventGridNamespacesClientOptions.

chunyu3 commented 3 weeks ago

In our design, one service will have one ClientOptions. We have not support multiple service. @JoshLove-msft What is EventGrid want? multiple service or one service with multiple clients (sub-client)? If it is one service with multiple clients, all the clients will share the same clientOptions

lirenhe commented 3 weeks ago

cc @m-nash for awareness.

JoshLove-msft commented 3 weeks ago

In our design, one service will have one ClientOptions. We have not support multiple service. @JoshLove-msft What is EventGrid want? multiple service or one service with multiple clients (sub-client)? If it is one service with multiple clients, all the clients will share the same clientOptions

The generator generates two service clients, EventGridSenderClient and EventGridReceiverClient. I expected there to be two corresponding options types for the two client types.

chunyu3 commented 3 weeks ago

In our design, one service will have one ClientOptions. We have not support multiple service. @JoshLove-msft What is EventGrid want? multiple service or one service with multiple clients (sub-client)? If it is one service with multiple clients, all the clients will share the same clientOptions

The generator generates two service clients, EventGridSenderClient and EventGridReceiverClient. I expected there to be two corresponding options types for the two client types.

Hello @JoshLove-msft Following is an example to define two services in one typespec file. Does EventGrid defines in the same way? Or would you please provide the EventGrid typespec for us to verify? thanks

import "@typespec/rest";
import "@typespec/http";

using TypeSpec.Http;

@service({
  title: "HttpbinServer",
})
@server(
  "https://{domain}.{tld}",
  "Httpbin endpoint",
  {
    @doc("second-level domain, use httpbin")
    domain?: string = "httpbin",

    @doc("top-level domain, use org")
    tld?: string = "org",
  }
)
namespace BinServer {

  @route("/status/{code}")
  interface ServerOp {
    status(@path code: int32): OkResponse | NoContentResponse;
  }
}

@service({
  title: "ContosoServer",
})
@server(
  "{Endpoint}/contoso/{ApiVersion}",
  "Service endpoint",
  {
    @doc("Service endpoint")
    Endpoint: string,

    @doc("Api Version")
    @path
    ApiVersion: APIVersions,
  }
)
namespace ContosoServer {
  enum APIVersions {
    v1: "v1",
  }

  @route("/contoso")
  interface ServerOp {
    get(@path code: int32): OkResponse | NoContentResponse;
  }
}
JoshLove-msft commented 3 weeks ago

Here is the client.tsp - https://github.com/Azure/azure-rest-api-specs/blob/main/specification/eventgrid/Azure.Messaging.EventGrid/client.tsp

chunyu3 commented 3 weeks ago

Here is the client.tsp - https://github.com/Azure/azure-rest-api-specs/blob/main/specification/eventgrid/Azure.Messaging.EventGrid/client.tsp

Hello @JoshLove-msft according to the spec, EventGrid only have one service Microsoft.EventGrid, the clients belong to the same service.