@@ -93,8 +93,10 @@ export async function updateClients(
93
93
if ( modelId && kind ) {
94
94
const entry = resourceModelToMetadataMap . get ( modelId ) ;
95
95
entry ?. methods . push ( {
96
- id : method . crossLanguageDefinitionId ,
97
- kind
96
+ methodId : method . crossLanguageDefinitionId ,
97
+ kind,
98
+ operationPath : method . operation . path ,
99
+ operationScope : getOperationScope ( method . operation . path )
98
100
} ) ;
99
101
if ( entry && ! entry . resourceType ) {
100
102
entry . resourceType = calculateResourceTypeFromPath (
@@ -115,8 +117,9 @@ export async function updateClients(
115
117
}
116
118
}
117
119
118
- // after the resourceIdPattern has been populated, we can set the parentResourceId
120
+ // after the resourceIdPattern has been populated, we can set the parentResourceId and the resource scope of each resource method
119
121
for ( const [ modelId , metadata ] of resourceModelToMetadataMap ) {
122
+ // get parent resource model id
120
123
const parentResourceModelId = getParentResourceModelId (
121
124
sdkContext ,
122
125
models . get ( modelId )
@@ -126,6 +129,14 @@ export async function updateClients(
126
129
parentResourceModelId
127
130
) ?. resourceIdPattern ;
128
131
}
132
+
133
+ // figure out the resourceScope of all resource methods
134
+ for ( const method of metadata . methods ) {
135
+ method . resourceScope = getResourceScopeOfMethod (
136
+ method . operationPath ,
137
+ resourceModelToMetadataMap . values ( )
138
+ ) ;
139
+ }
129
140
}
130
141
131
142
// the last step, add the decorator to the resource model
@@ -291,6 +302,27 @@ function getResourceScope(model: InputModelType): ResourceScope {
291
302
return ResourceScope . ResourceGroup ; // all the templates work as if there is a resource group decorator when there is no such decorator
292
303
}
293
304
305
+ function getResourceScopeOfMethod (
306
+ path : string ,
307
+ resources : MapIterator < ResourceMetadata >
308
+ ) : string | undefined {
309
+ // loop all possible resource metadata and see if some of them match the operation path of this method as a prefix
310
+ const candidates : string [ ] = [ ] ;
311
+ for ( const otherMetadata of resources ) {
312
+ if (
313
+ otherMetadata . resourceIdPattern &&
314
+ path . startsWith ( otherMetadata . resourceIdPattern )
315
+ ) {
316
+ candidates . push ( otherMetadata . resourceIdPattern ) ;
317
+ }
318
+ }
319
+ // finds the longest resource path id in candidates as the resource scope
320
+ if ( candidates . length > 0 ) {
321
+ return candidates . reduce ( ( a , b ) => ( a . length > b . length ? a : b ) ) ;
322
+ }
323
+ return undefined ;
324
+ }
325
+
294
326
// TODO -- this logic needs to be refined in the near future.
295
327
function getOperationScope ( path : string ) : ResourceScope {
296
328
if (
0 commit comments