Skip to content

Commit

Permalink
Closes #8586.
Browse files Browse the repository at this point in the history
  • Loading branch information
tjprescott committed Jul 9, 2024
1 parent 6094287 commit e4f429e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions tools/apiview/emitters/typespec-apiview/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Version 0.4.9 (07-09-2024)
Fix issue where "unknown" was rendered as "any".
Support value syntax for objects and arrays.
Support const statements in namespaces.

## Version 0.4.8 (04-18-2024)
Display suppressions in APIView.
Expand Down
15 changes: 14 additions & 1 deletion tools/apiview/emitters/typespec-apiview/src/apiview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
AugmentDecoratorStatementNode,
BaseNode,
BooleanLiteralNode,
ConstStatementNode,
DecoratorExpressionNode,
DirectiveExpressionNode,
EnumMemberNode,
Expand Down Expand Up @@ -447,7 +448,14 @@ export class ApiView {
case SyntaxKind.TypeSpecScript:
throw new Error(`Case "TypeSpecScript" not implemented`);
case SyntaxKind.ConstStatement:
throw new Error(`Case "ConstStatement" not implemented`);
obj = node as ConstStatementNode;
this.namespaceStack.push(obj.id.sv);
this.keyword("const", false, true);
this.tokenizeIdentifier(obj.id, "declaration");
this.punctuation("=", true, true);
this.tokenize(obj.value);
this.namespaceStack.pop();
break;
case SyntaxKind.DecoratorExpression:
obj = node as DecoratorExpressionNode;
this.punctuation("@", false, false);
Expand Down Expand Up @@ -1055,6 +1063,11 @@ export class ApiView {
this.punctuation(";");
this.blankLines(1);
}
for (const node of model.constants.values()) {
this.tokenize(node);
this.punctuation(";");
this.blankLines(1);
}
this.endGroup();
this.blankLines(1);
this.namespaceStack.pop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
DirectiveExpressionNode,
StringLiteralNode,
ObjectLiteralNode,
ConstStatementNode,
} from "@typespec/compiler";

export class NamespaceModel {
Expand Down Expand Up @@ -66,6 +67,7 @@ export class NamespaceModel {
>();
aliases = new Map<string, AliasStatementNode>();
augmentDecorators = new Array<AugmentDecoratorStatementNode>();
constants = new Array<ConstStatementNode>();

constructor(name: string, ns: Namespace, program: Program) {
this.name = name;
Expand Down Expand Up @@ -118,6 +120,11 @@ export class NamespaceModel {
this.augmentDecorators.push(augment);
}

// collect contants
for (const constant of findNodes(SyntaxKind.ConstStatement, program, ns)) {
this.constants.push(constant);
}

// sort operations and models
this.operations = new Map([...this.operations].sort(caseInsensitiveSort));
this.resources = new Map([...this.resources].sort(caseInsensitiveSort));
Expand Down

0 comments on commit e4f429e

Please sign in to comment.