microsoft/typespec

Public

mirrored from https://github.com/microsoft/typespecAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
e966efd30e552f4e84d5ae7224515199738ddd8e

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

packages/playground/src/samples.ts

77lines · modecode

1export const samples: Record<string, string> = {
2 Http: `import "@cadl-lang/rest";
3
4@serviceTitle("Widget Service")
5namespace DemoService;
6using Cadl.Http;
7
8model Widget {
9 @key id: string;
10 weight: int32;
11 color: "red" | "blue";
12}
13
14@error model Error {
15 code: int32;
16 message: string;
17}
18
19interface WidgetService {
20 @get list(): Widget[] | Error;
21 @route("widgets/{id}") @get read(@path id: string): Widget | Error;
22 @post create(@body body: Widget): Widget | Error;
23 @route("customGet") @get customGet(): Widget | Error;
24}`,
25 "Rest framework": `import "@cadl-lang/rest";
26
27@serviceTitle("Widget Service")
28namespace DemoService;
29
30using Cadl.Http;
31using Cadl.Rest;
32
33model Widget {
34 @key id: string;
35 weight: int32;
36 color: "red" | "blue";
37}
38
39@error model Error {
40 code: int32;
41 message: string;
42}
43
44interface WidgetService mixes Resource.ResourceOperations<Widget, Error> {
45 @get @route("customGet") customGet(): Widget;
46}`,
47 "Versioned Rest Framework": `import "@cadl-lang/rest";
48import "@cadl-lang/versioning";
49
50@serviceTitle("Widget Service")
51@versioned(VERSIONS)
52namespace DemoService;
53
54alias VERSIONS = "v1" | "v2";
55
56using Cadl.Http;
57using Cadl.Rest;
58
59model Widget {
60 @key id: string;
61 weight: int32;
62 color: "red" | "blue";
63 @added("v2") name: string;
64}
65
66@error model Error {
67 code: int32;
68 message: string;
69}
70
71interface WidgetService mixes Resource.ResourceOperations<Widget, Error> {
72 @added("v2")
73 @get
74 @route("customGet")
75 customGet(): Widget;
76}`,
77};
78