@@ -35,6 +35,7 @@ import {
3535 armResourceListName ,
3636 armResourceReadName ,
3737 armResourceUpdateName ,
38+ extensionResourceOperationName ,
3839 nonResourceMethodMetadata ,
3940 parentResourceName ,
4041 resourceGroupResource ,
@@ -155,9 +156,9 @@ export async function updateClients(
155156 for ( const [ modelId , metadata ] of resourceModelToMetadataMap ) {
156157 // TODO: handle the case where there is no parentResourceId but resourceIdPattern is missing
157158 if ( metadata . resourceIdPattern === "" && metadata . parentResourceModelId ) {
158- resourceModelToMetadataMap . get ( metadata . parentResourceModelId ) ?. methods . push (
159- ... metadata . methods
160- ) ;
159+ resourceModelToMetadataMap
160+ . get ( metadata . parentResourceModelId )
161+ ?. methods . push ( ... metadata . methods ) ;
161162 resourceModelToMetadataMap . delete ( modelId ) ;
162163 }
163164 }
@@ -193,36 +194,95 @@ function parseResourceOperation(
193194) : [ ResourceOperationKind , string | undefined ] | undefined {
194195 const decorators = serviceMethod ?. __raw ?. decorators ;
195196 for ( const decorator of decorators ?? [ ] ) {
196- if ( decorator . definition ?. name === armResourceReadName ) {
197- return [
198- ResourceOperationKind . Get ,
199- getResourceModelId ( sdkContext , decorator )
200- ] ;
201- } else if ( decorator . definition ?. name == armResourceCreateOrUpdateName ) {
202- return [
203- ResourceOperationKind . Create ,
204- getResourceModelId ( sdkContext , decorator )
205- ] ;
206- } else if ( decorator . definition ?. name == armResourceUpdateName ) {
207- return [
208- ResourceOperationKind . Update ,
209- getResourceModelId ( sdkContext , decorator )
210- ] ;
211- } else if ( decorator . definition ?. name == armResourceDeleteName ) {
212- return [
213- ResourceOperationKind . Delete ,
214- getResourceModelId ( sdkContext , decorator )
215- ] ;
216- } else if ( decorator . definition ?. name == armResourceListName ) {
217- return [
218- ResourceOperationKind . List ,
219- getResourceModelId ( sdkContext , decorator )
220- ] ;
221- } else if ( decorator . definition ?. name == armResourceActionName ) {
222- return [
223- ResourceOperationKind . Action ,
224- getResourceModelId ( sdkContext , decorator )
225- ] ;
197+ switch ( decorator . definition ?. name ) {
198+ case armResourceReadName :
199+ return [
200+ ResourceOperationKind . Get ,
201+ getResourceModelId ( sdkContext , decorator )
202+ ] ;
203+ case armResourceCreateOrUpdateName :
204+ return [
205+ ResourceOperationKind . Create ,
206+ getResourceModelId ( sdkContext , decorator )
207+ ] ;
208+ case armResourceUpdateName :
209+ return [
210+ ResourceOperationKind . Update ,
211+ getResourceModelId ( sdkContext , decorator )
212+ ] ;
213+ case armResourceDeleteName :
214+ return [
215+ ResourceOperationKind . Delete ,
216+ getResourceModelId ( sdkContext , decorator )
217+ ] ;
218+ case armResourceListName :
219+ return [
220+ ResourceOperationKind . List ,
221+ getResourceModelId ( sdkContext , decorator )
222+ ] ;
223+ case armResourceActionName :
224+ return [
225+ ResourceOperationKind . Action ,
226+ getResourceModelId ( sdkContext , decorator )
227+ ] ;
228+ case extensionResourceOperationName :
229+ switch ( decorator . args [ 2 ] . jsValue ) {
230+ case "read" :
231+ return [
232+ ResourceOperationKind . Get ,
233+ getResourceModelIdCore (
234+ sdkContext ,
235+ decorator . args [ 1 ] . value as Model ,
236+ decorator . definition ?. name
237+ )
238+ ] ;
239+ case "createOrUpdate" :
240+ return [
241+ ResourceOperationKind . Create ,
242+ getResourceModelIdCore (
243+ sdkContext ,
244+ decorator . args [ 1 ] . value as Model ,
245+ decorator . definition ?. name
246+ )
247+ ] ;
248+ case "update" :
249+ return [
250+ ResourceOperationKind . Update ,
251+ getResourceModelIdCore (
252+ sdkContext ,
253+ decorator . args [ 1 ] . value as Model ,
254+ decorator . definition ?. name
255+ )
256+ ] ;
257+ case "delete" :
258+ return [
259+ ResourceOperationKind . Delete ,
260+ getResourceModelIdCore (
261+ sdkContext ,
262+ decorator . args [ 1 ] . value as Model ,
263+ decorator . definition ?. name
264+ )
265+ ] ;
266+ case "list" :
267+ return [
268+ ResourceOperationKind . List ,
269+ getResourceModelIdCore (
270+ sdkContext ,
271+ decorator . args [ 1 ] . value as Model ,
272+ decorator . definition ?. name
273+ )
274+ ] ;
275+ case "action" :
276+ return [
277+ ResourceOperationKind . Action ,
278+ getResourceModelIdCore (
279+ sdkContext ,
280+ decorator . args [ 1 ] . value as Model ,
281+ decorator . definition ?. name
282+ )
283+ ] ;
284+ }
285+ return undefined ;
226286 }
227287 }
228288 return undefined ;
@@ -244,18 +304,27 @@ function getResourceModelId(
244304 decorator ?: DecoratorApplication
245305) : string | undefined {
246306 if ( ! decorator ) return undefined ;
247- const model = getClientType (
307+ return getResourceModelIdCore (
248308 sdkContext ,
249- decorator . args [ 0 ] . value as Model
250- ) as SdkModelType ;
309+ decorator . args [ 0 ] . value as Model ,
310+ decorator . definition ?. name
311+ ) ;
312+ }
313+
314+ function getResourceModelIdCore (
315+ sdkContext : CSharpEmitterContext ,
316+ decoratorModel : Model ,
317+ decoratorName ?: string
318+ ) : string | undefined {
319+ const model = getClientType ( sdkContext , decoratorModel ) as SdkModelType ;
251320 if ( model ) {
252321 return model . crossLanguageDefinitionId ;
253322 } else {
254323 sdkContext . logger . reportDiagnostic ( {
255324 code : "general-error" ,
256325 messageId : "default" ,
257326 format : {
258- message : `Resource model not found for decorator ${ decorator . decorator . name } `
327+ message : `Resource model not found for decorator ${ decoratorName } `
259328 } ,
260329 target : NoTarget
261330 } ) ;
@@ -369,7 +438,11 @@ function getOperationScope(path: string): ResourceScope {
369438 return ResourceScope . ResourceGroup ;
370439 } else if ( path . startsWith ( "/subscriptions/{subscriptionId}/" ) ) {
371440 return ResourceScope . Subscription ;
372- } else if ( path . startsWith ( "/providers/Microsoft.Management/managementGroups/{managementGroupId}/" ) ) {
441+ } else if (
442+ path . startsWith (
443+ "/providers/Microsoft.Management/managementGroups/{managementGroupId}/"
444+ )
445+ ) {
373446 return ResourceScope . ManagementGroup ;
374447 }
375448 return ResourceScope . Tenant ; // all the templates work as if there is a tenant decorator when there is no such decorator
0 commit comments