Перейти к файлу
Timothee Guerin 94cdeb9818
Fix issue with detecting existing comment for tryit url (#458)
2022-04-19 09:29:35 -07:00
.github Add @timotheeguerin as code owner (#254) 2022-02-14 21:10:30 +00:00
.vscode Configure eslint for all packages with shared config pkg (#188) 2022-02-22 15:58:17 -06:00
common Fix Duplicate description in parameters (#440) 2022-04-18 13:40:54 -07:00
docker Include git during docker build phase (#454) 2022-04-18 21:09:58 +00:00
docs Add duration built-in type to tutorial: (#408) 2022-04-05 19:19:06 +00:00
e2e Scope unpublished packages (#357) 2022-03-25 15:51:16 +00:00
eng Fix issue with detecting existing comment for tryit url (#458) 2022-04-19 09:29:35 -07:00
packages Fix Duplicate description in parameters (#440) 2022-04-18 13:40:54 -07:00
.dockerignore Feature: docker image (#57) 2021-11-12 11:17:46 -08:00
.editorconfig Port build process to new OSS repo 2021-10-19 15:21:39 -05:00
.gitattributes Port build process to new OSS repo 2021-10-19 15:21:39 -05:00
.gitignore Add Cadl doc for the OpenAPI developer 2021-11-29 07:03:15 -06:00
.prettierignore Plug in code coverage collection into tests and upload to ADO (#208) 2022-01-28 17:44:56 +00:00
.prettierrc.json Small formatting and syntax highlighting improvements (#73) 2021-11-22 13:04:36 -06:00
CODE_OF_CONDUCT.md Add LICENSE, CODE_OF_CONDUCT.md, and SECURITY.md 2021-10-19 14:53:13 -05:00
CONTRIBUTING.md Fix issue with detecting existing comment for tryit url (#458) 2022-04-19 09:29:35 -07:00
LICENSE Add LICENSE, CODE_OF_CONDUCT.md, and SECURITY.md 2021-10-19 14:53:13 -05:00
README.md Add ability to ignore pattern when formatting (#435) 2022-04-11 20:29:06 +00:00
SECURITY.md Add LICENSE, CODE_OF_CONDUCT.md, and SECURITY.md 2021-10-19 14:53:13 -05:00
rush.json Remove node 14 support (#433) 2022-04-11 14:30:22 -05:00
troubleshooting.md Improve getting started docs (#345) 2022-03-21 12:48:20 -07:00
tsconfig.json Add a playground (#302) 2022-03-11 10:52:58 -08:00

README.md

Cadl

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.

Packages

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

Getting Started

Using Docker

See docker documentation

Using Node & Npm

  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. Create a folder for your new Cadl project

  3. Via init command: Run npx -p @cadl-lang/compiler cadl init > Select openapi3 library template.

  4. 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/openapi3
    

    This will create a package.json file for your Cadl project and add the necessary Cadl dependencies to it.

  5. Install the Cadl extension for your editor of choice:

  6. Open the folder in your editor and create a new file main.cadl

  7. Follow our tutorial to get started writing Cadl!

  8. 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/openapi3
    

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

  9. Using --emit every 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": true

After you should be able to just run npx cadl compile .

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;

@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 "!mytestfolder/**/*"
cadl format **/*.cadl --exclude "mytestfolder/**/*"

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.