Перейти к файлу
Timothee Guerin 4576315d08
Versioning more fixes with sub namespaces version resolution (#1384)
2022-12-06 16:52:05 -08:00
.github Tentative: fix cadleng format command (#1362) 2022-12-02 13:23:41 -08:00
.vscode Feature: Cadl project file variable interpolation and `emitter-output-dir` (#1262) 2022-12-01 23:47:24 +00:00
common Versioning more fixes with sub namespaces version resolution (#1384) 2022-12-06 16:52:05 -08:00
docker Move leftover docs in `docs/` to website (#1325) 2022-11-29 19:55:10 +00:00
docs Update configuration docs with new and configuration (#1383) 2022-12-06 22:25:21 +00:00
e2e Prepare cadl publish - September Sprint 2022 (#1001) 2022-09-08 17:24:39 +00:00
eng Migration tool (#1310) 2022-11-29 14:22:51 -08:00
packages Versioning more fixes with sub namespaces version resolution (#1384) 2022-12-06 16:52:05 -08:00
.dockerignore Feature: docker image (#57) 2021-11-12 11:17:46 -08:00
.editorconfig Format CSharp files: add `dotnet format` to `rush format` (#490) 2022-04-29 09:46:23 -07:00
.gitattributes Port build process to new OSS repo 2021-10-19 15:21:39 -05:00
.gitignore Add test reporting to investigate the failure (#709) 2022-07-15 20:12:11 +00:00
.prettierignore Migrate website to use docusaurus (#1266) 2022-11-14 12:44:38 -08:00
.prettierrc.json Fix prettier import format (#1021) 2022-09-12 12:09:37 -04:00
CODE_OF_CONDUCT.md Add LICENSE, CODE_OF_CONDUCT.md, and SECURITY.md 2021-10-19 14:53:13 -05:00
CONTRIBUTING.md Add github action to run formatter for you (#1219) 2022-10-24 22:30:51 +00:00
LICENSE Add LICENSE, CODE_OF_CONDUCT.md, and SECURITY.md 2021-10-19 14:53:13 -05:00
README.md Address some doc issues per #567 (#1326) 2022-12-01 23:25:17 +00:00
SECURITY.md Add LICENSE, CODE_OF_CONDUCT.md, and SECURITY.md 2021-10-19 14:53:13 -05:00
cspell.yaml Migrate website to use docusaurus (#1266) 2022-11-14 12:44:38 -08:00
rush.json Lock versions (#1368) 2022-12-05 19:00:37 -08:00
troubleshooting.md Improve getting started docs (#345) 2022-03-21 12:48:20 -07:00
tsconfig.json Migration tool (#1310) 2022-11-29 14:22:51 -08:00

README.md

Cadl

Try Cadl Online

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, OpenAPI, GraphQL, gRPC, and other protocols.

Using Cadl, you can create reusable patterns for all aspects of an API, along with the ability to check for and flag known anti-patterns. These patterns establish "guardrails" for API designers and make it easier to follow best practices than deviate from them. Cadl promotes highly regular API designs that adhere to best practices by construction.

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.

Try Cadl without installing anything

You can try Cadl on the web without installing anything.

Getting Started

For documentation for Cadl language, see https://microsoft.github.io/cadl.

Using Docker

See docker documentation

Using Node & Npm

One-time Setup

  1. Install Node.js 16 LTS and ensure you are able to run the npm command in a command prompt:

    npm --version
    

    It is recommended to have npm 7+. To update npm run npm install -g npm

  2. Install Cadl compiler and libraries:

   npm init -y
   npm install -g @cadl-lang/compiler

If you do not wish to install the compiler globally with -g flag, you will need to install it locally once in every Cadl project folder. You would also need to prefix every Cadl run command with npx. See npx documentation

    npx cadl init
    npx cadl compile
  1. Install the Cadl extension for your editor of choice:

Creating Cadl project

  1. Create a folder for your new Cadl project

  2. Initialize a Cadl project.

    • Run cadl init > Select Generic Rest API template with @cadl-lang/rest and @cadl-lang/openapi3 libraries checked.
    • Run cadl install to install node package dependencies.
  3. Open the folder in your editor and edit main.cadl

  4. Follow our documentation to get started writing Cadl!

  5. Once you're ready to compile your Cadl to Swagger, save the file and type this at the command prompt in your project folder:

    cadl compile .
    

    This will compile the Cadl files in the project folder into one output file: .\cadl-output\openapi.json.

Troubleshooting

See common issues here

Usage

See full usage documentation by typing:

cadl --help

Compiling Cadl source to an OpenAPI 3.0 specification

Here is a very small Cadl example that uses the @cadl-lang/openapi3 library to generate OpenAPI 3.0 from Cadl.

sample.cadl

import "@cadl-lang/rest";

using Cadl.Http;

@server("https://example.com", "Single server endpoint")
@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.

Formatting Cadl files

Cadl provides an auto-formatter to keep your specs clean and organized. node_modules folders are automatically excluded by default

cadl format <patterns...>

# Format all the files in the current directory with the cadl extension.
cadl format **/*.cadl

# Exclude certain patterns. Either use `!` prefix or pass it via the `--exclude` or `-x` option.
cadl format **/*.cadl "!my-test-folder/**/*"
cadl format **/*.cadl --exclude "my-test-folder/**/*"

Installing VS Code Extension

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

Installing Visual Studio Extension

cadl vs install

This will download and install the latest Visual Studio extension. Use cadl vs uninstall to remove it.

If cadl-server cannot be found on PATH by Visual Studio in your setup, you can configure its location by setting up the cadl.cadl-server.path entry in .vs/VSWorkspaceSettings.json. You may need to restart Visual Studio after changing this. This should be the path to the @cadl-lang/compiler package. (e.g. ./node_modules/@cadl-lang/compiler)

Installing nightly version

On every commit to the main branch, packages with changes are automatically published to npm with the @next tag. The packages section shows which version corresponds to the next tag for each package.

To use a nightly version of the packages, go over each one of the packages in the package.json file and update it to either the latest published @next version or @latest, whichever is the newest. You can also use the tag latest or next instead of an explicit version.

After updating the package.json file you can run npm update --force. Force is required as there might be some incompatible version requirement.

Example

// Stable setup
"dependencies": {
  "@cadl-lang/compiler": "~0.30.0",
  "@cadl-lang/rest": "~0.14.0",
  "@cadl-lang/openapi": "~0.9.0",
}

// Consume next version
// In this example: compiler and openapi have changes but rest library has none
"dependencies": {
  "@cadl-lang/compiler": "~0.31.0-dev.5",
  "@cadl-lang/rest": "~0.14.0", // No changes to @cadl-lang/rest library so need to stay the latest.
  "@cadl-lang/openapi": "~0.10.0-dev.2",
}

Packages

Name Changelog Latest Next
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

@next version of the package are the latest versions available on the main branch.