Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .chronus/changes/typespecApiview-2026-0-8-15-7-55.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: feature
packages:
- "@azure-tools/typespec-apiview"
---

Migrate typespec-apiview from azure-sdk-tools repo.
1 change: 1 addition & 0 deletions .chronus/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ versionPolicies:
type: lockstep
step: minor
packages:
- "@azure-tools/typespec-apiview"
- "@azure-tools/typespec-autorest"
- "@azure-tools/typespec-azure-core"
- "@azure-tools/typespec-azure-portal-core"
Expand Down
27 changes: 27 additions & 0 deletions packages/typespec-apiview/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug TypeSpec APIView Emitter",
"program": "${workspaceFolder}/node_modules/@typespec/compiler/entrypoints/cli.js",
"args": [
"compile",
"C:/repos/azure-rest-api-specs/specification/orbital/Microsoft.PlanetaryComputer/main.tsp",
"--emit=C:/repos/azure-sdk-tools/tools/apiview/emitters/typespec-apiview/dist/src/index.js"
],
"smartStep": true,
"sourceMaps": true,
"skipFiles": ["<node_internals>/**/*.js"],
"outFiles": ["${workspaceFolder}/dist/**/*.js", "${workspaceFolder}/node_modules/**/*.js"],
"cwd": "${workspaceFolder}",
"presentation": {
"order": 1
}
}
]
}
104 changes: 104 additions & 0 deletions packages/typespec-apiview/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Release History

## Version 0.7.2 (05-14-2025)
Fixed issue where `cannot deindent with an indent` could cause the generator to crash.

## Version 0.7.1 (05-14-2025)
Support new TypeSpec compiler.
Fixed issue where `HasSuffixSpace` could cause the generator to crash.

## Version 0.7.0 (04-03-2025)
Support new TypeSpec compiler.

## Version 0.6.0 (03-20-2025)
Support new TypeSpec compiler.
**BREAKING CHANGE**: Removed support for `--version` parameter. Multi-versioned specs will be emitter as-is.

## Version 0.5.1 (02-27-2025)
Support new TypeSpec syntax.

## Version 0.5.0 (01-08-2025)
Support new internal APIView tree-structure.

## 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.
Resolve visual anomalies.

## Version 0.4.7 (03-22-2024)
Support TypeSpec string templates.
Fix display issue with templated aliases.
Ensure alias statements end with semicolon.

## Version 0.4.6 (03-08-2024)
Support CrossLanguagePackageId.

## Version 0.4.5 (01-29-2024)
Support named template arguments.
Support unnamed unions.
Support cross-language definition IDs.

## Version 0.4.4 (04-18-2023)
Support future beta releases of TypeSpec.

## Version 0.4.3 (04-17-2023)
Support latest release of TypeSpec.

## Version 0.4.2 (03-16-2023)
Support latest release of TypeSpec.

## Version 0.4.1 (03-13-2023)
Fixed issue where enums with spread members would cause the generator to crash.

## 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.
Emitter options `--output-file` and `--version` cannot be used with multi-service specs unless the
`--service` option is provided.
Added the `--include-global-namespace` option to permit including the global namespace in the token file.
Fixed issue where namespaces that are not proper subnamespaces may be included in the token file.

## Version 0.3.4 (01-13-2023)
Support latest release of Cadl compiler.

## Version 0.3.3 (01-03-2023)
Fixed issue where some type references were not navigable.

## Version 0.3.2 (12-20-2022)
Changed structure of APIView navigation so that aliases appear under a separate "Alias" section, instead of
within the existing "Models" section. Will likely result in a non-API-related diff with prior APIView versions.

## Version 0.3.1 (12-9-2022)
Support Cadl scalars.

## Version 0.3.0 (11-15-2022)
Add support for aliases and augment decorators.

## Version 0.2.1 (10-27-2022)
Change behavior of `version` emitter option so that if it is not supplied, APIView will be generated for the
un-projected Cadl, rendering all versioning decorators. Supplying `version` allows the user to project a
specific version.

