Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 29, 2025

Fixes the @actionSeparator decorator target validation to narrow allowed targets from Model | ModelProperty | Operation to Operation | Interface | Namespace.

Problem

The @actionSeparator decorator was incorrectly defined to accept Model and ModelProperty targets, but these targets don't work properly with the decorator's functionality. When users tried to apply @actionSeparator to interfaces (a logical use case), they would get confusing errors:

@actionSeparator(":")
interface OnOp {
  @autoRoute
  @action
  op do(): void;
}
// Error: Cannot apply @actionSeparator decorator to OnOp since it is not assignable to Model | ModelProperty | Operation

Additionally, applying the decorator to models or model properties would be accepted but wouldn't function correctly.

Solution

Updated the decorator definition to only accept targets where it actually works:

  • Operation: Direct application to operations (existing functionality preserved)
  • Interface: Now properly accepted for interface-level configuration
  • Namespace: Added for namespace-level configuration support

Before:

extern dec actionSeparator(target: Model | ModelProperty | Operation, separator: valueof "/" | ":" | "/:")

After:

extern dec actionSeparator(target: Operation | Interface | Namespace, separator: valueof "/" | ":" | "/:")

Changes Made

  • Updated TypeScript decorator function signature in packages/rest/src/rest.ts
  • Updated TypeSpec decorator definition in packages/rest/lib/rest-decorators.tsp
  • Regenerated TypeScript definitions in packages/rest/generated-defs/TypeSpec.Rest.ts
  • Added comprehensive test suite validating all allowed and disallowed targets
  • Updated README documentation to reflect the target change

Validation

The fix now correctly:

  • ✅ Accepts @actionSeparator on Operations, Interfaces, and Namespaces
  • ✅ Rejects @actionSeparator on Models and ModelProperties with clear error messages
  • ✅ Preserves all existing functionality for operation-level usage
  • ✅ Generates correct routes with all separator values (/, :, /:)

All existing tests continue to pass (54/54), ensuring no regressions were introduced.

Resolves the original issue where users couldn't apply @actionSeparator to interfaces, and prevents future confusion by only allowing the decorator on targets where it actually functions correctly.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • telemetry.astro.build
    • Triggering command: node /home/REDACTED/work/typespec/typespec/website/node_modules/.bin/../astro/astro.js build (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>[Bug]: @actionSerparator works only when defined on operation, but allowed on models and models properties</issue_title>
<issue_description>### Describe the bug

There's no well written documentation on how to use it either, so it might be that I'm doing it wrong.

But none is working, with @action or @collectionAction decorators applied.

Reproduction

https://typespec.io/playground/?e=%40typespec%2Fopenapi3&c=aW1wb3J0ICJAdHlwZXNwZWMvaHR0cCI7CtIZcmVzdCI7Cgp1c2luZyBIdHRwO8cMUmVzdDsKCkBzZXJ2aWNlCm5hbWVzcGFjZSBUxBogCgoKQHJvdXRlKCJvbi1vcCIpyyNPbk9wIHsKICBAYXV0b1LEJ8UNY3Rpb27KClNlcGFyYXRvcigiOiIpCiAgb3AgZG8oKTogdm9pZDsKfc1kbW9kZWzPZ03EFMdq1lPFNiBFbnRpdHnFKSAgaWQ6IHN0cmluZzsKICB9CvEAqGNvbGxlxU9BxQYoxj%2FET8dn%2FwCs5gCsLXByb3BldHn0ALRQxBty5wCT8wCk%2BADP%2FwC%2B%2FwC%2B%2BgC%2B&options=%7B%7D&vs=%7B%7D

Checklist

<agent_instructions>Narrow the target of the @actionSeparator to include only operations, interfaces, and namespaces. Ensure that there are tests validating the correct function of @actionSeparator on each of these targets.</agent_instructions>

Comments on the Issue (you are @copilot in this section)

Fixes #8589

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@Copilot Copilot AI changed the title [WIP] [Bug]: @actionSerparator works only when defined on operation, but allowed on models and models properties Fix @actionSeparator decorator to only accept Operation, Interface, and Namespace targets Sep 29, 2025
@Copilot Copilot AI requested a review from markcowl September 29, 2025 19:17
Copilot finished work on behalf of markcowl September 29, 2025 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: @actionSerparator works only when defined on operation, but allowed on models and models properties
2 participants