Cadl is a language for describing cloud service APIs and generating other API description languages, client and service code, documentation, and other assets. Cadl provides highly extensible core language primitives that can describe API shapes common among REST, GraphQL, gRPC, and other protocols.
You can try a work-in-progress build of the compiler by following the steps in the Getting Started section below. Please feel free to file issues for any issues you encounter while using the preview.
| Name | Changelog | Latest |
|---|---|---|
| Core functionality | ||
| @cadl-lang/compiler | Changelog | |
| Cadl Libraries | ||
| @cadl-lang/rest | Changelog | |
| @cadl-lang/openapi | Changelog | |
| @cadl-lang/openapi3 | Changelog | |
| @cadl-lang/versioning | Changelog | |
| Cadl Tools | ||
| @cadl-lang/prettier-plugin-cadl | Changelog | |
| cadl-vs | Changelog | |
| cadl-vscode | Changelog | |
| tmlanguage-generator | Changelog |
-
Install Node.js 16 LTS and ensure you are able to run the
npmcommand in a command prompt:npm --version
It is recommended to have npm 7+. To update npm run
npm install -g npm -
Create a folder for your new Cadl project
-
Via init command: Run
npx -p @cadl-lang/compiler cadl init> Select openapi3 library template. -
Alternatively manually: In a command prompt, run the following commands:
cd path\to\cadl\project npm init -y npm install -g @cadl-lang/compiler npm install @cadl-lang/rest @cadl-lang/openapi3This will create a
package.jsonfile for your Cadl project and add the necessary Cadl dependencies to it. -
Install the Cadl extension for your editor of choice:
-
Open the folder in your editor and create a new file
main.cadl -
Follow our tutorial to get started writing Cadl!
-
Once you're ready to compile your Cadl to Swagger, save the file and type this at the command prompt in your project folder:
npx cadl compile . --emit @cadl-lang/openapi3This will compile the Cadl files in the project folder into one output file:
.\cadl-output\openapi.json. -
Using
--emitevery time can become tedious. You can create a project file to configure the default emitter.
Create a cadl-project.yaml file next to the package.json with this content:
emitters:
"@cadl-lang/openapi3": trueAfter you should be able to just run npx cadl compile .
See full usage documentation by typing:
cadl --help
Here is a very small Cadl example that uses the @cadl-lang/openapi3 library to generate OpenAPI 3.0 from Cadl.
import "@cadl-lang/rest";
using Cadl.Http;
@route("/example")
namespace Example {
@get
@route("/message")
op getMessage(): string;
}
You can compile it to OpenAPI 3.0 by using the following command:
cadl compile sample.cadl --emit @cadl-lang/openapi3
Once it compiles, you can find the emitted OpenAPI document in `./cadl-output/openapi.json.
You can also pass in a directory instead of a file to cadl compile. That's
equivalent to passing main.cadl in that directory.
Cadl provides an auto-formatter to keep your specs clean and organized.
cadl format <patterns...>
# Format all the files in the current directory with the cadl extension.
cadl format **/*.cadlcadl code install
This will download and install the latest VS Code extension. Use cadl code uninstall to remove it. Pass --insiders if you use VS Code Insiders edition.
If cadl-server cannot be found on PATH by VS Code in your setup, you can
configure its location in VS Code settings. Search for "Cadl" in File ->
Preferences -> Settings, and adjust cadl.cadl-server.path accordingly. You may
need to restart VS Code after changing this. This should be the path to the @cadl-lang/compiler package. (e.g. ./node_modules/@cadl-lang/compiler)
You can also configure a project to use a local npm install of
@cadl-lang/compiler. See local-cadl sample.
cadl vs install
This will download and install the latest Visual Studio extension. Use cadl vs uninstall to remove it.