-
Notifications
You must be signed in to change notification settings - Fork 380
Add @sharedRoute decorator and decouple it from @route
#1798
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0b9c7b8
83f4677
7ab8010
ebc926c
aa639c6
69c784d
d2564b3
08da601
a9b23f3
311fabb
8cf9bd2
edcc87d
665dcf9
d2e7e25
279feea
60d7fbb
1c35071
994e5d2
54a0d04
7a29f78
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "changes": [ | ||
| { | ||
| "packageName": "@typespec/http", | ||
| "comment": "Add `@sharedRoute` decorator for marking operations as sharing a route with other operations", | ||
| "type": "none" | ||
| } | ||
| ], | ||
| "packageName": "@typespec/http" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "changes": [ | ||
| { | ||
| "packageName": "@typespec/http", | ||
| "comment": "Deprecate the `shared` option in the `@route` decorator. `@sharedRoute` is the new way to accomplish the same behavior.", | ||
| "type": "none" | ||
| } | ||
| ], | ||
| "packageName": "@typespec/http" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "changes": [ | ||
| { | ||
| "packageName": "@typespec/openapi3", | ||
| "comment": "", | ||
| "type": "none" | ||
| } | ||
| ], | ||
| "packageName": "@typespec/openapi3" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "changes": [ | ||
| { | ||
| "packageName": "@typespec/rest", | ||
| "comment": "", | ||
| "type": "none" | ||
| } | ||
| ], | ||
| "packageName": "@typespec/rest" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "changes": [ | ||
| { | ||
| "packageName": "@typespec/rest", | ||
| "comment": "Add validation to ensure that @action or @collectionAction operations have a specified name when used with @sharedRoute", | ||
| "type": "none" | ||
| } | ||
| ], | ||
| "packageName": "@typespec/rest" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -216,28 +216,43 @@ export function setRoute(context: DecoratorContext, entity: Type, details: Route | |
| const state = context.program.stateMap(routesKey); | ||
|
|
||
| if (state.has(entity) && entity.kind === "Namespace") { | ||
| const existingValue: RoutePath = state.get(entity); | ||
| if (existingValue.path !== details.path) { | ||
| const existingPath: string | undefined = state.get(entity); | ||
| if (existingPath !== details.path) { | ||
| reportDiagnostic(context.program, { | ||
| code: "duplicate-route-decorator", | ||
| messageId: "namespace", | ||
| target: entity, | ||
| }); | ||
| } | ||
| } else { | ||
| state.set(entity, details); | ||
| state.set(entity, details.path); | ||
| if (entity.kind === "Operation" && details.shared) { | ||
| setSharedRoute(context.program, entity as Operation); | ||
| } | ||
|
Comment on lines
+229
to
+231
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should deprecate this pattern if we are going with an
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would also like to deprecate it if we proceed with
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That, and you should be able to mark it with
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That, and you should be able to mark it with
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can just call
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also if you add the type for the options I don't think it will emit a diagnostic automatically here but we could add that support
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Possible that just calling
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even better, we should add a migration script to do this for people
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added deprecation for the old |
||
| } | ||
| } | ||
|
|
||
| const sharedRoutesKey = createStateSymbol("sharedRoutes"); | ||
|
|
||
| export function setSharedRoute(program: Program, operation: Operation) { | ||
| program.stateMap(sharedRoutesKey).set(operation, true); | ||
| } | ||
|
|
||
| export function isSharedRoute(program: Program, operation: Operation): boolean { | ||
| return program.stateMap(routesKey).get(operation)?.shared; | ||
| return program.stateMap(sharedRoutesKey).get(operation) === true; | ||
| } | ||
|
|
||
| export function getRoutePath( | ||
| program: Program, | ||
| entity: Namespace | Interface | Operation | ||
| ): RoutePath | undefined { | ||
| return program.stateMap(routesKey).get(entity); | ||
| const path = program.stateMap(routesKey).get(entity); | ||
| return path | ||
| ? { | ||
| path, | ||
| shared: entity.kind === "Operation" && isSharedRoute(program, entity as Operation), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The original logic simply plumbed details through without regard to whether it was an operation, interface, etc. so this change would introduce a behavioral change.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the original design, applying |
||
| } | ||
| : undefined; | ||
| } | ||
|
|
||
| const routeOptionsKey = createStateSymbol("routeOptions"); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.