microsoft/typespec
Publicmirrored from https://github.com/microsoft/typespecAvailable
packages/playground/src/samples.ts
77lines · modecode
| 1 | export const samples: Record<string, string> = { |
| 2 | Http: `import "@cadl-lang/rest"; |
| 3 | |
| 4 | @serviceTitle("Widget Service") |
| 5 | namespace DemoService; |
| 6 | using Cadl.Http; |
| 7 | |
| 8 | model 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 | |
| 19 | interface 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") |
| 28 | namespace DemoService; |
| 29 | |
| 30 | using Cadl.Http; |
| 31 | using Cadl.Rest; |
| 32 | |
| 33 | model 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 | |
| 44 | interface WidgetService mixes Resource.ResourceOperations<Widget, Error> { |
| 45 | @get @route("customGet") customGet(): Widget; |
| 46 | }`, |
| 47 | "Versioned Rest Framework": `import "@cadl-lang/rest"; |
| 48 | import "@cadl-lang/versioning"; |
| 49 | |
| 50 | @serviceTitle("Widget Service") |
| 51 | @versioned(VERSIONS) |
| 52 | namespace DemoService; |
| 53 | |
| 54 | alias VERSIONS = "v1" | "v2"; |
| 55 | |
| 56 | using Cadl.Http; |
| 57 | using Cadl.Rest; |
| 58 | |
| 59 | model 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 | |
| 71 | interface WidgetService mixes Resource.ResourceOperations<Widget, Error> { |
| 72 | @added("v2") |
| 73 | @get |
| 74 | @route("customGet") |
| 75 | customGet(): Widget; |
| 76 | }`, |
| 77 | }; |
| 78 | |