Cleanup global namespace uses (#950)
This commit is contained in:
Родитель
eb955d2fd7
Коммит
f1fad76666
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"changes": [
|
||||
{
|
||||
"packageName": "@cadl-lang/compiler",
|
||||
"comment": "Api: `isGlobalNamespace` takes projection into account",
|
||||
"type": "patch"
|
||||
}
|
||||
],
|
||||
"packageName": "@cadl-lang/compiler"
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"changes": [
|
||||
{
|
||||
"packageName": "@cadl-lang/openapi",
|
||||
"comment": "Api: Operation id resolver takes projection into account",
|
||||
"type": "patch"
|
||||
}
|
||||
],
|
||||
"packageName": "@cadl-lang/openapi"
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"changes": [
|
||||
{
|
||||
"packageName": "@cadl-lang/rest",
|
||||
"comment": "Api: Route resolution take projection into account",
|
||||
"type": "patch"
|
||||
}
|
||||
],
|
||||
"packageName": "@cadl-lang/rest"
|
||||
}
|
|
@ -63,9 +63,15 @@ export function isTemplateDeclarationOrInstance(type: TemplatedType): boolean {
|
|||
return node.templateParameters && node.templateParameters.length > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given namespace is the global namespace
|
||||
* @param program Program
|
||||
* @param namespace Namespace
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function isGlobalNamespace(
|
||||
program: Program,
|
||||
namespace: Namespace
|
||||
): namespace is Namespace & { name: "" } {
|
||||
return program.checker.getGlobalNamespaceType() === namespace;
|
||||
): namespace is Namespace & { name: ""; namespace: undefined } {
|
||||
return program.getGlobalNamespaceType() === namespace;
|
||||
}
|
||||
|
|
|
@ -91,7 +91,7 @@ export function getServiceVersion(program: Program): string {
|
|||
|
||||
export function getServiceNamespace(program: Program): Namespace | undefined {
|
||||
const serviceDetails = getServiceDetails(program);
|
||||
return serviceDetails.namespace ?? program.checker.getGlobalNamespaceType();
|
||||
return serviceDetails.namespace ?? program.getGlobalNamespaceType();
|
||||
}
|
||||
|
||||
export function getServiceNamespaceString(program: Program): string | undefined {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import {
|
||||
getFriendlyName,
|
||||
getServiceNamespace,
|
||||
isGlobalNamespace,
|
||||
isTemplateInstance,
|
||||
ModelProperty,
|
||||
Operation,
|
||||
|
@ -122,7 +123,7 @@ export function resolveOperationId(program: Program, operation: Operation) {
|
|||
const namespace = operation.namespace;
|
||||
if (
|
||||
namespace === undefined ||
|
||||
namespace === program.checker.getGlobalNamespaceType() ||
|
||||
isGlobalNamespace(program, namespace) ||
|
||||
namespace === getServiceNamespace(program)
|
||||
) {
|
||||
return operation.name;
|
||||
|
|
|
@ -504,7 +504,7 @@ function getExternalInterfaces(program: Program, namespace: Namespace) {
|
|||
}
|
||||
return interfaces
|
||||
.map((interfaceFQN: string) => {
|
||||
let current: Namespace | undefined = program.checker.getGlobalNamespaceType();
|
||||
let current: Namespace | undefined = program.getGlobalNamespaceType();
|
||||
const namespaces = interfaceFQN.split(".");
|
||||
const interfaceName = namespaces.pop()!;
|
||||
for (const namespaceName of namespaces) {
|
||||
|
@ -545,7 +545,7 @@ export function reportIfNoRoutes(program: Program, routes: OperationDetails[]) {
|
|||
if (routes.length === 0) {
|
||||
reportDiagnostic(program, {
|
||||
code: "no-routes",
|
||||
target: program.checker.getGlobalNamespaceType(),
|
||||
target: program.getGlobalNamespaceType(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче