Skip to content

no-explicit-routes-resource-ops

Id
@azure-tools/typespec-azure-core/no-explicit-routes-resource-ops

The @route decorator should not be used on standard resource operation signatures.

The @route decorator should not be used on standard resource operation signatures. Standard resource operations already have well-defined routes. If you need to add a route prefix, use @route on an interface or namespace instead.

  • Area: API

May indicate non-standard resource paths, though a static route is sometimes legitimate.

Using @route directly on resource operations:

@resource("widgets")
model Widget {
@key name: string;
}
@route("/api/widgets/{name}")
op readWidget is Azure.Core.StandardResourceOperations.ResourceRead<Widget>;
@route("/api/widgets")
op listWidgets is Azure.Core.StandardResourceOperations.ResourceList<Widget>;

Let standard resource operations define their own routes:

@resource("widgets")
model Widget {
@key name: string;
}
// route: /widgets/{name}
op readWidget is Azure.Core.StandardResourceOperations.ResourceRead<Widget>;
// route: /widgets
op listWidgets is Azure.Core.StandardResourceOperations.ResourceList<Widget>;

Suppress when the path is most naturally expressed as a static route (e.g. Network implementing Microsoft.Compute APIs for Virtual Machine Scale Sets); otherwise use the standard operation templates.