Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,15 @@ function fromSdkClient(
client.namespace,
);

const isMultiService = isMultiServiceClient(client);
const clientName =
!client.parent && isMultiService && !client.name.toLowerCase().endsWith("client")
? `${client.name}Client`
: client.name;

inputClient = {
kind: "client",
name: client.name,
name: clientName,
namespace: client.namespace,
doc: client.doc,
summary: client.summary,
Expand All @@ -79,7 +85,7 @@ function fromSdkClient(
apiVersions: client.apiVersions,
parent: undefined,
children: undefined,
isMultiServiceClient: isMultiServiceClient(client),
isMultiServiceClient: isMultiService,
};

sdkContext.__typeCache.updateSdkClientReferences(client, inputClient);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,209 @@ describe("isMultiServiceClient", () => {
}
});
});

describe("client name suffix", () => {
let runner: TestHost;

beforeEach(async () => {
runner = await createEmitterTestHost();
});

it("should append Client suffix to multi-service root client without suffix", async () => {
const program = await typeSpecCompile(
`
@versioned(VersionsA)
namespace ServiceA {
enum VersionsA {
av1,
}

@route("/test")
op testOne(@query("api-version") apiVersion: VersionsA): void;
}

@versioned(VersionsB)
namespace ServiceB {
enum VersionsB {
bv1,
}

@route("/test")
op testTwo(@query("api-version") apiVersion: VersionsB): void;
}

@client({
name: "Combined",
service: [ServiceA, ServiceB],
})
namespace Service.MultiService {}
`,
runner,
{ IsNamespaceNeeded: false, IsTCGCNeeded: true },
);
const context = createEmitterContext(program);
const sdkContext = await createCSharpSdkContext(context);
const root = createModel(sdkContext);

const client = root.clients[0];
ok(client, "Client should exist");
strictEqual(
client.name,
"CombinedClient",
"Multi-service root client should have Client suffix appended",
);
});

it("should not duplicate Client suffix for multi-service root client already ending with Client", async () => {
const program = await typeSpecCompile(
`
@versioned(VersionsA)
namespace ServiceA {
enum VersionsA {
av1,
}

@route("/test")
op testOne(@query("api-version") apiVersion: VersionsA): void;
}

@versioned(VersionsB)
namespace ServiceB {
enum VersionsB {
bv1,
}

@route("/test")
op testTwo(@query("api-version") apiVersion: VersionsB): void;
}

@client({
name: "CombinedClient",
service: [ServiceA, ServiceB],
})
namespace Service.MultiService {}
`,
runner,
{ IsNamespaceNeeded: false, IsTCGCNeeded: true },
);
const context = createEmitterContext(program);
const sdkContext = await createCSharpSdkContext(context);
const root = createModel(sdkContext);

const client = root.clients[0];
ok(client, "Client should exist");
strictEqual(
client.name,
"CombinedClient",
"Multi-service root client already ending with Client should not have suffix duplicated",
);
});

it("should not duplicate Client suffix with different casing", async () => {
const program = await typeSpecCompile(
`
@versioned(VersionsA)
namespace ServiceA {
enum VersionsA {
av1,
}

@route("/test")
op testOne(@query("api-version") apiVersion: VersionsA): void;
}

@versioned(VersionsB)
namespace ServiceB {
enum VersionsB {
bv1,
}

@route("/test")
op testTwo(@query("api-version") apiVersion: VersionsB): void;
}

@client({
name: "CombinedCLIENT",
service: [ServiceA, ServiceB],
})
namespace Service.MultiService {}
`,
runner,
{ IsNamespaceNeeded: false, IsTCGCNeeded: true },
);
const context = createEmitterContext(program);
const sdkContext = await createCSharpSdkContext(context);
const root = createModel(sdkContext);

const client = root.clients[0];
ok(client, "Client should exist");
strictEqual(
client.name,
"CombinedCLIENT",
"Multi-service root client ending with CLIENT (uppercase) should not have suffix duplicated",
);
});

it("should not append Client suffix to sub-clients of multi-service client", async () => {
const program = await typeSpecCompile(
`
@versioned(VersionsA)
namespace ServiceA {
enum VersionsA {
av1,
}

@route("/a")
interface AI {
@route("test")
op aTest(): void;
}
}

@versioned(VersionsB)
namespace ServiceB {
enum VersionsB {
bv1,
}

@route("/b")
interface BI {
@route("test")
op bTest(): void;
}
}

@client({
name: "Combined",
service: [ServiceA, ServiceB],
})
@useDependency(ServiceA.VersionsA.av1, ServiceB.VersionsB.bv1)
namespace Service.MultiService {}
`,
runner,
{ IsNamespaceNeeded: false, IsTCGCNeeded: true },
);
const context = createEmitterContext(program);
const sdkContext = await createCSharpSdkContext(context);
const root = createModel(sdkContext);

const client = root.clients[0];
ok(client, "Client should exist");
strictEqual(
client.name,
"CombinedClient",
"Multi-service root client should have Client suffix appended",
);

// Verify sub-clients do NOT have Client suffix appended
ok(client.children, "Client should have children");
ok(client.children.length > 0, "Client should have at least one child");
for (const childClient of client.children) {
strictEqual(
childClient.name.endsWith("Client"),
false,
`Child client '${childClient.name}' should not have Client suffix`,
);
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static ParameterProvider ClientOptions(CSharpType clientOptionsType)
DefaultValue = Static(typeof(DateTimeOffset)).Property(nameof(DateTimeOffset.Now))
};

public static readonly ParameterProvider ContentType = new("contentType", $"The contentType to use which has the multipart/form-data boundary.", typeof(string), wireInfo: new PropertyWireInformation(SerializationFormat.Default, true, false, false, false, "Content-Type", false));
public static readonly ParameterProvider ContentType = new("contentType", $"The contentType to use which has the multipart/form-data boundary.", typeof(string), wireInfo: new PropertyWireInformation(SerializationFormat.Default, true, false, false, false, "Content-Type", false, false));

public static readonly ParameterProvider NextPage =
new ParameterProvider("nextPage", $"The url of the next page of responses.", typeof(Uri));
Expand Down
Loading
Loading