This page documents the default client hierarchy behavior as well as how to customize clients. For an overview of the setup, please visit the previous page.
JS RLC is not in the business of customization. it will ignore client.tsp and the follow scenarios will not have impact on the JS RLC user experiences. In this context, TypeScript part means JS Modular Emitter.
Default behavior
By default, each namespace with @service decorator will be generated as a root client. The name for that client will be the namespace name concatenating Client as suffix.
Other nested namespacess and interfaces of each root client will be generated as operation groups with hierarchy.
The root client’s namespace will follow the namespace decorated with @service. If an operation group comes from a nested namespace, it will follow that namespace. If it comes from a nested interface, it will follow the namespace to which the interface belongs.
Different language’s code generator will have different way to organize clients and operation groups. Please refer the following examples.
Customization SHOULD always be done in a file called client.tsp along with the main.tsp.
You can use @client and @operationGroup to reconstruct the client hierarchy. However, if any customizations are made, the client hierarchy will only be inferred from those customizations. The logic defined in the default behaviors will no longer take effect.
If any customizations are made, the client’s namespace will follow the namespace decorated with @client or the namespace to which the interface decorated with @client belongs. The operation group’s namespace follows the same logic for @operationGroup. You can use @clientNamespace to override it if needed.
For this section, we will assume that you have service called PetStore in the namespace PetStore, defining the two operations feed and pet.
Renaming the client name
This can be achieved with the augment decorator: @clientName from typespec-client-generator-core.
Two clients that separate the operations can be declared using the @client decorator and the @operationGroup decorator from typespec-client-generator-core: