Skip to content

Commit 87e56e3

Browse files
committed
Deprecate @list decorator in favor of rest's @listsResource
1 parent 8277fdf commit 87e56e3

8 files changed

Lines changed: 86 additions & 1 deletion

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@typespec/compiler",
5+
"comment": "Deprecate `@list` decorator in favor of `@listsResource` in `@typespec/rest`",
6+
"type": "none"
7+
},
8+
{
9+
"packageName": "@typespec/compiler",
10+
"comment": "Deprecate `isListOperation` function in favor of `isListOperation` in `@typespec/rest`",
11+
"type": "none"
12+
},
13+
{
14+
"packageName": "@typespec/compiler",
15+
"comment": "Deprecate `getListOperationType` function",
16+
"type": "none"
17+
}
18+
],
19+
"packageName": "@typespec/compiler"
20+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@typespec/library-linter",
5+
"comment": "",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@typespec/library-linter"
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@typespec/rest",
5+
"comment": "Add `isListOperation` function migrated from `@typespec/compiler`",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@typespec/rest"
10+
}

docs/standard-library/built-in-decorators.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,25 @@ Invalid,
305305
```
306306

307307

308+
### `@list` {#@list}
309+
310+
Mark this operation as a `list` operation for resource types.
311+
312+
```typespec
313+
@list(listedType?: Model)
314+
```
315+
316+
#### Target
317+
318+
`Operation`
319+
320+
#### Parameters
321+
| Name | Type | Description |
322+
|------|------|-------------|
323+
| listedType | `Model` | Optional type of the items in the list. |
324+
325+
326+
308327
### `@maxItems` {#@maxItems}
309328

310329
Specify the maximum number of items this array should have.

packages/compiler/lib/decorators.tsp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,14 @@ extern dec maxValueExclusive(target: numeric | ModelProperty, value: valueof num
234234
*/
235235
extern dec secret(target: string | ModelProperty);
236236

237+
/**
238+
* Mark this operation as a `list` operation for resource types.
239+
* @deprecated Use the `listsResource` decorator in `@typespec/rest` instead.
240+
* @param listedType Optional type of the items in the list.
241+
*/
242+
@deprecated("Use the `listsResource` decorator in `@typespec/rest` instead.")
243+
extern dec list(target: Operation, listedType?: Model);
244+
237245
/**
238246
* Attaches a tag to an operation, interface, or namespace. Multiple `@tag` decorators can be specified to attach multiple tags to a TypeSpec element.
239247
* @param tag Tag value

packages/compiler/src/lib/decorators.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,9 @@ export function $withoutDefaultValues(context: DecoratorContext, target: Model)
774774

775775
const listPropertiesKey = createStateSymbol("listProperties");
776776

777+
/**
778+
* @deprecated Use the `listsResource` decorator in `@typespec/rest` instead.
779+
*/
777780
export function $list(context: DecoratorContext, target: Operation, listedType?: Type) {
778781
if (listedType && listedType.kind === "TemplateParameter") {
779782
// Silently return because this is probably being used in a templated interface
@@ -790,10 +793,16 @@ export function $list(context: DecoratorContext, target: Operation, listedType?:
790793
context.program.stateMap(listPropertiesKey).set(target, listedType);
791794
}
792795

796+
/**
797+
* @deprecated This function is unused and will be removed in a future release.
798+
*/
793799
export function getListOperationType(program: Program, target: Type): Model | undefined {
794800
return program.stateMap(listPropertiesKey).get(target);
795801
}
796802

803+
/**
804+
* @deprecated Use `isListOperation` in `@typespec/rest` instead.
805+
*/
797806
export function isListOperation(program: Program, target: Operation): boolean {
798807
// The type stored for the operation
799808
return program.stateMap(listPropertiesKey).has(target);

packages/library-linter/src/linter.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ const excludeDecoratorSignature = new Set([
4545
"@docFromComment",
4646
"@indexer",
4747
"@test",
48-
"@list", // TODO check if we actually need this one https://github.com/microsoft/typespec/issues/1978
4948
"@resourceTypeForKeyParam", // TODO check if we actually need this one https://github.com/microsoft/typespec/issues/1981
5049
]);
5150
function validateDecoratorSignature(program: Program) {

packages/rest/src/rest.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,16 @@ export function $listsResource(context: DecoratorContext, entity: Operation, res
421421
setResourceOperation(context, entity, resourceType, "list");
422422
}
423423

424+
/**
425+
* Returns `true` if the given operation is marked as a list operation.
426+
* @param program the TypeSpec program
427+
* @param target the target operation
428+
*/
429+
export function isListOperation(program: Program, target: Operation): boolean {
430+
// Is the given operation a `list` operation?
431+
return getResourceOperation(program, target)?.operation === "list";
432+
}
433+
424434
function lowerCaseFirstChar(str: string): string {
425435
return str[0].toLocaleLowerCase() + str.substring(1);
426436
}

0 commit comments

Comments
 (0)