## Version 0.2.0 (10-26-2022)
Support `namespace` emitter option to filter the appropriate namespace when it cannot be automatically resolved.
This is primarily intended for creating APIViews for libraries.
Support `version` emitter option to choose which version of a multi-versioned spec to emit. Specs with a single
version can omit this. Multi-version specs can omit this if emitting the latest version.
No longer suppress `@doc`, `@summary`, and `@example` decorators. These can be toggled using the APIView UI.
Support rendering multi-line strings.
Change default path for generating artifacts.

## Version 0.1.1 (10-13-2022)
Support compiler-level noEmit option.
Support `output-dir` emitter option.

## Version 0.1.0 (10-5-2022)
Initial release.
105 changes: 105 additions & 0 deletions packages/typespec-apiview/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# TypeSpec APIView Emitter

This package provides the [TypeSpec](https://github.com/microsoft/typespec) emitter to produce APIView token file output from TypeSpec source.

## Install

Add `@azure-tools/typespec-apiview` to your `package.json` and run `npm install`.

## Emit APIView spec

1. Via the command line

```bash
tsp compile {path to typespec project} --emit=@azure-tools/typespec-apiview
```

2. Via the config

Add the following to the `typespec-project.yaml` file.

```yaml
emitters:
@azure-tools/typespec-apiview: true
```

For configuration [see options](#emitter-options)

## Create API View

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 `typespec-apiview` emitter.

## Revise API View

1. Log in to the API View site (apiview.dev)[https://apiview.dev].
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 `typespec-apiview` emitter.

## Use APIView-specific decorators:

Currently there are no APIView-specific decorators...

## Emitter options:

Emitter options can be configured via the `tspconfig.yaml` configuration:

```yaml
emitters:
'@azure-tools/typespec-apiview':
<optionName>: <value>


# For example
emitters:
'@azure-tools/typespec-apiview':
output-file: my-custom-apiview.json
```

or via the command line with

```bash
--option "@azure-tools/typespec-apiview.<optionName>=<value>"

# For example
--option "@azure-tools/typespec-apiview.output-file=my-custom-apiview.json"
```

### `emitter-output-dir`

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 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.

### `service`

Filter output to a single service definition. If omitted, all service defintions will be
output as separate APIView token files.

### `output-file`

Configure the name of the output JSON token file relative to the `output-dir`. For multi-service
specs, this option cannot be supplied unless the `service` option is also set. If outputting
all services in a multi-service spec, the output filename will be the service root namespace with the
`-apiview.json` suffix. Otherwise, the default is `apiview.json`.

### `version`

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

- [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)
69 changes: 69 additions & 0 deletions packages/typespec-apiview/cspell.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
version: "0.2"
language: en
allowCompoundWords: true
dictionaries:
- node
- typescript
words:
- autorest
- azsdkengsys
- azurecr
- blockful
- blockless
- typespec
- Contoso
- CRUDL
- devdriven
- dogfood
- eastus
- esbuild
- globby
- Hdvcmxk
- inmemory
- instanceid
- intrinsics
- ints
- jsyaml
- msbuild
- MSRC
- munge
- myconst
- mylib
- nostdlib
- oapi
- oneof
- onig
- onigasm
- onwarn
- openapi
- openapiv
- picocolors
- pnpm
- proto
- protobuf
- protoc
- regen
- rpaas
- rushx
- safeint
- strs
- TSES
- unassignable
- Uncapitalize
- uninstantiated
- unioned
- unprojected
- unsourced
- unversioned
- vsix
- vswhere
- westus
- xplat
- deindent
ignorePaths:
- "**/node_modules/**"
- "**/dist/**"
- "**/dist-dev/**"
- "**/tsp-output/**"
enableFiletypes:
- tsp
18 changes: 18 additions & 0 deletions packages/typespec-apiview/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// @ts-check
import tsEslint from "typescript-eslint";
import { TypeSpecCommonEslintConfigs } from "../../core/eslint.config.js";

export default tsEslint.config(
{
ignores: ["dist/**"],
},
...TypeSpecCommonEslintConfigs,
{
rules: {
"@typescript-eslint/no-unused-vars": [
"warn",
{ argsIgnorePattern: "^_", varsIgnorePattern: "^_" },
],
},
},
);
Loading
Loading