Skip to content

Commit

Permalink
[tcgc] always have a serverUrl for easier code usage (#538)
Browse files Browse the repository at this point in the history
  • Loading branch information
iscai-msft authored Mar 27, 2024
1 parent 076e2d6 commit c864f67
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: feature
packages:
- "@azure-tools/typespec-client-generator-core"
---

When no server url is passed, we still set serverUrl to `{endpoint}` and make one templateArg for `endpoint`. This way, emitters can always look at a combination of serverUrl and templateArguments to get the full picture
2 changes: 1 addition & 1 deletion packages/typespec-client-generator-core/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ export interface SdkCredentialType extends SdkTypeBase {

export interface SdkEndpointType extends SdkTypeBase {
kind: "endpoint";
serverUrl?: string;
serverUrl: string; // if not specified, we will use value "{endpoint}", and templateArguments will have one parameter called "endpoint"
templateArguments: SdkPathParameter[];
}

Expand Down
24 changes: 23 additions & 1 deletion packages/typespec-client-generator-core/src/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import {
getClientNamespaceStringHelper,
getDocHelper,
getHashForType,
getSdkTypeBaseHelper,
isNullable,
} from "./internal-utils.js";
import { createDiagnostic } from "./lib.js";
Expand Down Expand Up @@ -378,10 +379,31 @@ function getSdkEndpointParameter(
if (servers === undefined || servers.length > 1) {
// if there is no defined server url, or if there are more than one
// we will return a mandatory endpoint parameter in initialization
const name = "endpoint";
type = {
kind: "endpoint",
nullable: false,
templateArguments: [],
serverUrl: "{endpoint}",
templateArguments: [
{
name,
nameInClient: name,
description: "Service host",
kind: "path",
onClient: true,
nullable: false,
urlEncode: false,
optional: false,
serializedName: "endpoint",
correspondingMethodParams: [],
type: {
...getSdkTypeBaseHelper(context, client.service, "string"),
encode: "string",
},
isApiVersionParam: false,
apiVersions: getAvailableApiVersions(context, client.service),
},
],
};
} else {
// this means we have one server
Expand Down

0 comments on commit c864f67

Please sign in to comment.