Closed3

cadl -> typespec

ohki_suguru.phpohki_suguru.php

概要

Cadlは、クラウドサービスAPIを記述し、他のAPI記述言語、クライアントとサービスのコード、ドキュメント、およびその他の資産を生成するための言語です。Cadlは、REST、OpenAPI、GraphQL、gRPC、およびその他のプロトコルで一般的なAPIシェイプを記述できる、拡張性の高いコア言語プリミティブを提供します。

リポジトリ

https://github.com/microsoft/cadl

ドキュメント

https://microsoft.github.io/cadl/

最新の書き方の記事

https://devblogs.microsoft.com/azure-sdk/the-value-of-cadl-in-designing-apis/

オンラインで試したい

https://cadlplayground.z22.web.core.windows.net/

OpenAPIから移った人が見ると良い型定義

https://microsoft.github.io/cadl/getting-started/cadl-for-openapi-dev

リンクまとめ

https://zenn.dev/niku/articles/368006496f37cd

ohki_suguru.phpohki_suguru.php

Error, Warning

<unknown location>:1:1 - warning @cadl-lang/rest/no-routes: Current spec is not exposing any routes. This could be to not having the service namespace marked with @serviceTitle.

https://microsoft.github.io/cadl/release-notes/release-2022-10-12#cadl-deprecation-service-decorator-replacing-servicetitle-and-serviceversion
↑ここを見る限り、すでにDeprecatedとなっている。
時々ドキュメントが古い箇所がある。
emittersもすでにDeprecatedとなっている。

// Before
@serviceTitle("Pet Store")
@serviceVersion("v1")
namespace PetStore;

// After
@service({"Pet Store", version: "v1"})
namespace PetStore;

このようになるらしい

ohki_suguru.phpohki_suguru.php

書き方サンプル

import "@cadl-lang/rest";
import "@cadl-lang/versioning";

using Cadl.Versioning;

@versioned(Versions)
@service({
  title: "Widget Service",
})
namespace DemoService;

enum Versions {
  "v1",
  "v2",
}

using Cadl.Http;
using Cadl.Rest;

model Widget {
  @key id: string;
  weight: int32;
  color: "red" | "blue";
  @added(Versions.v2) name: string;
}

@error
model Error {
  code: int32;
  message: string;
}

interface WidgetService extends Resource.ResourceOperations<Widget, Error> {
  @added(Versions.v2)
  @get
  @route("customGet")
  customGet(): Widget;
}
このスクラップは2023/05/01にクローズされました