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

tsp, design discussion, client hierarchy #2428

Open
weidongxu-microsoft opened this issue Nov 29, 2023 · 7 comments
Open

tsp, design discussion, client hierarchy #2428

weidongxu-microsoft opened this issue Nov 29, 2023 · 7 comments
Labels

Comments

@weidongxu-microsoft
Copy link
Member

weidongxu-microsoft commented Nov 29, 2023

see https://github.com/Azure/typespec-azure-pr/issues/3809#discussion_r1405948920

Should Java support nested client?
E.g. petStoreClient.getPets().getActions().feed()

@weidongxu-microsoft weidongxu-microsoft changed the title tsp, design, client hierarchy tsp, design discussion, client hierarchy Nov 29, 2023
@weidongxu-microsoft
Copy link
Member Author

petStoreClientBuilder.buildPets()
petStoreClientBuilder.buildPetsActions()

@weidongxu-microsoft
Copy link
Member Author

weidongxu-microsoft commented Nov 30, 2023

petStoreClientBuilder.buildPets()
petStoreClientBuilder.<other-configures>.pets().buildActions()

@weidongxu-microsoft
Copy link
Member Author

weidongxu-microsoft commented Aug 26, 2024

Scenario for Face AI (with client parameter)

getClient pattern

We currently have this pattern (only?) in storage-blob.

FaceServiceClient faceServiceClient = new FaceServiceClientBuilder().buildClient();
FaceListClient faceListClient = faceServiceClient.getFaceListClient(faceListId);
// other clients
PersonGroupClient otherClient = faceServiceClient.getPersonGroupClient();

(PS: in current client.tsp, FaceServiceClient contains no API, only operation groups -- hence it won't be generated in Java)

buildClient pattern

FaceListClient faceListClient = new FaceServiceClientBuilder()
    .faceListId(faceListId)
    .buildFaceListClient();
// other clients
PersonGroupClient otherClient = new FaceServiceClientBuilder()
    .buildPersonGroupClient();

Some verification logic is needed in Builder, to verify that faceListId is provided when creating FaceListClient.

A minor variation

Use a dedicated builder for FaceListClient, so that it be clearer no faceListId is settable to other clients.

FaceListClient faceListClient = new FaceListClientBuilder()
    .faceListId(faceListId)
    .buildClient();
// other clients
PersonGroupClient otherClient = new FaceServiceClientBuilder()
    .buildPersonGroupClient();

@XiaofeiCao

This comment was marked as outdated.

@weidongxu-microsoft

This comment was marked as outdated.

@weidongxu-microsoft
Copy link
Member Author

weidongxu-microsoft commented Sep 11, 2024

Known namespace/interface patterns (assume namespace/interface always contains some operations)

// same to @client
// var client = new ClientBuilder().buildClient();
namespace Client {
}

// same to @client and @operationGropu
// var og1Client = new ClientBuilder().buildOg1Client();
namespace Client {
  interface Og1 {};
  interface Og2 {};
}

// intend to be
// var og1Client = new ClientBuilder().buildClient().getOg1Client(level1Options);
namespace Client {
  @clientInitialization(ClientLevel1Options)
  interface Og1 {};
  interface Og2 {};
}

// intend to be
// var og1Client = new ClientBuilder().buildClient().getClientLevel2().getClientLevel3().getOg1Client();
namespace Client {
  namespace ClientLevel2 {
    namespace ClientLevel3 {
      interface Og1 {};
      interface Og2 {};
    }
  }
}

// intent as
// var og1Client = new ClientBuilder().buildClient().getClientLevel2(level2Options).getClientLevel3(level3Options).getOg1Client(level4Options);
namespace Client {
  @clientInitialization(ClientLevel2Options)
  namespace ClientLevel2 {
    @clientInitialization(ClientLevel3Options)
    namespace ClientLevel3 {
      @clientInitialization(ClientLevel4Options)
      interface Og1 {};
      interface Og2 {};
    }
  }
}

All of these patterns can exist in a single tsp file.


Plan to use an emitter option (e.g. client-accessor or enable-subclient) to switch the client hierarchy pattern.

github-merge-queue bot pushed a commit to microsoft/typespec that referenced this issue Sep 12, 2024
This is only part of the support for
Azure/autorest.java#2428

cadl-ranch Azure/cadl-ranch#727

user code
```java
        InitializationClient client = new InitializationClientBuilder()
            .name("client1")
            .buildClient();
        client.action();
```
sarangan12 pushed a commit to sarangan12/typespec that referenced this issue Sep 16, 2024
This is only part of the support for
Azure/autorest.java#2428

cadl-ranch Azure/cadl-ranch#727

user code
```java
        InitializationClient client = new InitializationClientBuilder()
            .name("client1")
            .buildClient();
        client.action();
```
@weidongxu-microsoft
Copy link
Member Author

ref Azure/typespec-azure#1702

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants