@azure-tools/typespec-azure-core 0.31.0-dev.5 → 0.31.0-dev.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +4 -605
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -2,32 +2,6 @@
2
2
 
3
3
  This package provides TypeSpec decorators, models and interfaces to describe Azure services. With models, decorators and interfaces defined in Azure.Core, you will be able to define Azure resources and operations using standard patterns and best practices with ease.
4
4
 
5
- ## Table of Contents
6
-
7
- - [Getting Started](#getting-started)
8
- - [Creating a new TypeSpec project with `tsp init`](#creating-a-new-typespec-project-with-typespec-init)
9
- - [Writing Your First Service](#writing-your-first-service)
10
- - [Create the service namespace](#create-the-service-namespace)
11
- - [Using the versioned Azure.Core types](#using-the-versioned-azurecore-types)
12
- - [Defining your first resource](#defining-your-first-resource)
13
- - [Defining standard resource operations](#defining-standard-resource-operations)
14
- - [Defining long-running resource operations](#defining-long-running-resource-operations)
15
- - [Defining child resources](#defining-child-resources)
16
- - [Defining custom resource actions](#defining-custom-resource-actions)
17
- - [Customizing operation parameters and responses](#customizing-operation-parameters-and-responses)
18
- - [Versioning your service](#versioning-your-service)
19
- - [Using Azure.Core versions](#using-azurecore-versions)
20
- - [Advanced Topics](#advanced-topics)
21
- - [Defining singleton resources](#defining-singleton-resources)
22
- - [Library Versions](#library-versions)
23
- - [Library Tour](#library-tour)
24
- - [Models](#models)
25
- - [Operations](#operations)
26
- - [Decorators](#decorators)
27
- - [API](#api)
28
- - [Generating an OpenAPI Specification](#generating-an-openapi-specification)
29
- - [A Complete Example](#a-complete-example)
30
-
31
5
  ## Getting Started
32
6
 
33
7
  To get started using TypeSpec and `Azure.Core`, you have two options:
@@ -37,585 +11,10 @@ To get started using TypeSpec and `Azure.Core`, you have two options:
37
11
 
38
12
  You should also read the [language overview](https://microsoft.github.io/typespec/docs/language-basics/overview/) to get better acquainted with the language.
39
13
 
40
- ### Creating a new TypeSpec project with `tsp init`
41
-
42
- If you installed TypeSpec on your local machine, here is how you can create a new TypeSpec project:
43
-
44
- First, open your command prompt (PowerShell, cmd.exe, bash, etc), create an empty folder for your new project, and `cd` into it.
45
-
46
- Now create a new Azure service specification using the `tsp init` command:
47
-
48
- ```bash
49
- tsp init https://aka.ms/typespec/core-init
50
- ```
51
-
52
- You will be prompted with a few questions:
53
-
54
- - The service template: choose "Azure Data Plane Service"
55
- - The project name: Enter a name to be used as the project folder name or press enter to use the same name as the folder you created
56
- - Update the libraries: Press Enter to continue with the selected packages
57
-
58
- The prompts will look something like this:
59
-
60
- ```bash
61
- TypeSpec compiler v0.34.0
62
-
63
- √ Please select a template » Azure Data Plane Service
64
- √ Project name ... myService
65
- √ Update the libraries? » @typespec/rest, @typespec/versioning, @azure-tools/typespec-autorest, @azure-tools/typespec-azure-core
66
- TypeSpec init completed. You can run `tsp install` now to install dependencies.
67
- ```
68
-
69
- Once your project files have been created, execute the following command to install the TypeSpec compiler and libraries:
70
-
71
- ```bash
72
- tsp install
73
- ```
74
-
75
- You can now open the file `main.tsp` to follow along with the rest of the tutorial!
76
-
77
- ## Writing Your First Service
78
-
79
- The Azure Data Plane Service template will create a very basic TypeSpec file in `main.tsp`:
80
-
81
- ```typespec
82
- import "@typespec/http";
83
- import "@typespec/rest";
84
- import "@typespec/versioning";
85
- import "@azure-tools/typespec-autorest";
86
- import "@azure-tools/typespec-azure-core";
87
- ```
88
-
89
- These lines import the libraries you will need to build your first service.
90
-
91
- > **NOTE:** The `@azure-tools/typespec-autorest` import is not explicitly needed for this tutorial.
92
-
93
- **Add the following lines** to bring the models, operations, and decorators you will need into the specification:
94
-
95
- ```typespec
96
- using TypeSpec.Http;
97
- using TypeSpec.Rest;
98
- using TypeSpec.Versioning;
99
- using Azure.Core;
100
- ```
101
-
102
- ### Create the service namespace
103
-
104
- To describe a service, you first need to define a "blockless" (file-level, no curly braces) namespace and use the `@service` decorator to mark it as the service namespace:
105
-
106
- ```typespec
107
- @service({
108
- title: "Contoso Widget Manager",
109
- })
110
- namespace Contoso.WidgetManager;
111
- ```
112
-
113
- This marks the `Contoso.WidgetManager` namespace as a service namespace in this TypeSpec specification and sets its title to "Contoso Widget Manager."
114
-
115
- ### Using the versioned Azure.Core types
116
-
117
- Before you can use the models and operations defined in the `Azure.Core` namespace, you will need to specify the API version of the `Azure.Core` library that your service uses. You can do this by adding the `@useDependency` decorator to the `Contoso.WidgetManager` namespace as seen here:
118
-
119
- ```typespec
120
- @service({
121
- title: "Contoso Widget Manager",
122
- })
123
- @useDependency(Azure.Core.Versions.v1_0_Preview_2)
124
- namespace Contoso.WidgetManager;
125
- ```
126
-
127
- See the sections [Versioning your service](#versioning-your-service) and [Using Azure.Core versions](#using-azurecore-versions) for more details about service versioning.
128
-
129
- > **NOTE:** The `Azure.Core` version used in this tutorial may be out of date! The `typespec-azure-core` [README.md](https://github.com/Azure/typespec-azure/blob/main/packages/typespec-azure-core/README.md) file contains the [versions listing](#library-versions) which describes the available versions.
130
-
131
- ### Defining your first resource
132
-
133
- Now we're ready to describe our first resource type. A "resource" is a model type that represents a fundamental type in the domain model of your service.
134
-
135
- For our `WidgetService`, the most obvious model type that we will need is called `Widget`. We can create it by creating a `model` that is annotated with the `@resource` decorator. Add the following lines after the top-level `namespace` declaration:
136
-
137
- ```typespec
138
- @doc("A widget.")
139
- @resource("widgets")
140
- model Widget {
141
- @key("widgetName")
142
- @doc("The widget name.")
143
- @visibility("read")
144
- name: string;
145
-
146
- @doc("The ID of the widget's manufacturer.")
147
- manufacturerId: string;
148
- }
149
- ```
150
-
151
- There are a few important things to point out here:
152
-
153
- - The `Widget` model has a `@resource` decorator with a parameter of `"widgets"`. This string is the "collection name" of the resource and affects where the resource appears in the service URI layout.
154
- - The `name` property has a `@key` decorator with a parameter of `"widgetName"`. This string customizes the name of the path parameter (and the parameter name itself) in operations that use this resource type. There _must_ be one property with a `@key` decorator on all resource types!
155
- - The `@visibility("read")` decorator on the `name` property says that the `name` property should only appear in operation responses but not in operations that allow you to change properties of the `Widget` resource.
156
- - We use `@doc` decorators on the model type and all properties to describe. Documentation strings are enforced by linting rule when authoring specs with `Azure.Core`!
157
-
158
- Great, now we have a resource type! Now, how do we define operations for this resource?
159
-
160
- ### Defining standard resource operations
161
-
162
- The `Azure.Core` namespace provides a number of [standard lifecycle operations](#operations) for resource types which encode many of the requirements of the [Azure REST API Guidelines](https://github.com/microsoft/api-guidelines/blob/vNext/azure/Guidelines.md). Let's define the standard set of CRUD (Create, Read, Update, Delete) operations that are typically needed for a resource type in an Azure service.
163
-
164
- We will do that by defining an interface called `Widgets` which reuses the standard operation shapes for these lifecycle operations:
165
-
166
- ```typespec
167
- interface Widgets {
168
- @doc("Fetch a Widget by name.")
169
- getWidget is ResourceRead<Widget>;
170
-
171
- @doc("Creates or updates a Widget.")
172
- createOrUpdateWidget is ResourceCreateOrUpdate<Widget>;
173
-
174
- @doc("Delete a Widget.")
175
- deleteWidget is ResourceDelete<Widget>;
176
-
177
- @doc("List Widget resources.")
178
- listWidgets is ResourceList<Widget>;
179
- }
180
- ```
181
-
182
- > **NOTE:** It is not necessary to define your resource operations inside of an `interface`. You can also define them in a sub-namespace of your service or inside the top-level namespace of the service. However, it is a best practice in TypeSpec to use `interface` to encapsulate the operations of a particular resource type.
183
-
184
- This interface uses the following standard lifecycle operations:
185
-
186
- - `ResourceRead<TResource>` - defines a "read" operation for a single resource instance
187
- - `ResourceCreateOrUpdate<TResource>` - defines an "upsert" operation which either creates or updates an instance of the resource type depending on whether it already exists
188
- - `ResourceDelete<TResource>` - defines a "delete" operation to delete a specific instance of the resource
189
- - `ResourceList<TResource>` - defines an operation that lists all instances of the resource type
190
-
191
- > **NOTE:** There are both instantaneous and long-running versions of "create", "update", and "delete" operations for resource types depending on what you need for a particular resource!
192
-
193
- Based on the configuration of the `Widget` type and the use of these standard operation templates, these operations will all exist under the route path:
194
-
195
- ```
196
- /widgets/{widgetName}
197
- ```
198
-
199
- The list operation will simply generate the path `/widgets`.
200
-
201
- ### Defining long-running resource operations
202
-
203
- If your service uses any long-running operations (those that usually take longer than 1 second to complete), you will need to define a "status monitor" operation which can report the status of the operation as it proceeds.
204
-
205
- Let's say that we want to make our `createOrUpdateWidget` and `deleteWidget` operations long-running; here's how we can update our `Widgets` interface to accomplish that:
206
-
207
- ```typespec
208
- interface Widgets {
209
- @doc("Gets status of a Widget operation.")
210
- getWidgetOperationStatus is GetResourceOperationStatus<Widget>;
211
-
212
- @doc("Fetch a Widget by name.")
213
- getWidget is ResourceRead<Widget>;
214
-
215
- @doc("Creates or updates a Widget asynchronously.")
216
- @pollingOperation(Widgets.getWidgetOperationStatus)
217
- createOrUpdateWidget is LongRunningResourceCreateOrUpdate<Widget>;
218
-
219
- @doc("Delete a Widget asynchronously.")
220
- @pollingOperation(Widgets.getWidgetOperationStatus)
221
- deleteWidget is LongRunningResourceDelete<Widget>;
222
-
223
- @doc("List Widget resources.")
224
- listWidgets is ResourceList<Widget>;
225
- }
226
- ```
227
-
228
- First, we change `createOrUpdateWidget` to use `LongRunningResourceCreateOrUpdate<Widget>` and `deleteWidget` to use `LongRunningResourceDelete`.
229
-
230
- Next, we define the `getWidgetOperationStatus` operation based on the `GetResourceOperationStatus` signature. This defines the operation status monitor as a child resource of the `Widget` type so that it shows up under that resource in the route hierarchy.
231
-
232
- Finally, we **must** add the `pollingLocation` decorator to both of the long-running operations and reference the `Widgets.getWidgetOperationStatus` operation. This connects the long-running operations to their associated status monitor operation to make it easier for service clients to be generated.
233
-
234
- > **NOTE:** The status monitor operation **must** be defined earlier in the interface than the long-running operations that reference it otherwise TypeSpec will not be able to resolve the reference!
235
-
236
- ### Defining child resources
237
-
238
- Sometimes your resource types will need to have child resources that relate to their parent types. You can identify that a resource type is the child of another resource by using the `@parentResource` decorator.
239
-
240
- For example, here's how you could create a new `WidgetPart` resource under the `Widget` defined above:
241
-
242
- ```typespec
243
- @doc("A WidgetPart resource belonging to a Widget resource.")
244
- @resource("parts")
245
- @parentResource(Widget)
246
- model WidgetPart {
247
- @key("partName")
248
- name: string;
249
-
250
- @doc("The part number.")
251
- number: string;
252
-
253
- @doc("The part name.")
254
- partName: string;
255
- }
256
- ```
257
-
258
- When you use the standard resource operations with child resource types, their operation routes will include the route of the parent resource. For example, we might define the following operations for `WidgetPart`:
259
-
260
- ```typespec
261
- @doc("Creates a WidgetPart")
262
- createWidgetPart is ResourceCreateWithServiceProvidedName<WidgetPart>;
263
-
264
- @doc("Get a WidgetPart")
265
- getWidgetPart is ResourceRead<WidgetPart>;
266
- ```
267
-
268
- These operations will be defined under the route path:
269
-
270
- ```
271
- /widgets/{widgetName}/parts/{partName}
272
- ```
273
-
274
- ### Defining custom resource actions
275
-
276
- Often your resource types will need additional operations that are not covered by the standard resource operation shapes. For this, there are a set of operation signatures for defining _resource actions_ at the instance and collection level.
277
-
278
- To define a custom action you can use the `ResourceAction` and `ResourceCollectionAction` signatures from `Azure.Core`. Let's define a couple of custom actions for the `Widget` and `WidgetPart` resources:
279
-
280
- ```typespec
281
- // In the Widgets interface...
282
- @doc("Schedule a widget for repairs.")
283
- scheduleRepairs is ResourceAction<
284
- Widget,
285
- WidgetRepairRequest,
286
- WidgetRepairRequest
287
- >;
288
-
289
- // In the WidgetParts interface...
290
- @doc("Reorder all parts for the widget.")
291
- reorderParts is ResourceCollectionAction<
292
- WidgetPart,
293
- WidgetPartReorderRequest,
294
- WidgetPartReorderRequest
295
- >;
296
- ```
297
-
298
- The `scheduleRepairs` operation defines a custom action for all instances of the `Widget` resource. **All collection action templates expect 3 parameters:** the resource type, the request action parameters, and the response type. In this case, `WidgetRepairRequest` is both the parameter and response type because we are using it as the body of both the request and the response of this operation.
299
-
300
- > **NOTE:** The request parameters and response type **do not** have to be the same type!
301
-
302
- We also define an collection operation called `reorderParts`. Similarly to `scheduleRepairs`, it uses the `WidgetPartReorderRequest` as the request and response body.
303
-
304
- Here are what the routes of these two operations will look like:
305
-
306
- ```
307
- /widgets/{widgetName}:scheduleRepairs
308
- /widgets/{widgetName}/parts:reorderParts
309
- ```
310
-
311
- Notice that the operation name is used as the action name in the route!
312
-
313
- There are also long-running operation versions of these two operations:
314
-
315
- - `LongRunningResourceAction`
316
- - `LongRunningResourceCollectionAction`
317
-
318
- The same rules described in the [long-running operations](defining-long-running-resource-operations) section also apply to these long-running action signatures.
319
-
320
- ### Customizing operation parameters and responses
321
-
322
- For all standard lifecycle operations (excluding resource custom actions, those are already customizable) you can customize the operation parameters and response body by passing a special model type to the `TCustom` parameter of the operation template, typically the second parameter of the operation template.
323
-
324
- For example, if you wanted to add standard list operation query parameters to the `listWidgets` operation, you could modify the definition like this:
325
-
326
- ```typespec
327
- @doc("List Widget resources")
328
- listWidgets is ResourceList<
329
- Widget,
330
- {
331
- parameters: StandardListQueryParameters & SelectQueryParameter;
332
- }
333
- >;
334
- ```
335
-
336
- This definition populates the `ResourceList<TResource, TCustom>` signature with an inline model definition for the `TCustom` type. The `TCustom` parameter expects a model with two possible properties:
337
-
338
- - `parameters` - A model type that will be mixed into the parameter list of the operation. Typically used for mixing in `@query` or `@header` parameters for the operation.
339
- - `response` - A model type that will be mixed into the non-error response envelope of the operation. This can be used to inject response properties or `@header`s in your operation response.
340
-
341
- An example of customizing both `parameters` and `response` at the same time would be using the OASIS Repeatable Requests customization types `RepeatabilityRequestHeaders` and `RepeatabilityResponseHeaders`. Here's how we can use these types with the `deleteWidget` operation:
342
-
343
- ```
344
- @doc("Delete a Widget.")
345
- deleteWidget is ResourceDelete<
346
- Widget,
347
- {
348
- parameters: RepeatabilityRequestHeaders;
349
- response: RepeatabilityResponseHeaders;
350
- }
351
- >;
352
- ```
353
-
354
- This would customize both the request parameters and the response envelope of the `deleteWidget` operation to include the headers defined in both these model types.
355
-
356
- ### Versioning your service
357
-
358
- It is inevitable that service specifications will change over time. It is a best practice to add versioning support to your specification from the first version. To do that, you will need to define an `enum` containing your service versions and then apply the `@versioned` decorator to your service namespace.
359
-
360
- Here is an example for the `WidgetManager` service:
361
-
362
- ```typespec
363
- @service({
364
- title: "Contoso Widget Manager",
365
- })
366
- @versioned(Contoso.WidgetManager.Versions)
367
- namespace Contoso.WidgetManager;
368
-
369
- enum Versions {
370
- @useDependency(Azure.Core.Versions.v1_0_Preview_1)
371
- v2022_08_31: "2022-08-31",
372
- }
373
- ```
374
-
375
- There are a few things to point out here:
376
-
377
- - We define an `enum` called `Versions` inside of the service namespace. For each service version, we map a version symbol like `v2022_08_31` to a version string like `2022-08-31`. This service currently only has a single version, but we can add more to this enum as things change over time.
378
- - We add the `@versioned` decorator and reference the `Versions` enum we defined using the fully-qualified name `Contoso.WidgetManager.Versions`. This marks the service as being versioned and specifies the set of versions.
379
- - We change the `@useDependency` decorator we used previously to now link each service version to a specific version of `Azure.Core`. See the [Using Azure.Core Versions](#using-azurecore-versions) section for more information.
380
-
381
- Imagine that it's 3 months later and you want to release a new version of your service with some slight changes. Add a new version to the `Versions` enum:
382
-
383
- ```typespec
384
- enum Versions {
385
- @useDependency(Azure.Core.Versions.v1_0_Preview_1)
386
- v2022_08_31: "2022-08-31",
387
- v2022_11_30: "2022-11-30",
388
- }
389
- ```
390
-
391
- You will also need to add the `@useDependency` decorator:
392
-
393
- ```typespec
394
- enum Versions {
395
- @useDependency(Azure.Core.Versions.v1_0_Preview_1)
396
- v2022_08_31: "2022-08-31",
397
-
398
- @useDependency(Azure.Core.Versions.v1_0_Preview_2)
399
- v2022_11_30: "2022-11-30",
400
- }
401
- ```
402
-
403
- Finally, you can express changes to your service using the `@added` and `@removed` decorators. Here's an example of adding a new property to `Widget` and removing an old one:
404
-
405
- ```typespec
406
- @doc("A widget.")
407
- @resource("widgets")
408
- model Widget {
409
- @key("widgetName")
410
- @doc("The widget name.")
411
- @visibility("read")
412
- name: string;
413
-
414
- @doc("The widget color.")
415
- @added(Contoso.WidgetManager.Versions.v2022_11_30)
416
- color: string;
417
-
418
- @doc("The ID of the widget's manufacturer.")
419
- @removed(Contoso.WidgetManager.Versions.v2022_11_30)
420
- manufacturerId: string;
421
- }
422
- ```
423
-
424
- You can do a lot more with versioning decorators, so consult the `typespec-versioning` [README.md](https://github.com/microsoft/typespec/tree/main/packages/versioning#enable-versioning-for-service-or-library) for more information on how you can use them to annotate your service and describe changes between different versions.
425
-
426
- ### Using Azure.Core versions
427
-
428
- `typespec-azure-core` is a versioned TypeSpec library. This means that even as the TypeSpec portions of the typespec-azure-core library are updated, you can anchor each version of your spec to a [specific `Azure.Core` version](#library-versions). This is done by decorating your service namespace with the `@useDependency` decorator from the `typespec-versioning` library.
429
-
430
- Simple TypeSpec specs need only pass the desired `Azure.Core` version into the `@useDependency` decorator:
431
-
432
- ```typespec
433
- @service({
434
- title: "Contoso Widget Manager",
435
- })
436
- @useDependency(Azure.Core.Versions.v1_0_Preview_2)
437
- namespace Contoso.WidgetManager;
438
- ```
439
-
440
- If your spec has [multiple versions](#versioning-your-service), you will need to specify the version of `typespec-azure-core` that was used for each version in your spec. Assuming that there are two versions of `Azure.Core` and each version of your service uses a different one, it would look like this:
441
-
442
- ```typespec
443
- @service({
444
- title: "Contoso Widget Manager",
445
- })
446
- @versioned(Contoso.WidgetManager.Versions)
447
- namespace Contoso.WidgetManager;
448
-
449
- enum Versions {
450
- @useDependency(Azure.Core.Versions.v1_0_Preview_1)
451
- v2022_08_31: "v20220831",
452
-
453
- @useDependency(Azure.Core.Versions.v1_0_Preview_2)
454
- v2022_11_30: "v20221130",
455
- }
456
- ```
457
-
458
- ## Advanced Topics
459
-
460
- Once you have written your first service with `Azure.Core`, you might be interested to try the following features:
461
-
462
- ### Defining singleton resources
463
-
464
- You can define a singleton resource (a resource type with only one instance) by using a string literal for the key type. Imagine we want to expose an analytics endpoint for each `Widget` instance. Here's what it would look like:
465
-
466
- ```typespec
467
- @resource("analytics")
468
- @parentResource(Widget)
469
- model WidgetAnalytics {
470
- @key("analyticsId")
471
- id: "current";
472
-
473
- @doc("The number of uses of the widget.")
474
- useCount: int64;
475
-
476
- @doc("The number of times the widget was repaired.")
477
- repairCount: int64;
478
- }
479
- ```
480
-
481
- You can then use the standard operation signatures with this singleton resource type:
482
-
483
- ```typespec
484
- op getAnalytics is ResourceRead<WidgetAnalytics>;
485
- op updateAnalytics is ResourceCreateOrUpdate<WidgetAnalytics>;
486
- ```
487
-
488
- By using a literal value of `"current"` for `"id"`, the route path for these operations will be the following:
489
-
490
- ```
491
- "/widgets/{widgetName}/analytics/current"
492
- ```
493
-
494
- The operations defined against this singleton resource will also exclude the key parameter because it cannot be changed.
495
-
496
- ## Library Versions
497
-
498
- This is a versioned TypeSpec library which means that you must add the `@useDependency` decorator to your service namespace when you use its contents.
499
-
500
- Here are the current versions:
501
-
502
- - `Azure.Core.Versions.v1_0_Preview_1`
503
- - `Azure.Core.Versions.v1_0_Preview_2`
504
-
505
- See the [Using Azure.Core Versions](#using-azurecore-versions) section for more details on how to use the `@useDependency` decorator.
506
-
507
- ## Library Tour
508
-
509
- The `@azure-tools/typespec-azure-core` library defines the following artifacts:
510
-
511
- - TypeSpec Azure Core Library
512
- - [Models](#models)
513
- - [Operations](#operations)
514
- - [Decorators](#decorators)
515
- - [API](#api)
516
-
517
- ### Models
518
-
519
- The `@azure-tools/typespec-azure-core` library defines the following models:
520
-
521
- | Model | Notes |
522
- | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
523
- | Page<TResource\> | Model for a paged resource. `<TResource>` is the model description of the item. |
524
- | PagedResultMetadata | Contains the metadata associated with a `Page<TResource>`. |
525
- | RequestParameter<T\> | For long-running operations, identifies that a continuation operation request parameter is pulled from the original request. `<T>` is the property name on the original request. |
526
- | ResponseProperty<T\> | For long-running operations, identifies that a continuation operation request parameter is pulled from the response of the previous request. `<T>` is the property name on the previous response. |
527
- | LongRunningStates | Identifies the long-running states associated with a long-running operation. |
528
- | OperationLinkMetadata | Contains the metadata associated with an operation link. |
529
-
530
- ### Operations
531
-
532
- The `@azure-tools/typespec-azure-core` library defines these standard operation templates as basic building blocks that you can expose. You can use `is` to compose the operations to meet the exact needs of your APIs.
533
-
534
- For all of these operation templates, `TResource` is the resource model and `TCustom` allows customization of the operation parameters or response. `TCustom`, if provided, must extend the `Azure.Core.Foundations.CustomizationFields` model, which looks like:
535
-
536
- ```typespec
537
- @doc("The expected shape of model types passed to the TCustom parameter of operation signatures.")
538
- model CustomizationFields {
539
- @doc("An object containing custom parameters that will be included in the operation.")
540
- parameters?: object;
541
-
542
- @doc("An object containing custom properties that will be included in the response.")
543
- response?: object;
544
- }
545
- ```
546
-
547
- | Operation | Notes |
548
- | ------------------------------------------------------------------- | ---------------------------------------------------------------------------------- |
549
- | ResourceCreateOrUpdate<TResource, Traits> | Creates an instance of the resource or updates the existing instance. |
550
- | ResourceCreateOrReplace<TResource, Traits> | Creates an instance of the resource or entirely replaces the existing instance. |
551
- | ResourceCreateWithServiceProvidedName<TResource, Traits> | Creates an instance of the resource while allowing the service to choose the name. |
552
- | ResourceRead<TResource, Traits> | Reads the details of an existing instance of the resource. |
553
- | ResourceDelete<TResource, Traits> | Deletes an existing instance of the resource. |
554
- | ResourceList<TResource, Traits> | Lists instances of the resource type with server-driven paging. |
555
- | ResourceUpdate<TResource, Traits> | Updates an existing instance of the resource. |
556
- | NonPagedResourceList<TResource, Traits> | Resource LIST operation without paging. |
557
- | ResourceAction<TResource, TParams, TResponse, Traits> | Perform a custom action on a specific resource. |
558
- | ResourceCollectionAction<TResource, TParams, TResponse, Traits> | Perform a custom action on a collection of resources. |
559
- | LongRunningResourceCreateOrReplace<TResource, Traits> | Long-running version of the ResourceCreateOrReplace operation. |
560
- | LongRunningResourceCreateOrUpdate<TResource, Traits> | Long-running version of the ResourceCreateOrUpdate operation. |
561
- | LongRunningResourceCreateWithServiceProvidedName<TResource, Traits> | Long-running version of the ResourceCreateWithServieProvidedName operation. |
562
- | LongRunningResourceDelete<TResource, Traits> | Long-running version of the ResourceDelete operation. |
563
- | LongRunningResourceUpdate<TResource, Traits> | Long-running version of the ResourceUpdate operation. |
564
-
565
- ### Decorators
566
-
567
- The `@azure-tools/typespec-azure-core` library defines the following decorators:
568
-
569
- | Declarator | Scope | Usage |
570
- | ------------------ | -------------------------- | --------------------------------------------------------------------------------------------------------- |
571
- | @pagedResult | models | indicates model describes a paged result. |
572
- | @items | model properties | indicates model property that stores the items within a paged result. |
573
- | @nextLink | model properties | indicates model property that contains the continuation information for the next page. |
574
- | @nextPageOperation | operations | indicates operation that will be called for subsequent page requests. |
575
- | @lroStatus | enums and model properties | indicates model or model property that represents long-running operation status. |
576
- | @lroSucceeded | enum members | indicates enum member that corresponds to the long-running operation succeeded status. |
577
- | @lroCanceled | enum members | indicates enum member that corresponds to the long-running operation canceled status. |
578
- | @lroFailed | enum members | indicates enum member that corresponds to the long-running operation failed status. |
579
- | @pollingLocation | model properties | indicates model property that contains the location to poll for operation state. |
580
- | @finalLocation | model properties | indicates model property that contains the final location for the operation result. |
581
- | @operationLink | operations | indicates operation that is linked to the decorated operation by virtue of its `linkType`. |
582
- | @pollingOperation | operations | indicates an operation is a polling operation for a long-running operation. |
583
- | @finalOperation | operations | indicates an operation is the final operation for a long-running operation. |
584
- | @fixed | enum | indicates that an enum should not be treated as extensible, since Azure assumes are enums are extensible. |
585
-
586
- ### API
587
-
588
- The `@azure-tools/typespec-azure-core` library defines the following API functions that emitter authors can use for development:
589
-
590
- | Name | Entity | Returns | Description |
591
- | -------------------- | ---------------------------------- | ----------------------------------- | ---------------------------------------------------------------------------------------------------- |
592
- | getPagedResult | models and operations | PagedResultMetadata? | Returns the `PagedResultMetadata` if associated with a model or operation return type. |
593
- | getItems | model properties | boolean | Returns `true` if the model property is annotated with `@items`. |
594
- | getNextLink | model properties | boolean | Returns `true` if the model property is annotated with `@nextLink`. |
595
- | getLongRunningStates | enums, models and model properties | LongRunningStates? | Returns the `LongRunningStates` associated with an entity. |
596
- | isLroSucceededState | enum members | boolean | Returns `true` if the enum member represents a "succeeded" state. |
597
- | isLroCanceledState | enum members | boolean | Returns `true` if the enum member represents a "canceled" state. |
598
- | isLroFailedState | enum members | boolean | Returns `true` if the enum member represents a "failed" state. |
599
- | isPollingLocation | model properties | boolean | Returns `true` if the model property is annotated with `@pollingLocation`. |
600
- | isFinalLocation | model properties | boolean | Returns `true` if the model property is annotated with `@finalLocation`. |
601
- | getOperationLink | operations | OperationLinkMetadata? | Returns the `OperationLinkMetadata` for an operation with a specific `linkType`. |
602
- | getOperationLinks | operations | Map<string, OperationLinkMetadata>? | Returns a `Map` of `OperationLinkMetadata` objects for an Operation where the key is the `linkType`. |
603
- | isFixed | enum | boolean | Returns `true` if the enum is annotated with `@fixed`. |
604
-
605
- ## Generating an OpenAPI Specification
606
-
607
- To generate an OpenAPI v2 (Swagger) specification from the service definition, run the following command inside of the project folder:
608
-
609
- ```
610
- tsp compile . --emit @azure-tools/typespec-autorest
611
- ```
612
-
613
- This will create a file in the `tsp-output` subfolder called `openapi.json`.
614
-
615
- You can learn more about the `typespec-autorest` emitter and its options by reading its [README.md](https://github.com/Azure/typespec-azure/blob/main/packages/typespec-autorest/README.md).
14
+ ## Documentation
616
15
 
617
- ## A Complete Example
16
+ [Getting Started Tutorial](https://azure.github.io/typespec-azure/docs/getstarted/installation)
618
17
 
619
- A complete version of the `Contoso.WidgetManager` specification can be found in the [`widget-manager` sample folder](https://github.com/Azure/typespec-azure/blob/main/packages/typespec-samples/data-plane/widget-manager/main.tsp).
18
+ [How-tos and Examples](https://azure.github.io/typespec-azure/docs/howtos/Azure%20Core/long-running-operations)
620
19
 
621
- You can experiment with the full sample on the [TypeSpec Azure Playground](https://cadlplayground.z22.web.core.windows.net/cadl-azure/?sample=Azure%20Core%20Data%20Plane20Service)!
20
+ [Reference](https://azure.github.io/typespec-azure/docs/libraries/azure-core/reference)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azure-tools/typespec-azure-core",
3
- "version": "0.31.0-dev.5",
3
+ "version": "0.31.0-dev.6",
4
4
  "author": "Microsoft Corporation",
5
5
  "description": "TypeSpec Azure Core library",
6
6
  "homepage": "https://azure.github.io/typespec-azure",