diff --git a/.gitignore b/.gitignore index 57d04b2e371..5dce6d6e3a7 100644 --- a/.gitignore +++ b/.gitignore @@ -500,6 +500,8 @@ tools/oav-traffic-converter/build/ src/swift/*.xcworkspace/xcuserdata/ src/swift/**/*.xcodeproj/xcuserdata/ -# Cadl APIView -cadl-output/ -tools/apiview/emitters/cadl-apiview/temp/ \ No newline at end of file +# TypeSpec APIView +tools/apiview/emitters/cadl-apiview/cadl-output/ +tools/apiview/emitters/cadl-apiview/temp/ +tools/apiview/emitters/typespec-apiview/tsp-output/ +tools/apiview/emitters/typespec-apiview/temp/ \ No newline at end of file diff --git a/tools/apiview/emitters/cadl-apiview/.eslintrc.cjs b/tools/apiview/emitters/cadl-apiview/.eslintrc.cjs deleted file mode 100644 index 8ce089ccb78..00000000000 --- a/tools/apiview/emitters/cadl-apiview/.eslintrc.cjs +++ /dev/null @@ -1,6 +0,0 @@ -require("@cadl-lang/eslint-config-cadl/patch/modern-module-resolution"); - -module.exports = { - extends: "@cadl-lang/eslint-config-cadl", - parserOptions: { tsconfigRootDir: __dirname }, -}; diff --git a/tools/apiview/emitters/cadl-apiview/.prettierrc.yaml b/tools/apiview/emitters/cadl-apiview/.prettierrc.yaml deleted file mode 100644 index 544f4b35e98..00000000000 --- a/tools/apiview/emitters/cadl-apiview/.prettierrc.yaml +++ /dev/null @@ -1,8 +0,0 @@ -trailingComma: "all" -printWidth: 120 -quoteProps: "consistent" -endOfLine: lf -arrowParens: always -plugins: - - "./node_modules/@cadl-lang/prettier-plugin-cadl" -overrides: [{ "files": "*.cadl", "options": { "parser": "cadl" } }] diff --git a/tools/apiview/emitters/cadl-apiview/src/testing/index.ts b/tools/apiview/emitters/cadl-apiview/src/testing/index.ts deleted file mode 100644 index 07a6d3bac90..00000000000 --- a/tools/apiview/emitters/cadl-apiview/src/testing/index.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { resolvePath } from "@cadl-lang/compiler"; -import { CadlTestLibrary } from "@cadl-lang/compiler/testing"; -import { fileURLToPath } from "url"; - -export const ApiViewTestLibrary: CadlTestLibrary = { - name: "@azure-tools/cadl-apiview", - packageRoot: resolvePath(fileURLToPath(import.meta.url), "../../../../"), - files: [ - { - realDir: "", - pattern: "package.json", - virtualPath: "./node_modules/@azure-tools/cadl-apiview", - }, - { - realDir: "dist/src", - pattern: "*.js", - virtualPath: "./node_modules/@azure-tools/cadl-apiview/dist/src", - }, - ], -}; diff --git a/tools/apiview/emitters/cadl-apiview/src/version.ts b/tools/apiview/emitters/cadl-apiview/src/version.ts deleted file mode 100644 index 633c84a9da6..00000000000 --- a/tools/apiview/emitters/cadl-apiview/src/version.ts +++ /dev/null @@ -1 +0,0 @@ -export const LIB_VERSION = "0.3.5"; diff --git a/tools/apiview/emitters/cadl-apiview/.c8rc.json b/tools/apiview/emitters/typespec-apiview/.c8rc.json similarity index 100% rename from tools/apiview/emitters/cadl-apiview/.c8rc.json rename to tools/apiview/emitters/typespec-apiview/.c8rc.json diff --git a/tools/apiview/emitters/typespec-apiview/.eslintrc.cjs b/tools/apiview/emitters/typespec-apiview/.eslintrc.cjs new file mode 100644 index 00000000000..a02edcee2a1 --- /dev/null +++ b/tools/apiview/emitters/typespec-apiview/.eslintrc.cjs @@ -0,0 +1,6 @@ +require("@typespec/eslint-config-typespec/patch/modern-module-resolution"); + +module.exports = { + extends: "@typespec/eslint-config-typespec", + parserOptions: { tsconfigRootDir: __dirname }, +}; diff --git a/tools/apiview/emitters/cadl-apiview/.mocharc.yaml b/tools/apiview/emitters/typespec-apiview/.mocharc.yaml similarity index 100% rename from tools/apiview/emitters/cadl-apiview/.mocharc.yaml rename to tools/apiview/emitters/typespec-apiview/.mocharc.yaml diff --git a/tools/apiview/emitters/cadl-apiview/.prettierignore b/tools/apiview/emitters/typespec-apiview/.prettierignore similarity index 100% rename from tools/apiview/emitters/cadl-apiview/.prettierignore rename to tools/apiview/emitters/typespec-apiview/.prettierignore diff --git a/tools/apiview/emitters/typespec-apiview/.prettierrc.yaml b/tools/apiview/emitters/typespec-apiview/.prettierrc.yaml new file mode 100644 index 00000000000..e19c948bb5e --- /dev/null +++ b/tools/apiview/emitters/typespec-apiview/.prettierrc.yaml @@ -0,0 +1,8 @@ +trailingComma: "all" +printWidth: 120 +quoteProps: "consistent" +endOfLine: lf +arrowParens: always +plugins: + - "./node_modules/@typespec/prettier-plugin-typespec" +overrides: [{ "files": "*.tsp", "options": { "parser": "typespec" } }] diff --git a/tools/apiview/emitters/cadl-apiview/CHANGELOG.md b/tools/apiview/emitters/typespec-apiview/CHANGELOG.md similarity index 95% rename from tools/apiview/emitters/cadl-apiview/CHANGELOG.md rename to tools/apiview/emitters/typespec-apiview/CHANGELOG.md index 6b12380fa64..0c78840998e 100644 --- a/tools/apiview/emitters/cadl-apiview/CHANGELOG.md +++ b/tools/apiview/emitters/typespec-apiview/CHANGELOG.md @@ -1,6 +1,9 @@ # Release History -## Version 0.3.5 (Unreleased) +## Version 0.4.0 (03-06-2023) +Update for rename of Cadl to TypeSpec. + +## Version 0.3.5 (02-10-2023) Support latest release of Cadl compiler. **BREAKING CHANGE**: Removed the `--namespace` emitter option. Added the `--service` emitter option to support filtering output for multi-service specs. diff --git a/tools/apiview/emitters/cadl-apiview/README.md b/tools/apiview/emitters/typespec-apiview/README.md similarity index 55% rename from tools/apiview/emitters/cadl-apiview/README.md rename to tools/apiview/emitters/typespec-apiview/README.md index 7157d0ae539..b99c736f75f 100644 --- a/tools/apiview/emitters/cadl-apiview/README.md +++ b/tools/apiview/emitters/typespec-apiview/README.md @@ -1,26 +1,26 @@ -# Cadl APIView Emitter +# TypeSpec APIView Emitter -This package provides the [Cadl](https://github.com/microsoft/cadl) emitter to produce APIView token file output from Cadl source. +This package provides the [TypeSpec](https://github.com/microsoft/typespec) emitter to produce APIView token file output from TypeSpec source. ## Install -Add `@azure-tools/cadl-apiview` to your `package.json` and run `npm install`. +Add `@azure-tools/typespec-apiview` to your `package.json` and run `npm install`. ## Emit APIView spec 1. Via the command line ```bash -cadl compile {path to cadl project} --emit=@azure-tools/cadl-apiview +tsc compile {path to typespec project} --emit=@azure-tools/typespec-apiview ``` 2. Via the config -Add the following to the `cadl-project.yaml` file. +Add the following to the `typespec-project.yaml` file. ```yaml emitters: - @azure-tools/cadl-apiview: true + @azure-tools/typespec-apiview: true ``` For configuration [see options](#emitter-options) @@ -29,7 +29,7 @@ For configuration [see options](#emitter-options) 1. Log in to the API View site (apiview.dev)[https://apiview.dev]. 2. Click the blue "Create Review" button in the bottom-right corner of the screen. -3. In the first block, load the token file generated by the `cadl-apiview` emitter. +3. In the first block, load the token file generated by the `typespec-apiview` emitter. ## Revise API View @@ -37,7 +37,7 @@ For configuration [see options](#emitter-options) 2. Navigate to your review. 3. Click the "Revisions" tab in the top left. 4. Click the blue "Add Revision" button in the bottom-right corner of the screen. -5. In the first block, load the token file generated by the `cadl-apiview` emitter. +5. In the first block, load the token file generated by the `typespec-apiview` emitter. ## Use APIView-specific decorators: @@ -45,37 +45,37 @@ Currently there are no APIView-specific decorators... ## Emitter options: -Emitter options can be configured via the `cadl-project.yaml` configuration: +Emitter options can be configured via the `tspconfig.yaml` configuration: ```yaml emitters: - '@azure-tools/cadl-apiview': + '@azure-tools/typespec-apiview': : # For example emitters: - '@azure-tools/cadl-apiview': + '@azure-tools/typespec-apiview': output-file: my-custom-apiview.json ``` or via the command line with ```bash ---option "@azure-tools/cadl-apiview.=" +--option "@azure-tools/typespec-apiview.=" # For example ---option "@azure-tools/cadl-apiview.output-file=my-custom-apiview.json" +--option "@azure-tools/typespec-apiview.output-file=my-custom-apiview.json" ``` ### `emitter-output-dir` -Configure the name of the output directory. Default is `cadl-output/@azure-tools/cadl-apiview`. +Configure the name of the output directory. Default is `tsc-output/@azure-tools/typespec-apiview`. ### `include-global-namespace` Normally, APIView will filter all namespaces and only output those in the service namespace and any -subnamespaces. This is to filter out types that come from the Cadl compiler and supporting libraries. +subnamespaces. This is to filter out types that come from the TypeSpec compiler and supporting libraries. This setting, if `true`, tells APIView to output the contents of the global (empty) namespace, which would normally be excluded. @@ -93,13 +93,13 @@ all services in a multi-service spec, the output filename will be the service ro ### `version` -For multi-versioned Cadl specs, this parameter is used to control which version to emit. This -is not required for single-version specs. For multi-versioned specs, the unprojected Cadl will +For multi-versioned TypeSpec, this parameter is used to control which version to emit. This +is not required for single-version specs. For multi-versioned specs, the unprojected TypeSpec will be rendered if this is not supplied. For multi-service specs, this option cannot be supplied unless the `service` option is also set. ## See also -- [Cadl Getting Started](https://github.com/microsoft/cadl#getting-started) -- [Cadl Tutorial](https://github.com/microsoft/cadl/blob/main/docs/tutorial.md) -- [Cadl for the OpenAPI Developer](https://github.com/microsoft/cadl/blob/main/docs/cadl-for-openapi-dev.md) +- [TypeSpec Getting Started](https://github.com/microsoft/typespec#getting-started) +- [TypeSpec Tutorial](https://github.com/microsoft/typespec/blob/main/docs/tutorial.md) +- [TypeSpec for the OpenAPI Developer](https://github.com/microsoft/typespec/blob/main/docs/typespec-for-openapi-dev.md) diff --git a/tools/apiview/emitters/cadl-apiview/ci.yml b/tools/apiview/emitters/typespec-apiview/ci.yml similarity index 77% rename from tools/apiview/emitters/cadl-apiview/ci.yml rename to tools/apiview/emitters/typespec-apiview/ci.yml index b35909715be..0dc2d7d4de5 100644 --- a/tools/apiview/emitters/cadl-apiview/ci.yml +++ b/tools/apiview/emitters/typespec-apiview/ci.yml @@ -8,7 +8,7 @@ trigger: - hotfix/* paths: include: - - tools/apiview/emitters/cadl-apiview + - tools/apiview/emitters/typespec-apiview pr: branches: @@ -19,11 +19,11 @@ pr: - hotfix/* paths: include: - - tools/apiview/emitters/cadl-apiview + - tools/apiview/emitters/typespec-apiview variables: NodeVersion: '16.x' - CadlEmitterDirectory: 'tools/apiview/emitters/cadl-apiview' + TypeSpecEmitterDirectory: 'tools/apiview/emitters/typespec-apiview' ArtifactName: 'apiview' FeedRegistry: 'https://registry.npmjs.org/' @@ -44,23 +44,23 @@ stages: - script: | npm install - workingDirectory: $(CadlEmitterDirectory) - displayName: "Install npm packages for CADL emiter" + workingDirectory: $(TypeSpecEmitterDirectory) + displayName: "Install npm packages for TypeSpec emiter" - script: | npm run-script build - workingDirectory: $(CadlEmitterDirectory) - displayName: "Build CADL emitter" + workingDirectory: $(TypeSpecEmitterDirectory) + displayName: "Build TypeSpec emitter" - script: | npm run-script test - workingDirectory: $(CadlEmitterDirectory) - displayName: "Test CADL emitter" + workingDirectory: $(TypeSpecEmitterDirectory) + displayName: "Test TypeSpec emitter" - pwsh: | - npm pack $(CadlEmitterDirectory) + npm pack $(TypeSpecEmitterDirectory) Copy-Item ./*.tgz $(Build.ArtifactStagingDirectory) - displayName: "Pack CADL Emitter" + displayName: "Pack TypeSpec Emitter" - task: PublishBuildArtifacts@1 inputs: @@ -73,7 +73,7 @@ stages: condition: Succeeded() jobs: - job: PublishPackage - displayName: 'Publish cadl-apiview package to devops feed' + displayName: 'Publish typespec-apiview package to devops feed' pool: name: azsdk-pool-mms-ubuntu-2204-general vmImage: MMSUbuntu22.04 diff --git a/tools/apiview/emitters/cadl-apiview/cspell.yaml b/tools/apiview/emitters/typespec-apiview/cspell.yaml similarity index 93% rename from tools/apiview/emitters/cadl-apiview/cspell.yaml rename to tools/apiview/emitters/typespec-apiview/cspell.yaml index 76aaf687b3a..7081335ee16 100644 --- a/tools/apiview/emitters/cadl-apiview/cspell.yaml +++ b/tools/apiview/emitters/typespec-apiview/cspell.yaml @@ -10,7 +10,7 @@ words: - azurecr - blockful - blockless - - cadl + - typespec - Contoso - CRUDL - devdriven @@ -58,10 +58,11 @@ words: - vswhere - westus - xplat + - deindent ignorePaths: - "**/node_modules/**" - "**/dist/**" - "**/dist-dev/**" - - "**/cadl-output/**" + - "**/tsp-output/**" enableFiletypes: - - cadl \ No newline at end of file + - tsp \ No newline at end of file diff --git a/tools/apiview/emitters/cadl-apiview/package.json b/tools/apiview/emitters/typespec-apiview/package.json similarity index 68% rename from tools/apiview/emitters/cadl-apiview/package.json rename to tools/apiview/emitters/typespec-apiview/package.json index 0950984ac6e..47611b496c5 100644 --- a/tools/apiview/emitters/cadl-apiview/package.json +++ b/tools/apiview/emitters/typespec-apiview/package.json @@ -1,8 +1,8 @@ { - "name": "@azure-tools/cadl-apiview", - "version": "0.3.5", + "name": "@azure-tools/typespec-apiview", + "version": "0.4.0", "author": "Microsoft Corporation", - "description": "Cadl library for emitting APIView token files from Cadl specifications", + "description": "Library for emitting APIView token files from TypeSpec", "homepage": "https://github.com/Azure/azure-sdk-tools", "readme": "https://github.com/Azure/azure-sdk-tools/blob/master/README.md", "license": "MIT", @@ -14,7 +14,7 @@ "url": "https://github.com/Azure/azure-sdk-tools/issues" }, "keywords": [ - "cadl", + "typespec", "apiview" ], "type": "module", @@ -33,39 +33,39 @@ ] } }, - "cadlMain": "dist/src/index.js", + "tspMain": "dist/src/index.js", "engines": { "node": ">=16.0.0" }, "scripts": { "clean": "rimraf ./dist ./temp", "prebuild": "node -p \"'export const LIB_VERSION = ' + JSON.stringify(require('./package.json').version) + ';'\" > src/version.ts", - "build": "npm run prebuild && tsc -p . && npm run lint-cadl-library", + "build": "npm run prebuild && tsc -p . && npm run lint-typespec-library", "watch": "tsc -p . --watch", - "lint-cadl-library": "cadl compile . --warn-as-error --import @cadl-lang/library-linter --no-emit", + "lint-typespec-library": "tsp compile . --warn-as-error --import @typespec/library-linter --no-emit", "test": "mocha", "test-official": "c8 mocha --forbid-only --reporter mocha-multi-reporters", "lint": "eslint . --ext .ts --max-warnings=0", "lint:fix": "eslint . --fix --ext .ts" }, "files": [ - "lib/*.cadl", + "lib/*.tsp", "dist/**", "!dist/test/**" ], "dependencies": { - "@azure-tools/cadl-azure-core": "0.26.0", - "@azure-tools/cadl-autorest": "0.26.0", - "@azure-tools/cadl-dpg": "latest", - "@cadl-lang/compiler": "0.40.0", - "@cadl-lang/rest": "latest", - "@cadl-lang/versioning": "latest" + "@azure-tools/typespec-azure-core": "0.27.0", + "@azure-tools/typespec-autorest": "0.27.0", + "@typespec/compiler": "0.41.0", + "@typespec/http": "0.41.0", + "@typespec/rest": "0.41.0", + "@typespec/versioning": "0.41.0" }, "devDependencies": { - "@cadl-lang/eslint-plugin": "~0.40.0", - "@cadl-lang/library-linter": "~0.40.0", - "@cadl-lang/prettier-plugin-cadl": "^0.40.0", - "@cadl-lang/eslint-config-cadl": "~0.4.1", + "@typespec/eslint-plugin": "~0.41.0", + "@typespec/library-linter": "~0.41.0", + "@typespec/prettier-plugin-typespec": "^0.41.0", + "@typespec/eslint-config-typespec": "~0.6.0", "@types/mocha": "~9.1.0", "@types/node": "~16.0.3", "@changesets/cli": "^2.24.4", diff --git a/tools/apiview/emitters/cadl-apiview/src/apiview.ts b/tools/apiview/emitters/typespec-apiview/src/apiview.ts similarity index 94% rename from tools/apiview/emitters/cadl-apiview/src/apiview.ts rename to tools/apiview/emitters/typespec-apiview/src/apiview.ts index a103706b2bc..c4f3dd71890 100644 --- a/tools/apiview/emitters/cadl-apiview/src/apiview.ts +++ b/tools/apiview/emitters/typespec-apiview/src/apiview.ts @@ -9,6 +9,7 @@ import { EnumSpreadMemberNode, EnumStatementNode, getNamespaceFullName, + getSourceLocation, IdentifierNode, InterfaceStatementNode, IntersectionExpressionNode, @@ -33,7 +34,7 @@ import { UnionExpressionNode, UnionStatementNode, UnionVariantNode, -} from "@cadl-lang/compiler"; +} from "@typespec/compiler"; import { ApiViewDiagnostic, ApiViewDiagnosticLevel } from "./diagnostic.js"; import { ApiViewNavigation } from "./navigation.js"; import { generateId, NamespaceModel } from "./namespace-model.js"; @@ -130,7 +131,7 @@ export class ApiView { trim() { let last = this.tokens[this.tokens.length - 1] while (last) { - if (last.Kind == ApiViewTokenKind.Whitespace) { + if (last.Kind === ApiViewTokenKind.Whitespace) { this.tokens.pop(); last = this.tokens[this.tokens.length - 1]; } else { @@ -159,7 +160,7 @@ export class ApiView { } space() { - if (this.tokens[this.tokens.length - 1]?.Kind != ApiViewTokenKind.Whitespace) { + if (this.tokens[this.tokens.length - 1]?.Kind !== ApiViewTokenKind.Whitespace) { this.tokens.push({ Kind: ApiViewTokenKind.Whitespace, Value: WHITESPACE, @@ -182,9 +183,9 @@ export class ApiView { let newlineCount: number = 0; for (let i = this.tokens.length; i > 0; i--) { const token = this.tokens[i - 1]; - if (token.Kind == ApiViewTokenKind.Newline) { + if (token.Kind === ApiViewTokenKind.Newline) { newlineCount++; - } else if (token.Kind == ApiViewTokenKind.Whitespace) { + } else if (token.Kind === ApiViewTokenKind.Whitespace) { continue; } else { break; @@ -201,7 +202,7 @@ export class ApiView { let toRemove = newlineCount - (count + 1); while (toRemove) { const popped = this.tokens.pop(); - if (popped?.Kind == ApiViewTokenKind.Newline) { + if (popped?.Kind === ApiViewTokenKind.Newline) { toRemove--; } } @@ -281,7 +282,7 @@ export class ApiView { stringLiteral(value: string) { const lines = value.split("\n"); - if (lines.length == 1) { + if (lines.length === 1) { this.tokens.push({ Kind: ApiViewTokenKind.StringLiteral, Value: `\u0022${value}\u0022`, @@ -343,7 +344,7 @@ export class ApiView { continue; } // use a fake name to make the global namespace clear - const namespaceName = name == "" ? "::GLOBAL::" : name; + const namespaceName = name === "" ? "::GLOBAL::" : name; const nsModel = new NamespaceModel(namespaceName, ns, program); if (nsModel.shouldEmit()) { this.tokenizeNamespaceModel(nsModel); @@ -354,7 +355,7 @@ export class ApiView { private emitHeader() { const toolVersion = LIB_VERSION; - const headerText = `// Package parsed using @azure-tools/cadl-apiview (version:${toolVersion})`; + const headerText = `// Package parsed using @azure-tools/typespec-apiview (version:${toolVersion})`; this.token(ApiViewTokenKind.SkipDiffRangeStart); this.literal(headerText); this.namespaceStack.push("GLOBAL"); @@ -399,7 +400,7 @@ export class ApiView { for (let x = 0; x < obj.arguments.length; x++) { const arg = obj.arguments[x]; this.tokenize(arg); - if (x != last) { + if (x !== last) { this.punctuation(",", false, true); } } @@ -413,8 +414,8 @@ export class ApiView { break; case SyntaxKind.BlockComment: throw new Error(`Case "BlockComment" not implemented`); - case SyntaxKind.CadlScript: - throw new Error(`Case "CadlScript" not implemented`); + case SyntaxKind.TypeSpecScript: + throw new Error(`Case "TypeSpecScript" not implemented`); case SyntaxKind.DecoratorExpression: obj = node as DecoratorExpressionNode; this.punctuation("@", false, false); @@ -426,7 +427,7 @@ export class ApiView { for (let x = 0; x < obj.arguments.length; x++) { const arg = obj.arguments[x]; this.tokenize(arg); - if (x != last) { + if (x !== last) { this.punctuation(",", false, true); } } @@ -442,7 +443,7 @@ export class ApiView { this.tokenizeDecorators(obj.decorators, false); this.tokenizeIdentifier(obj.id, "member"); this.lineMarker(); - if (obj.value != undefined) { + if (obj.value) { this.punctuation(":", false, true); this.tokenize(obj.value); } @@ -470,7 +471,7 @@ export class ApiView { for (let x = 0; x < obj.options.length; x++) { const opt = obj.options[x]; this.tokenize(opt); - if (x != obj.options.length - 1) { + if (x !== obj.options.length - 1) { this.punctuation("&", true, true); } } @@ -539,11 +540,11 @@ export class ApiView { case SyntaxKind.TemplateParameterDeclaration: obj = node as TemplateParameterDeclarationNode; this.tokenize(obj.id); - if (obj.constraint != undefined) { + if (obj.constraint) { this.keyword("extends", true, true); this.tokenize(obj.constraint); } - if (obj.default != undefined) { + if (obj.default) { this.punctuation("=", true, true); this.tokenize(obj.default); } @@ -554,7 +555,7 @@ export class ApiView { for (let x = 0; x < obj.values.length; x++) { const val = obj.values[x]; this.tokenize(val); - if (x != obj.values.length - 1) { + if (x !== obj.values.length - 1) { this.renderPunctuation(","); } } @@ -568,7 +569,7 @@ export class ApiView { for (let x = 0; x < obj.arguments.length; x++) { const arg = obj.arguments[x]; this.tokenize(arg); - if (x != obj.arguments.length - 1) { + if (x !== obj.arguments.length - 1) { this.renderPunctuation(","); } } @@ -580,7 +581,7 @@ export class ApiView { for (let x = 0; x < obj.options.length; x++) { const opt = obj.options[x]; this.tokenize(opt); - if (x != obj.options.length -1) { + if (x !== obj.options.length -1) { this.punctuation("|", true, true); } } @@ -610,11 +611,11 @@ export class ApiView { this.tokenizeDecorators(node.decorators, false); this.keyword("model", false, true); this.tokenizeIdentifier(node.id, "declaration"); - if (node.extends != undefined) { + if (node.extends) { this.keyword("extends", true, true); this.tokenize(node.extends); } - if (node.is != undefined) { + if (node.is) { this.keyword("is", true, true); this.tokenize(node.is); } @@ -641,7 +642,7 @@ export class ApiView { this.tokenizeDecorators(node.decorators, false); this.keyword("scalar", false, true); this.tokenizeIdentifier(node.id, "declaration"); - if (node.extends != undefined) { + if (node.extends) { this.keyword("extends", true, true); this.tokenize(node.extends); } @@ -660,7 +661,7 @@ export class ApiView { for (let x = 0; x < node.operations.length; x++) { const op = node.operations[x]; this.tokenizeOperationStatement(op, true); - this.blankLines((x != node.operations.length -1) ? 1 : 0); + this.blankLines((x !== node.operations.length -1) ? 1 : 0); } this.endGroup(); this.namespaceStack.pop(); @@ -696,7 +697,7 @@ export class ApiView { this.namespaceStack.push(variantName); this.tokenize(variant); this.namespaceStack.pop(); - if (x != node.options.length - 1) { + if (x !== node.options.length - 1) { this.punctuation(","); } this.blankLines(0); @@ -719,7 +720,7 @@ export class ApiView { this.lineMarker(); this.punctuation(node.optional ? "?:" : ":", false, true); this.tokenize(node.value); - if (node.default != undefined) { + if (node.default) { this.punctuation("=", true, true); this.tokenize(node.default); } @@ -741,7 +742,7 @@ export class ApiView { break; } if (isOperationSignature) { - if (x != node.properties.length - 1) { + if (x !== node.properties.length - 1) { this.punctuation(",", false, true); } } else { @@ -777,7 +778,7 @@ export class ApiView { } this.namespaceStack.pop(); if (isOperationSignature) { - if (x != node.properties.length - 1) { + if (x !== node.properties.length - 1) { this.renderPunctuation(","); } } else { @@ -861,7 +862,7 @@ export class ApiView { if (!inline && nodes.length) { while (this.tokens.length) { const item = this.tokens.pop()!; - if (item.Kind == ApiViewTokenKind.LineIdMarker && item.DefinitionId == "GLOBAL") { + if (item.Kind === ApiViewTokenKind.LineIdMarker && item.DefinitionId === "GLOBAL") { this.tokens.push(item); this.blankLines(2); break; @@ -930,7 +931,7 @@ export class ApiView { } break; case SyntaxKind.StringLiteral: - if (style != "member") { + if (style !== "member") { throw new Error(`StringLiteral type can only be a member name. Unexpectedly "${style}"`); } this.stringLiteral(node.value); @@ -945,7 +946,7 @@ export class ApiView { this.typeReference(node.sv, defId); break; case "member": - this.member(node.sv); + this.member(this.getRawText(node)); break; case "keyword": this.keyword(node.sv) @@ -954,13 +955,18 @@ export class ApiView { } } + private getRawText(node: IdentifierNode): string { + return getSourceLocation(node).file.text.slice(node.pos, node.end); + } + + private tokenizeTemplateParameters(nodes: readonly TemplateParameterDeclarationNode[]) { if (nodes.length) { this.punctuation("<", false, false); for (let x = 0; x < nodes.length; x++) { const param = nodes[x]; this.tokenize(param); - if (x != nodes.length - 1) { + if (x !== nodes.length - 1) { this.renderPunctuation(","); this.space(); } @@ -990,27 +996,27 @@ export class ApiView { private getNameForNode(node: BaseNode | NamespaceModel): string { const id = generateId(node); - if (id != undefined) { + if (id) { return id.split(".").splice(-1)[0]; } else { throw new Error("Unable to get name for node."); } } - private renderPunctuation(punc: string) { + private renderPunctuation(punctuation: string) { const last = this.tokens.pop()!; - if (last?.Kind == ApiViewTokenKind.Whitespace) { + if (last?.Kind === ApiViewTokenKind.Whitespace) { // hacky workaround to ensure comma is after trailing bracket for expanded anonymous models this.tokens.pop(); } else { this.tokens.push(last); } - this.punctuation(punc, false, true); + this.punctuation(punctuation, false, true); } resolveMissingTypeReferences() { for (const token of this.tokens) { - if (token.Kind == ApiViewTokenKind.TypeName && token.NavigateToId == "__MISSING__") { + if (token.Kind === ApiViewTokenKind.TypeName && token.NavigateToId === "__MISSING__") { token.NavigateToId = this.definitionIdFor(token.Value!, this.packageName); } } @@ -1024,7 +1030,7 @@ export class ApiView { Navigation: this.navigationItems, Diagnostics: this.diagnostics, VersionString: this.versionString, - Language: "Cadl" + Language: "TypeSpec" }; } @@ -1034,7 +1040,7 @@ export class ApiView { return this.typeDeclarations.has(fullName) ? fullName : undefined; } for (const item of this.typeDeclarations) { - if (item.split(".").splice(-1)[0] == value) { + if (item.split(".").splice(-1)[0] === value) { return item; } } diff --git a/tools/apiview/emitters/cadl-apiview/src/diagnostic.ts b/tools/apiview/emitters/typespec-apiview/src/diagnostic.ts similarity index 100% rename from tools/apiview/emitters/cadl-apiview/src/diagnostic.ts rename to tools/apiview/emitters/typespec-apiview/src/diagnostic.ts diff --git a/tools/apiview/emitters/cadl-apiview/src/emitter.ts b/tools/apiview/emitters/typespec-apiview/src/emitter.ts similarity index 90% rename from tools/apiview/emitters/cadl-apiview/src/emitter.ts rename to tools/apiview/emitters/typespec-apiview/src/emitter.ts index 09e0f7322b9..b4e844c5353 100644 --- a/tools/apiview/emitters/cadl-apiview/src/emitter.ts +++ b/tools/apiview/emitters/typespec-apiview/src/emitter.ts @@ -1,5 +1,3 @@ -// See: https://cadlwebsite.z1.web.core.windows.net/docs/extending-cadl/emitters-basics - import { EmitContext, emitFile, @@ -12,8 +10,8 @@ import { projectProgram, resolvePath, Service, -} from "@cadl-lang/compiler"; -import { buildVersionProjections, getVersion } from "@cadl-lang/versioning"; +} from "@typespec/compiler"; +import { buildVersionProjections, getVersion } from "@typespec/versioning"; import path from "path"; import { ApiView } from "./apiview.js"; import { ApiViewEmitterOptions, reportDiagnostic } from "./lib.js"; @@ -47,7 +45,7 @@ export function resolveOptions(context: EmitContext): Res function resolveNamespaceString(namespace: Namespace): string | undefined { // FIXME: Fix this wonky workaround when getNamespaceString is fixed. const value = getNamespaceFullName(namespace); - return value == "" ? undefined : value; + return value === "" ? undefined : value; } // TODO: Up-level this logic? @@ -55,12 +53,12 @@ function resolveAllowedVersions(program: Program, service: Service): string[] { const allowed: string[] = []; const serviceVersion = service.version; const versions = getVersion(program, service.type)?.getVersions(); - if (serviceVersion != undefined && versions != undefined) { + if (serviceVersion !== undefined && versions !== undefined) { throw new Error("Cannot have serviceVersion with multi-API."); } - if (serviceVersion != undefined) { + if (serviceVersion !== undefined) { allowed.push(serviceVersion); - } else if (versions != undefined) { + } else if (versions !== undefined) { for (const item of versions) { allowed.push(item.name); } @@ -73,7 +71,7 @@ function resolveAllowedVersions(program: Program, service: Service): string[] { function resolveVersionValue(program: Program, namespace: Namespace, version: string): string { try { const versions = getVersion(program, namespace)!.getVersions(); - return versions.filter((item) => item.name == version).map((item) => item.value)[0]; + return versions.filter((item) => item.name === version).map((item) => item.value)[0]; } catch { return version; } @@ -84,8 +82,8 @@ function resolveProgramForVersion(program: Program, namespace: Namespace, versio return program; } const version = resolveVersionValue(program, namespace, versionKey); - const projections = buildVersionProjections(program, namespace).filter((item) => item.version == version); - if (projections.length == 0) { + const projections = buildVersionProjections(program, namespace).filter((item) => item.version === version); + if (projections.length === 0) { // non-multi-version scenario. Return original program. return program; } else { @@ -156,7 +154,7 @@ function createApiViewEmitter(program: Program, options: ResolvedApiViewEmitterO return; } // applies the default "apiview.json" filename if not provided and there's only a single service - if (services.length == 1) { + if (services.length === 1) { options.outputFile = options.outputFile ?? "apiview.json" } validateMultiServiceOptions(program, services, options); @@ -168,7 +166,7 @@ function createApiViewEmitter(program: Program, options: ResolvedApiViewEmitterO const serviceTitle = service.title ? service.title : namespaceString; const allowedVersions = resolveAllowedVersions(program, service); if (versionString) { - if (allowedVersions.filter((version) => version == versionString).length == 0) { + if (allowedVersions.filter((version) => version === versionString).length === 0) { reportDiagnostic(program, { code: "version-not-found", target: NoTarget, diff --git a/tools/apiview/emitters/cadl-apiview/src/index.ts b/tools/apiview/emitters/typespec-apiview/src/index.ts similarity index 100% rename from tools/apiview/emitters/cadl-apiview/src/index.ts rename to tools/apiview/emitters/typespec-apiview/src/index.ts diff --git a/tools/apiview/emitters/cadl-apiview/src/lib.ts b/tools/apiview/emitters/typespec-apiview/src/lib.ts similarity index 89% rename from tools/apiview/emitters/cadl-apiview/src/lib.ts rename to tools/apiview/emitters/typespec-apiview/src/lib.ts index a2e613b90e3..8c6b55f7951 100644 --- a/tools/apiview/emitters/cadl-apiview/src/lib.ts +++ b/tools/apiview/emitters/typespec-apiview/src/lib.ts @@ -1,4 +1,4 @@ -import { createCadlLibrary, JSONSchemaType, paramMessage } from "@cadl-lang/compiler"; +import { createTypeSpecLibrary, JSONSchemaType, paramMessage } from "@typespec/compiler"; export interface ApiViewEmitterOptions { "output-file"?: string; @@ -20,8 +20,8 @@ const ApiViewEmitterOptionsSchema: JSONSchemaType = { }; -export const $lib = createCadlLibrary({ - name: "@azure-tools/cadl-apiview", +export const $lib = createTypeSpecLibrary({ + name: "@azure-tools/typespec-apiview", diagnostics: { "no-services-found": { severity: "error", diff --git a/tools/apiview/emitters/cadl-apiview/src/namespace-model.ts b/tools/apiview/emitters/typespec-apiview/src/namespace-model.ts similarity index 89% rename from tools/apiview/emitters/cadl-apiview/src/namespace-model.ts rename to tools/apiview/emitters/typespec-apiview/src/namespace-model.ts index 06eeaf95436..991916980d7 100644 --- a/tools/apiview/emitters/cadl-apiview/src/namespace-model.ts +++ b/tools/apiview/emitters/typespec-apiview/src/namespace-model.ts @@ -26,7 +26,7 @@ import { Node, visitChildren, ScalarStatementNode, -} from "@cadl-lang/compiler"; +} from "@typespec/compiler"; export class NamespaceModel { kind = SyntaxKind.NamespaceStatement; @@ -73,10 +73,10 @@ export class NamespaceModel { // Gather models and resources for (const [modelName, model] of ns.models) { - if (model.node != undefined) { + if (model.node !== undefined) { let isResource = false; for (const dec of model.decorators) { - if (dec.decorator.name == "$resource") { + if (dec.decorator.name === "$resource") { isResource = true; break; } @@ -144,7 +144,7 @@ function inNamespace(node: Node, program: Program, namespace: Namespace): boolea switch (n.kind) { case SyntaxKind.NamespaceStatement: return program.checker.getTypeForNode(n) === namespace; - case SyntaxKind.CadlScript: + case SyntaxKind.TypeSpecScript: if (n.inScopeNamespaces.length > 0 && inNamespace(n.inScopeNamespaces[0], program, namespace)) { return true; } @@ -156,7 +156,7 @@ function inNamespace(node: Node, program: Program, namespace: Namespace): boolea export function generateId(obj: BaseNode | NamespaceModel | undefined): string | undefined { let node; - if (obj == undefined) { + if (obj === undefined) { return undefined; } if (obj instanceof NamespaceModel) { @@ -181,14 +181,7 @@ export function generateId(obj: BaseNode | NamespaceModel | undefined): string | break; case SyntaxKind.EnumMember: node = obj as EnumMemberNode; - switch (node.id.kind) { - case SyntaxKind.Identifier: - name = node.id.sv; - break; - case SyntaxKind.StringLiteral: - name = node.id.value; - break; - } + name = node.id.sv; parentId = generateId(node.parent); break; case SyntaxKind.EnumSpreadMember: @@ -214,14 +207,7 @@ export function generateId(obj: BaseNode | NamespaceModel | undefined): string | break; case SyntaxKind.ModelProperty: node = obj as ModelPropertyNode; - switch (node.id.kind) { - case SyntaxKind.Identifier: - name = node.id.sv; - break; - case SyntaxKind.StringLiteral: - name = node.id.value; - break; - } + name = node.id.sv; parentId = generateId(node.parent); break; case SyntaxKind.ModelSpreadProperty: @@ -253,20 +239,13 @@ export function generateId(obj: BaseNode | NamespaceModel | undefined): string | break; case SyntaxKind.UnionVariant: node = obj as UnionVariantNode; - switch (node.id.kind) { - case SyntaxKind.Identifier: - name = node.id.sv; - break; - case SyntaxKind.StringLiteral: - name = node.id.value; - break; - } + name = node.id.sv; parentId = generateId(node.parent); break; default: return undefined; } - if (parentId != undefined) { + if (parentId !== undefined) { return `${parentId}.${name}`; } else { return name; diff --git a/tools/apiview/emitters/cadl-apiview/src/navigation.ts b/tools/apiview/emitters/typespec-apiview/src/navigation.ts similarity index 99% rename from tools/apiview/emitters/cadl-apiview/src/navigation.ts rename to tools/apiview/emitters/typespec-apiview/src/navigation.ts index 511e2308198..4abf8cb063a 100644 --- a/tools/apiview/emitters/cadl-apiview/src/navigation.ts +++ b/tools/apiview/emitters/typespec-apiview/src/navigation.ts @@ -11,7 +11,7 @@ import { SyntaxKind, UnionExpressionNode, UnionStatementNode, -} from "@cadl-lang/compiler"; +} from "@typespec/compiler"; import { ApiView, NamespaceStack } from "./apiview.js"; import { NamespaceModel } from "./namespace-model.js"; diff --git a/tools/apiview/emitters/typespec-apiview/src/testing/index.ts b/tools/apiview/emitters/typespec-apiview/src/testing/index.ts new file mode 100644 index 00000000000..ccd07422c3c --- /dev/null +++ b/tools/apiview/emitters/typespec-apiview/src/testing/index.ts @@ -0,0 +1,20 @@ +import { resolvePath } from "@typespec/compiler"; +import { TypeSpecTestLibrary } from "@typespec/compiler/testing"; +import { fileURLToPath } from "url"; + +export const ApiViewTestLibrary: TypeSpecTestLibrary = { + name: "@azure-tools/typespec-apiview", + packageRoot: resolvePath(fileURLToPath(import.meta.url), "../../../../"), + files: [ + { + realDir: "", + pattern: "package.json", + virtualPath: "./node_modules/@azure-tools/typespec-apiview", + }, + { + realDir: "dist/src", + pattern: "*.js", + virtualPath: "./node_modules/@azure-tools/typespec-apiview/dist/src", + }, + ], +}; diff --git a/tools/apiview/emitters/typespec-apiview/src/version.ts b/tools/apiview/emitters/typespec-apiview/src/version.ts new file mode 100644 index 00000000000..cf3eb161dca --- /dev/null +++ b/tools/apiview/emitters/typespec-apiview/src/version.ts @@ -0,0 +1 @@ +export const LIB_VERSION = "0.4.0"; diff --git a/tools/apiview/emitters/cadl-apiview/test/apiview-options.test.ts b/tools/apiview/emitters/typespec-apiview/test/apiview-options.test.ts similarity index 74% rename from tools/apiview/emitters/cadl-apiview/test/apiview-options.test.ts rename to tools/apiview/emitters/typespec-apiview/test/apiview-options.test.ts index 29ea0a74afb..f59d01ec921 100644 --- a/tools/apiview/emitters/cadl-apiview/test/apiview-options.test.ts +++ b/tools/apiview/emitters/typespec-apiview/test/apiview-options.test.ts @@ -1,13 +1,11 @@ -import { Diagnostic, logDiagnostics, resolvePath } from "@cadl-lang/compiler"; -import { expectDiagnosticEmpty, expectDiagnostics } from "@cadl-lang/compiler/testing"; -import { strictEqual } from "assert"; -import { apiViewFor, apiViewText, compare, createApiViewTestRunner, diagnosticsFor } from "./test-host.js"; +import { expectDiagnostics } from "@typespec/compiler/testing"; +import { apiViewFor, apiViewText, compare, diagnosticsFor } from "./test-host.js"; describe("apiview-options: tests", () => { it("omits namespaces that aren't proper subnamespaces", async () => { const input = ` - @Cadl.service( { title: "Test", version: "1" } ) + @TypeSpec.service( { title: "Test", version: "1" } ) namespace Azure.Test { model Foo {}; } @@ -38,7 +36,7 @@ describe("apiview-options: tests", () => { const input = ` model SomeGlobal {}; - @Cadl.service( { title: "Test", version: "1" } ) + @TypeSpec.service( { title: "Test", version: "1" } ) namespace Azure.Test { model Foo {}; } @@ -48,7 +46,7 @@ describe("apiview-options: tests", () => { model SomeGlobal {} } - @Cadl.service( + @TypeSpec.service( { title: "Test"; version: "1"; @@ -67,12 +65,12 @@ describe("apiview-options: tests", () => { it("emits error if multi-service package tries to specify version", async () => { const input = ` - @Cadl.service( { title: "Test", version: "1" } ) + @TypeSpec.service( { title: "Test", version: "1" } ) namespace Azure.Test { model Foo {}; } - @Cadl.service( { title: "OtherTest", version: "1" } ) + @TypeSpec.service( { title: "OtherTest", version: "1" } ) namespace Azure.OtherTest { model Foo {}; } @@ -80,11 +78,11 @@ describe("apiview-options: tests", () => { const diagnostics = await diagnosticsFor(input, {"version": "1"}); expectDiagnostics(diagnostics, [ { - code: "@azure-tools/cadl-apiview/invalid-option", + code: "@azure-tools/typespec-apiview/invalid-option", message: `Option "--output-file" cannot be used with multi-service specs unless "--service" is also supplied.` }, { - code: "@azure-tools/cadl-apiview/invalid-option", + code: "@azure-tools/typespec-apiview/invalid-option", message: `Option "--version" cannot be used with multi-service specs unless "--service" is also supplied.` } ]); @@ -92,12 +90,12 @@ describe("apiview-options: tests", () => { it("allows options if multi-service package specifies --service", async () => { const input = ` - @Cadl.service( { title: "Test", version: "1" } ) + @TypeSpec.service( { title: "Test", version: "1" } ) namespace Azure.Test { model Foo {}; } - @Cadl.service( { title: "OtherTest", version: "1" } ) + @TypeSpec.service( { title: "OtherTest", version: "1" } ) namespace Azure.OtherTest { model Foo {}; } diff --git a/tools/apiview/emitters/cadl-apiview/test/apiview.test.ts b/tools/apiview/emitters/typespec-apiview/test/apiview.test.ts similarity index 91% rename from tools/apiview/emitters/cadl-apiview/test/apiview.test.ts rename to tools/apiview/emitters/typespec-apiview/test/apiview.test.ts index 97f9689bb48..beef6ab285d 100644 --- a/tools/apiview/emitters/cadl-apiview/test/apiview.test.ts +++ b/tools/apiview/emitters/typespec-apiview/test/apiview.test.ts @@ -1,4 +1,4 @@ -import assert, { fail, strictEqual } from "assert"; +import assert, { fail } from "assert"; import { ApiViewDocument, ApiViewTokenKind } from "../src/apiview.js"; import { apiViewFor, apiViewText, compare } from "./test-host.js"; @@ -11,17 +11,17 @@ describe("apiview: tests", () => { defIdsPerLine[index] = new Array(); for (const token of apiview.Tokens) { // ensure that there are no repeated definition IDs. - if (token.DefinitionId != undefined) { + if (token.DefinitionId !== undefined) { if (definitionIds.has(token.DefinitionId)) { fail(`Duplicate defintion ID ${token.DefinitionId}.`); } definitionIds.add(token.DefinitionId); } // Collect the definition IDs that exist on each line - if (token.DefinitionId != undefined) { + if (token.DefinitionId !== undefined) { defIdsPerLine[index].push(token.DefinitionId); } - if (token.Kind == ApiViewTokenKind.Newline) { + if (token.Kind === ApiViewTokenKind.Newline) { index++; defIdsPerLine[index] = new Array(); } @@ -29,13 +29,13 @@ describe("apiview: tests", () => { // ensure that each line has either 0 or 1 definition ID. for (let x = 0; x < defIdsPerLine.length; x++) { const row = defIdsPerLine[x]; - assert(row.length == 0 || row.length == 1, `Too many definition IDs (${row.length}) on line ${x}`); + assert(row.length === 0 || row.length === 1, `Too many definition IDs (${row.length}) on line ${x}`); } } it("describes model", async () => { const input = ` - @Cadl.service( { title: "Test", version: "1" } ) + @TypeSpec.service( { title: "Test", version: "1" } ) namespace Azure.Test { model Animal { species: string; @@ -89,7 +89,7 @@ describe("apiview: tests", () => { it("describes scalar", async () => { const input = ` - @Cadl.service( { title: "Test", version: "1" } ) + @TypeSpec.service( { title: "Test", version: "1" } ) namespace Azure.Test { scalar Password extends string; @@ -116,7 +116,7 @@ describe("apiview: tests", () => { it("describes alias", async () => { const input = ` - @Cadl.service( { title: "Test", version: "1" } ) + @TypeSpec.service( { title: "Test", version: "1" } ) namespace Azure.Test { model Animal { species: string; @@ -142,7 +142,7 @@ describe("apiview: tests", () => { it("describes augment decorator", async () => { const input = ` - @Cadl.service( { title: "Test", version: "1" } ) + @TypeSpec.service( { title: "Test", version: "1" } ) namespace Azure.Test { model Animal { species: string; @@ -169,7 +169,7 @@ describe("apiview: tests", () => { it("describes templated model", async () => { const input = ` - @Cadl.service( { title: "Test", version: "1" } ) + @TypeSpec.service( { title: "Test", version: "1" } ) namespace Azure.Test { model Thing { property: T; @@ -241,7 +241,7 @@ describe("apiview: tests", () => { it("describes enum", async () => { const input = ` - @Cadl.service( { title: "Test", version: "1" } ) + @TypeSpec.service( { title: "Test", version: "1" } ) namespace Azure.Test { enum SomeEnum { @@ -284,7 +284,7 @@ describe("apiview: tests", () => { it("describes union", async () =>{ const input = ` - @Cadl.service( { title: "Test", version: "1" } ) + @TypeSpec.service( { title: "Test", version: "1" } ) namespace Azure.Test { union MyUnion { cat: Cat, @@ -335,7 +335,7 @@ describe("apiview: tests", () => { it("describes template operation", async () =>{ const input = ` - @Cadl.service( { title: "Test", version: "1" } ) + @TypeSpec.service( { title: "Test", version: "1" } ) namespace Azure.Test { model FooParams { a: string; @@ -397,7 +397,7 @@ describe("apiview: tests", () => { it("describes operation with anonymous models", async () =>{ const input = ` - @Cadl.service( { title: "Test", version: "1" } ) + @TypeSpec.service( { title: "Test", version: "1" } ) namespace Azure.Test { op SomeOp( param1: { @@ -429,7 +429,7 @@ describe("apiview: tests", () => { it("describes interface", async () => { const input = ` - @Cadl.service( { title: "Test", version: "1" } ) + @TypeSpec.service( { title: "Test", version: "1" } ) namespace Azure.Test { interface Foo { @get @@ -466,7 +466,7 @@ describe("apiview: tests", () => { it("describes string literals", async () => { const input = ` - @Cadl.service( { title: "Test", version: "1" } ) + @TypeSpec.service( { title: "Test", version: "1" } ) namespace Azure.Test { @doc("Short string") model Foo {}; diff --git a/tools/apiview/emitters/cadl-apiview/test/test-host.ts b/tools/apiview/emitters/typespec-apiview/test/test-host.ts similarity index 75% rename from tools/apiview/emitters/cadl-apiview/test/test-host.ts rename to tools/apiview/emitters/typespec-apiview/test/test-host.ts index 6f030ba197b..946814be3d9 100644 --- a/tools/apiview/emitters/cadl-apiview/test/test-host.ts +++ b/tools/apiview/emitters/typespec-apiview/test/test-host.ts @@ -1,17 +1,18 @@ -import { createTestHost, createTestWrapper } from "@cadl-lang/compiler/testing"; -import { RestTestLibrary } from "@cadl-lang/rest/testing"; -import { VersioningTestLibrary } from "@cadl-lang/versioning/testing"; -import { AzureCoreTestLibrary } from "@azure-tools/cadl-azure-core/testing"; +import { createTestHost, createTestWrapper } from "@typespec/compiler/testing"; +import { RestTestLibrary } from "@typespec/rest/testing"; +import { HttpTestLibrary } from "@typespec/http/testing"; +import { VersioningTestLibrary } from "@typespec/versioning/testing"; +import { AzureCoreTestLibrary } from "@azure-tools/typespec-azure-core/testing"; import { ApiViewTestLibrary } from "../src/testing/index.js"; -import "@azure-tools/cadl-apiview"; +import "@azure-tools/typespec-apiview"; import { ApiViewEmitterOptions } from "../src/lib.js"; import { ApiViewDocument, ApiViewTokenKind } from "../src/apiview.js"; -import { Diagnostic, resolvePath } from "@cadl-lang/compiler"; +import { Diagnostic, resolvePath } from "@typespec/compiler"; import { strictEqual } from "assert"; export async function createApiViewTestHost() { return createTestHost({ - libraries: [ApiViewTestLibrary, RestTestLibrary, VersioningTestLibrary, AzureCoreTestLibrary], + libraries: [ApiViewTestLibrary, RestTestLibrary, HttpTestLibrary, VersioningTestLibrary, AzureCoreTestLibrary], }); } @@ -20,16 +21,16 @@ export async function createApiViewTestRunner({ }: { withVersioning?: boolean } = {}) { const host = await createApiViewTestHost(); const autoUsings = [ - "Cadl.Rest", - "Cadl.Http", + "TypeSpec.Rest", + "TypeSpec.Http", ] if (withVersioning) { - autoUsings.push("Cadl.Versioning"); + autoUsings.push("TypeSpec.Versioning"); } return createTestWrapper(host, { autoUsings: autoUsings, compilerOptions: { - emit: ["@azure-tools/cadl-apiview"], + emit: ["@azure-tools/typespec-apiview"], } }); } @@ -39,7 +40,7 @@ export async function diagnosticsFor(code: string, options: ApiViewEmitterOption const outPath = resolvePath("/apiview.json"); const diagnostics = await runner.diagnose(code, { noEmit: false, - emitters: { "@azure-tools/cadl-apiview": { ...options, "output-file": outPath } }, + emitters: { "@azure-tools/typespec-apiview": { ...options, "output-file": outPath } }, miscOptions: { "disable-linter": true }, }); return diagnostics; @@ -50,7 +51,7 @@ export async function apiViewFor(code: string, options: ApiViewEmitterOptions): const outPath = resolvePath("/apiview.json"); await runner.compile(code, { noEmit: false, - emitters: { "@azure-tools/cadl-apiview": { ...options, "output-file": outPath } }, + emitters: { "@azure-tools/typespec-apiview": { ...options, "output-file": outPath } }, miscOptions: { "disable-linter": true }, }); @@ -67,7 +68,7 @@ export function apiViewText(apiview: ApiViewDocument): string[] { vals.push("\n"); break; default: - if (token.Value != undefined) { + if (token.Value !== undefined) { vals.push(token.Value); } break; @@ -90,7 +91,7 @@ function trimLines(lines: string[]): string[] { const trimmed: string[] = []; const indent = getIndex(lines); for (const line of lines) { - if (line.trim() == '') { + if (line.trim() === '') { // skip blank lines continue; } else { diff --git a/tools/apiview/emitters/cadl-apiview/tsconfig.json b/tools/apiview/emitters/typespec-apiview/tsconfig.json similarity index 100% rename from tools/apiview/emitters/cadl-apiview/tsconfig.json rename to tools/apiview/emitters/typespec-apiview/tsconfig.json