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] add namespace flag #2161

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open

[tcgc] add namespace flag #2161

wants to merge 16 commits into from

Conversation

iscai-msft
Copy link
Contributor

@iscai-msft iscai-msft commented Jan 31, 2025

Adding support for a namespace flag in tsp configs. The rules are simple:

  1. If namespace is present in tspconfig.yaml, all instances of the root namespace will be replaced with the value of namespace.
  2. If there are multiple root namespaces, we throw an error since it's not clear which one to replace.
  3. We still use @clientNamespace. However, the client namespace will have to contain the root namespace

@microsoft-github-policy-service microsoft-github-policy-service bot added the lib:tcgc Issues for @azure-tools/typespec-client-generator-core library label Jan 31, 2025
@azure-sdk
Copy link
Collaborator

azure-sdk commented Jan 31, 2025

All changed packages have been documented.

  • @azure-tools/typespec-client-generator-core
Show changes

@azure-tools/typespec-client-generator-core - feature ✏️

Add support for namespace flag in tspconfig.yaml

@azure-sdk
Copy link
Collaborator

azure-sdk commented Jan 31, 2025

You can try these changes here

🛝 Playground 🌐 Website 📚 Next docs

@@ -79,6 +79,7 @@ export async function createSdkContext<
decoratorsAllowList: [...defaultDecoratorsAllowList, ...(options?.additionalDecorators ?? [])],
previewStringRegex: options?.versioning?.previewStringRegex || tcgcContext.previewStringRegex,
disableUsageAccessPropagationToBase: options?.disableUsageAccessPropagationToBase ?? false,
namespace: context.options["namespace"],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be missing it but where are we blocking / ignoring this outside of azure flavor? @srnagar if I recall correctly that is what we were doing is azure only since thats the only use case that actually needs this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is we weren't going to block unbranded from using it, but we are really mainly adding it for Azure compatibility.

The general use case I have for this is:

  1. there's a main.tsp that defines the service under one main namespace (say namespace DocumentIntelligence)
  2. there's a client.tsp with client-customizations under one main namespace (say namespace DocumentIntelligenceCustomizations)
  3. we use namespace flag in tspconfig.yaml to give the azure name, so namespace: Azure.DocumentIntelligence

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The namespace in tspconfig.yaml is mainly used for Azure and we will not use it for unbranded libraries. We just don't publicly document namespace option for unbranded libraries.

If we want to be very explicit, we can add a check in the TCGC that can be removed later if we want to extend this support for unbranded libraries.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally feel like it's cleaner to keep it as is, and when we split up tcgc, we can keep namespace in the tcgc library. I think I'd almost prefer if we only want azure to use it, to call it something like azureNamespace. I don't feel very strongly about this though

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I agree with just keeping it as is.

Copy link
Member

@tadelesh tadelesh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall looks good. some impl optimization comments left.

const rootNamespaceName = diagnostics.pipe(getRootUserDefinedNamespaceName(context));
// if you've defined a namespace flag, we replace the root name with the flag
return diagnostics.wrap(
override.replace(rootNamespaceName, context.namespace || rootNamespaceName),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to judge undefined of context.namespace to prevent always find rootNamespaceName part.

Comment on lines +629 to +636
diagnostics.add(
createDiagnostic({
code: "unclear-namespace-overriding",
messageId: "default",
format: {},
target: context.program.getGlobalNamespaceType(),
}),
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we just report there is multiple user defined ns? i don't prefer couple this function with namespace override config.

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 this pull request may close these issues.

6 participants