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

[tcgc] namespaces in TCGC #1604

Closed
4 tasks done
Tracked by #4537
iscai-msft opened this issue Sep 24, 2024 · 11 comments · Fixed by #1786
Closed
4 tasks done
Tracked by #4537

[tcgc] namespaces in TCGC #1604

iscai-msft opened this issue Sep 24, 2024 · 11 comments · Fixed by #1786
Assignees
Labels
lib:tcgc Issues for @azure-tools/typespec-client-generator-core library

Comments

@iscai-msft
Copy link
Contributor

Clear and concise description of the problem

As we start implementing "namespace is namespace" in our language emitters, TCGC plays an important role in helping emitters get the information they need to generate. At the same time, it is important that we are not breaking, both for ease of migration, and also because some languages (like javascript) don't really have a concept of "namespace" and won't be adopting this behavior the same way the other language emitters are.

As such, I propose a multi-part approach in getting TCGC to help with the "namespace is namespace" push.

  1. Ensure that the existing .namespace string on SdkClientTypes returns the correct namespace
  2. Add a .namespace string onto SdkModelType and SdkEnumType, so we can generate these models in the correct space.
  3. Add additional helper method getNamespaceToClients(sdkContext) that returns a mapping of namespaces to clients in those namespaces.
  4. Add additional helper method getNamespaceToModels(sdkContext) that will return a mapping of namespaces to models in those namespaces

Checklist

  • Follow our Code of Conduct
  • Check that this issue is about the Azure libraries for typespec. For feature request in the typespec language or core libraries file it in the TypeSpec repo
  • Read the docs.
  • Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
@iscai-msft iscai-msft added the lib:tcgc Issues for @azure-tools/typespec-client-generator-core library label Sep 24, 2024
@iscai-msft iscai-msft self-assigned this Sep 24, 2024
@tadelesh
Copy link
Member

Another option is making SkdPackage to be hierarchy with namespace, and add a flag like flatten-namespace and default to true to prevent breaking change for some languages.

@chunyu3
Copy link
Member

chunyu3 commented Sep 25, 2024

How about the namespace defined in @client? As following, the client include more parts separated by ., and all the parts except the latest one will be the namespace of the client, will tcgc help to merge this to namespace of the client?

@client(
  {
    name: "SubNamespace.SecondClient",
    service: FirstTest.Service,
  }
)

@archerzz
Copy link
Member

For 3 & 4, what's the user scenario? There are basically 2 ways to provide the relationship between the namespaces and their belonging entities (clients, models, etc):

  • a hierarchy of SdkInputNameSpace with child properties representing clients, models, etc.
  • or a flat mapping like suggested on top

@tadelesh
Copy link
Member

link original customer ask: #1226

@iscai-msft
Copy link
Contributor Author

#1226

We had previously decided to move away from this because we didn't find it intuitive with how namespaces are set up. We believe we should continue with namespace solely as a namespace object, instead of also supporting namespace behavior based off of string parsing

@tadelesh
Copy link
Member

For 3 & 4, what's the user scenario? There are basically 2 ways to provide the relationship between the namespaces and their belonging entities (clients, models, etc):

  • a hierarchy of SdkInputNameSpace with child properties representing clients, models, etc.
  • or a flat mapping like suggested on top

3 is aimed to provide the hierarchy.

@tadelesh
Copy link
Member

How about the namespace defined in @client? As following, the client include more parts separated by ., and all the parts except the latest one will be the namespace of the client, will tcgc help to merge this to namespace of the client?

@client(
  {
    name: "SubNamespace.SecondClient",
    service: FirstTest.Service,
  }
)

the name should be the client name directly. tcgc will not do any magic to it.

@weidongxu-microsoft
Copy link
Member

weidongxu-microsoft commented Nov 4, 2024

How about the namespace defined in @client? As following, the client include more parts separated by ., and all the parts except the latest one will be the namespace of the client, will tcgc help to merge this to namespace of the client?

@client(
  {
    name: "SubNamespace.SecondClient",
    service: FirstTest.Service,
  }
)

the name should be the client name directly. tcgc will not do any magic to it.

So, I assume when namespace refactor done, service would need to write

@client(
  {
    name: "SecondClient",
    service: FirstTest.Service,
  }
)
@clientNamespace("<base_namespace>.SubNamespace")
namespace SecondClient {
}

@weidongxu-microsoft
Copy link
Member

If possible, Java would like SdkConstantType has .namespace

@tadelesh
Copy link
Member

tadelesh commented Nov 4, 2024

If possible, Java would like SdkConstantType has .namespace

i talked with haoling last week, since it is a special logic for some languages to treat optional constant as enum, it's better to opt in a conversion directly in tcgc, then it will have generated name, usage, access, namespace accordingly.

@tadelesh
Copy link
Member

tadelesh commented Nov 4, 2024

How about the namespace defined in @client? As following, the client include more parts separated by ., and all the parts except the latest one will be the namespace of the client, will tcgc help to merge this to namespace of the client?

@client(
  {
    name: "SubNamespace.SecondClient",
    service: FirstTest.Service,
  }
)

the name should be the client name directly. tcgc will not do any magic to it.

So, I assume when namespace refactor done, service would need to write

@client(
{
name: "SecondClient",
service: FirstTest.Service,
}
)
@clientNamespace("<base_namespace>.SubNamespace")
namespace SecondClient {
}

correct. but the problem here is all models' namespace (used by operation) will not be changed.

@tadelesh tadelesh closed this as completed Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lib:tcgc Issues for @azure-tools/typespec-client-generator-core library
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants