Azure / Azure/typespec-azure

Namespace hierarchy assumptions in the context of client generation with `useAuth`

Open
#2,032 2 comments 0 reactions 1 assignee Claimed by @tadelesh View on GitHub
lib:tcgc
Dominant language
TypeScript
Stars
27
Forks
90
Avg merge
1d 22h
Merged PRs (30d)
156

Description

We have similar discussions in [this](https://teams.microsoft.com/l/message/19:906c1efbbec54dc8949ac736633e6bdf@thread.skype/1732737519683?tenantId=72f988bf-86f1-41af-91ab-2d7cd011db47&groupId=3e17dcb0-4257-4a30-b843-77f47f1d4121&parentMessageId=1732737519683&teamName=Azure%20SDK&channelName=TypeSpec%20Discussion&createdTime=1732737519683) but the hierachy assumptions are still unclear for me when mapping to our [new client design](https://gist.github.com/tadelesh/bb1b04501d25dd1f19bc5b164fb79810). Here are my assumptions and questions.
- Case 1: One auth with root namespace
- Case 2: Different auth in different namespace

### Case 1: One auth with root namespace
```
@service({
title: "Widget Service",
})
@useAuth(BearerAuth | ApiKeyAuth)
namespace Todo {
@route("/users")
namespace Users {
op create(): void;
}

@route("/items")
namespace TodoItems {
op create(): void;
}
}
```

_Assumptions:_
- The top-level client `Todo` accepts a parameter for authentication (e.g., BearerAuth or ApiKeyAuth).
- The top-level client contains two sub-clients: `Users` and `TodoItems`. Both of them would share the parent authentication.
- For all sub-clients they will inherit all parameters from the top-level client but can't add or override parameters from their parent.
- their `access` would be `Access.internal` which means they can't be initialized separately;
- their `accessorAccess` would be `Access.public` which means they could be got from parent client.

### Case 2: Different auth in different namespace

```
@service({
title: "Widget Service",
})
@useAuth(BearerAuth | ApiKeyAuth)
namespace Todo {
@useAuth(NoAuth)
@route("/users")
namespace Users {
op create(): void;
}

@route("/items")
namespace TodoItems {
op create(): void;
}
}
```

_Assumptions:_
- The top-level client `Todo` accepts a parameter for authentication (e.g., BearerAuth or ApiKeyAuth).
- The top-level client contains two sub-clients: `Users` and `TodoItems`. Sub-client `Users` would **override** the parent's authentication parameter to align with NoAuth. `TodoItems` would share the parent authentication.
- For all sub-clients they will inherit all parameters from the top-level client but **can't add or override** parameters from their parent.
- their `access` would be `Access.internal` which means they can't be initialized separately;
- their `accessorAccess` would be `Access.public` which means they could be got from parent client.

If we trust the assumption that `useAuth` should not change the hierarchy, we may see the contradictory point in client `Users` which requires a construtor overriding but is not allowed to override. One way to correct the conflict is to use `@clientInitialization`.

```
@@clientInitialization(Users , {access: Access.public, accessorAccess: Access.internal});
```

I know most of SDK emitters has yet to support different authentication for different clients but considering this would impact the client hierarchy, Could we settle down following questions to reduce future potential breakings?

- With above two cases, is the assumption correct?
- Do we have the same assumption in Azure and unbranded area?
- Do we allow `useAuth` to change the sub-client's `access`?
- Can `@clientInitialization` be used in both Azure and unbranded area?

/cc @joheredi @tadelesh @ArcturusZhang @weidongxu-microsoft

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.