Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"changes": [
{
"packageName": "@typespec/compiler",
"comment": "Deprecate `@list` decorator in favor of `@listsResource` in `@typespec/rest`",
Comment thread
daviwil marked this conversation as resolved.
Outdated
"type": "none"
},
{
"packageName": "@typespec/compiler",
"comment": "Deprecate `isListOperation` function in favor of `isListOperation` in `@typespec/rest`",
Comment thread
daviwil marked this conversation as resolved.
Outdated
"type": "none"
},
{
"packageName": "@typespec/compiler",
"comment": "Deprecate `getListOperationType` function",
Comment thread
daviwil marked this conversation as resolved.
Outdated
"type": "none"
}
],
"packageName": "@typespec/compiler"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@typespec/library-linter",
"comment": "",
"type": "none"
}
],
"packageName": "@typespec/library-linter"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@typespec/rest",
"comment": "Add `isListOperation` function migrated from `@typespec/compiler`",
"type": "none"
}
],
"packageName": "@typespec/rest"
}
19 changes: 19 additions & 0 deletions docs/standard-library/built-in-decorators.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,25 @@ Invalid,
```


### `@list` {#@list}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is unfortunate that we get the doc now that it is deprecated

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be nice if the deprecation notice came through with it. The only other option is to just take out the extern definition and put the exception for @list back into library-linter, but is that worse?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I guess that is dependent on the design meeting that was inconclusive last week :(


Mark this operation as a `list` operation for resource types.

```typespec
@list(listedType?: Model)
```

#### Target

`Operation`

#### Parameters
| Name | Type | Description |
|------|------|-------------|
| listedType | `Model` | Optional type of the items in the list. |



### `@maxItems` {#@maxItems}

Specify the maximum number of items this array should have.
Expand Down
7 changes: 7 additions & 0 deletions packages/compiler/lib/decorators.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,13 @@ extern dec maxValueExclusive(target: numeric | ModelProperty, value: valueof num
*/
extern dec secret(target: string | ModelProperty);

/**
* Mark this operation as a `list` operation for resource types.
* @deprecated Use the `listsResource` decorator in `@typespec/rest` instead.
* @param listedType Optional type of the items in the list.
*/
extern dec list(target: Operation, listedType?: Model);

/**
* Attaches a tag to an operation, interface, or namespace. Multiple `@tag` decorators can be specified to attach multiple tags to a TypeSpec element.
* @param tag Tag value
Expand Down
9 changes: 9 additions & 0 deletions packages/compiler/src/lib/decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,9 @@ export function $withoutDefaultValues(context: DecoratorContext, target: Model)

const listPropertiesKey = createStateSymbol("listProperties");

/**
* @deprecated Use the `listsResource` decorator in `@typespec/rest` instead.
Comment thread
timotheeguerin marked this conversation as resolved.
*/
export function $list(context: DecoratorContext, target: Operation, listedType?: Type) {
if (listedType && listedType.kind === "TemplateParameter") {
// Silently return because this is probably being used in a templated interface
Expand All @@ -790,10 +793,16 @@ export function $list(context: DecoratorContext, target: Operation, listedType?:
context.program.stateMap(listPropertiesKey).set(target, listedType);
}

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

/**
* @deprecated Use `isListOperation` in `@typespec/rest` instead.
*/
export function isListOperation(program: Program, target: Operation): boolean {
// The type stored for the operation
return program.stateMap(listPropertiesKey).has(target);
Expand Down
1 change: 0 additions & 1 deletion packages/library-linter/src/linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ const excludeDecoratorSignature = new Set([
"@docFromComment",
"@indexer",
"@test",
"@list", // TODO check if we actually need this one https://github.com/microsoft/typespec/issues/1978
"@resourceTypeForKeyParam", // TODO check if we actually need this one https://github.com/microsoft/typespec/issues/1981
]);
function validateDecoratorSignature(program: Program) {
Expand Down
14 changes: 10 additions & 4 deletions packages/rest/src/rest.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
$list,
createDiagnosticCollector,
DecoratorContext,
DiagnosticResult,
Expand Down Expand Up @@ -412,15 +411,22 @@ export function $deletesResource(
}

export function $listsResource(context: DecoratorContext, entity: Operation, resourceType: Model) {
// Add the @list decorator too so that collection routes are generated correctly
context.call($list, entity, resourceType);

// Add path segment for resource type key
context.call($segmentOf, entity, resourceType);

setResourceOperation(context, entity, resourceType, "list");
}

/**
* Returns `true` if the given operation is marked as a list operation.
* @param program the TypeSpec program
* @param target the target operation
*/
export function isListOperation(program: Program, target: Operation): boolean {
// Is the given operation a `list` operation?
return getResourceOperation(program, target)?.operation === "list";
}

function lowerCaseFirstChar(str: string): string {
return str[0].toLocaleLowerCase() + str.substring(1);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/rest/test/routes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ describe("rest: routes", () => {
@autoRoute
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lmazuel do we want to talk about this deprecation, this was an undocumented decorator in the compiler that was only used internally in the rest library.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any thoughts on this?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably just bring it up in the DPG meeting today at 11

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like folks are OK with this one going in!

interface SubInterface {
@get
@list(Subthing)
@listsResource(Subthing)
@segmentOf(Subthing)
GetSubthings(...KeysOf<Thing>): string;

Expand Down