UNPKG

@azure-tools/typespec-apiview

Version:

Library for emitting APIView token files from TypeSpec

128 lines 6.33 kB
// These schemas are all adapted from the TypeSpec definition here: // https://github.com/Azure/azure-sdk-tools/blob/main/tools/apiview/parsers/apiview-treestyle-parser-schema/main.tsp import { SyntaxKind } from "@typespec/compiler/ast"; // CORE API VIEW SCHEMAS export var TokenKind; (function (TokenKind) { TokenKind[TokenKind["Text"] = 0] = "Text"; TokenKind[TokenKind["Punctuation"] = 1] = "Punctuation"; TokenKind[TokenKind["Keyword"] = 2] = "Keyword"; TokenKind[TokenKind["TypeName"] = 3] = "TypeName"; TokenKind[TokenKind["MemberName"] = 4] = "MemberName"; TokenKind[TokenKind["StringLiteral"] = 5] = "StringLiteral"; TokenKind[TokenKind["Literal"] = 6] = "Literal"; TokenKind[TokenKind["Comment"] = 7] = "Comment"; })(TokenKind || (TokenKind = {})); // CODE DIAGNOSTIC SCHEMAS export var CodeDiagnosticLevel; (function (CodeDiagnosticLevel) { CodeDiagnosticLevel[CodeDiagnosticLevel["Info"] = 1] = "Info"; CodeDiagnosticLevel[CodeDiagnosticLevel["Warning"] = 2] = "Warning"; CodeDiagnosticLevel[CodeDiagnosticLevel["Error"] = 3] = "Error"; /** Fatal level diagnostic will block API review approval and it will show an error message to the user. Approver will have to * override fatal level system comments before approving a review.*/ CodeDiagnosticLevel[CodeDiagnosticLevel["Fatal"] = 4] = "Fatal"; })(CodeDiagnosticLevel || (CodeDiagnosticLevel = {})); // NAVIGATION SCHEMAS export class NavigationItem { constructor(objNode, stack) { let obj; switch (objNode.kind) { case SyntaxKind.NamespaceStatement: stack.push(objNode.name); this.Text = objNode.name; this.Tags = { TypeKind: "namespace" /* ApiViewNavigationKind.Module */ }; const operationItems = new Array(); for (const node of objNode.operations.values()) { operationItems.push(new NavigationItem(node, stack)); } const resourceItems = new Array(); for (const node of objNode.resources.values()) { resourceItems.push(new NavigationItem(node, stack)); } const modelItems = new Array(); for (const node of objNode.models.values()) { modelItems.push(new NavigationItem(node, stack)); } const aliasItems = new Array(); for (const node of objNode.aliases.values()) { aliasItems.push(new NavigationItem(node, stack)); } this.ChildItems = []; if (operationItems.length) { this.ChildItems.push({ Text: "Operations", ChildItems: operationItems, Tags: { TypeKind: "method" /* ApiViewNavigationKind.Method */ }, NavigationId: "" }); } if (resourceItems.length) { this.ChildItems.push({ Text: "Resources", ChildItems: resourceItems, Tags: { TypeKind: "class" /* ApiViewNavigationKind.Class */ }, NavigationId: "" }); } if (modelItems.length) { this.ChildItems.push({ Text: "Models", ChildItems: modelItems, Tags: { TypeKind: "class" /* ApiViewNavigationKind.Class */ }, NavigationId: "" }); } if (aliasItems.length) { this.ChildItems.push({ Text: "Aliases", ChildItems: aliasItems, Tags: { TypeKind: "class" /* ApiViewNavigationKind.Class */ }, NavigationId: "" }); } break; case SyntaxKind.ModelStatement: obj = objNode; stack.push(obj.id.sv); this.Text = obj.id.sv; this.Tags = { TypeKind: "class" /* ApiViewNavigationKind.Class */ }; this.ChildItems = []; break; case SyntaxKind.EnumStatement: obj = objNode; stack.push(obj.id.sv); this.Text = obj.id.sv; this.Tags = { TypeKind: "enum" /* ApiViewNavigationKind.Enum */ }; this.ChildItems = []; break; case SyntaxKind.OperationStatement: obj = objNode; stack.push(obj.id.sv); this.Text = obj.id.sv; this.Tags = { TypeKind: "method" /* ApiViewNavigationKind.Method */ }; this.ChildItems = []; break; case SyntaxKind.InterfaceStatement: obj = objNode; stack.push(obj.id.sv); this.Text = obj.id.sv; this.Tags = { TypeKind: "method" /* ApiViewNavigationKind.Method */ }; this.ChildItems = []; for (const child of obj.operations) { this.ChildItems.push(new NavigationItem(child, stack)); } break; case SyntaxKind.UnionStatement: obj = objNode; stack.push(obj.id.sv); this.Text = obj.id.sv; this.Tags = { TypeKind: "enum" /* ApiViewNavigationKind.Enum */ }; this.ChildItems = []; break; case SyntaxKind.AliasStatement: obj = objNode; stack.push(obj.id.sv); this.Text = obj.id.sv; this.Tags = { TypeKind: "class" /* ApiViewNavigationKind.Class */ }; this.ChildItems = []; break; case SyntaxKind.ModelExpression: throw new Error(`Navigation unsupported for "ModelExpression".`); case SyntaxKind.IntersectionExpression: throw new Error(`Navigation unsupported for "IntersectionExpression".`); case SyntaxKind.ScalarStatement: obj = objNode; stack.push(obj.id.sv); this.Text = obj.id.sv; this.Tags = { TypeKind: "class" /* ApiViewNavigationKind.Class */ }; this.ChildItems = []; break; default: throw new Error(`Navigation unsupported for "${objNode.kind.toString()}".`); } this.NavigationId = stack.value(); stack.pop(); } } //# sourceMappingURL=schemas.js.map