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

Always make the baseUrl overridable in clients #1153

Closed
Tracked by #2665
timotheeguerin opened this issue Jul 11, 2024 · 1 comment · Fixed by #1155
Closed
Tracked by #2665

Always make the baseUrl overridable in clients #1153

timotheeguerin opened this issue Jul 11, 2024 · 1 comment · Fixed by #1155
Assignees
Labels
lib:tcgc Issues for @azure-tools/typespec-client-generator-core library

Comments

@timotheeguerin
Copy link
Member

timotheeguerin commented Jul 11, 2024

Tcgc issue from the discusssion here #217

As discussed the baseUrl (https://foo.com/bar) should always be settable in clients as an option.

Issue was also filed to see if http library should also provide a different view microsoft/typespec#3821 in the future

Just to clarify here too but it should be the baseUrl that is overridable not the host(Basically the entire thing that @server would set. Without that you are blocking many scenarios still:

  • http:// localhost
  • different hosted path
@timotheeguerin timotheeguerin added the lib:tcgc Issues for @azure-tools/typespec-client-generator-core library label Jul 11, 2024
@iscai-msft iscai-msft self-assigned this Jul 11, 2024
@timotheeguerin
Copy link
Member Author

timotheeguerin commented Jul 31, 2024

Playground showcasing the issues

import "@typespec/http";

using TypeSpec.Http;

// ---------------------- How server should work in theory ----------------------
@service
@server("https://github.com", "Github public api")
namespace Service1 {
// new Service1Client();
// new Service1Client({baseUrl: "http://localhost:3000"});

}

@service
@server(
  "https://{region}.azure.com",
  "Region service",
  {
    region: string,
  }
)
namespace Service2 {
// new Service2Client({region: "westus"});
// new Service2Client({baseUrl: "http://localhost:3000"});

}

@service
@server("https://github.com", "Github public api")
@server(
  "https://{org}.private.github.com",
  "Github private org api",
  {
    org: string,
  }
)
@server(
  "{endpoint}",
  "hosted github api",
  {
    endpoint: url,
  }
)
namespace Service3 {
// Service3Client.publicApi()
// Service3Client.privateApi("my-org")
// Service3Client.hosted("https://my-intra-custom-github.com")
// new Service3Client({baseUrl: "http://localhost:3000"});

}

// ----------------------     Azure  cases ----------------------
@service
@server("https://management.azure.com", "Azure public API")
namespace ArmServiceOption1 {
// new ArmServiceOption1Client();
// new ArmServiceOption1Client({baseUrl: "https://fairfax.azure.com"});

// Pros:
// - simple
// Cons:
// - not actually accurate, tcgc could special case to emit similar as option3

}
@service
@server("https://management.azure.com", "Azure public API")
@server("https://fairfax.azure.com", "Fairfax public API")
@server("https://china.azure.com", "China public API")
namespace ArmServiceOption2 {
// ArmServiceOption1Client.public();
// ArmServiceOption1Client.fairfax();
// ArmServiceOption1Client.china();

// Pros:
// - accurate
// Cons:
// - expose (in theory) all the gov cloud as typed factory which is not ideal
// - worse for public cloud

}

@service
@server(
  "{azureEndpoint}",
  "Arm endpoint",
  {
    azureEndpoint: url = "https://management.azure.com",
  }
)
namespace ArmServiceOption3 {
// new ArmServiceOption3Client();
// new ArmServiceOption3Client({endpoint: "https://fairfax.azure.com"});
// new ArmServiceOption3Client({baseUrl: "https://fairfax.azure.com"});

// Pros:
// - accurate
// Cons:
// - autorest output will change or autorest library will need to revert back

}


github-merge-queue bot pushed a commit that referenced this issue Aug 6, 2024
fixes #1153

---------

Co-authored-by: iscai-msft <isabellavcai@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lib:tcgc Issues for @azure-tools/typespec-client-generator-core library
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants