diff --git a/packages/rulesets/src/native/tests/resources/body-top-level-properties-real-swagger.json b/packages/rulesets/src/native/tests/resources/body-top-level-properties-real-swagger.json index b8068bba0..ec7af1a30 100644 --- a/packages/rulesets/src/native/tests/resources/body-top-level-properties-real-swagger.json +++ b/packages/rulesets/src/native/tests/resources/body-top-level-properties-real-swagger.json @@ -66,6 +66,40 @@ "nextLinkName": null } } + }, + "/{resourceUri}/providers/microsoft.insights/metricNamespaces/{metricNamespaces}": { + "get": { + "tags": [ + "metricNamespaces" + ], + "operationId": "MetricNamespaces_List", + "description": "Lists the metric namespaces for the resource.", + "parameters": [ + { + "$ref": "#/parameters/ResourceUriParameter" + }, + { + "$ref": "#/parameters/StartTimeParameter" + } + ], + "responses": { + "default": { + "description": "Error response describing why the operation failed.", + "schema": { + "$ref": "#/definitions/ErrorResponse" + } + }, + "200": { + "description": "Successful request to get the list of metric namespaces", + "schema": { + "$ref": "#/definitions/MetricNamespaceCollection" + } + } + }, + "x-ms-pageable": { + "nextLinkName": null + } + } } }, "definitions": { diff --git a/packages/rulesets/src/native/utilities/arm-helper.ts b/packages/rulesets/src/native/utilities/arm-helper.ts index 24e6a2157..75271a3cd 100644 --- a/packages/rulesets/src/native/utilities/arm-helper.ts +++ b/packages/rulesets/src/native/utilities/arm-helper.ts @@ -117,6 +117,7 @@ export class ArmHelper { private populateResources(doc: any, specPath: string) { const operations = this.populateOperations(doc, specPath) + for (const op of operations) { const resourceInfo = this.extractResourceInfo(op.responseSchema, specPath) // if no response or response with no $ref , it's deemed not a resource @@ -134,6 +135,24 @@ export class ArmHelper { } } + private isListOperation(op: Operation) { + const path = op.apiPath + if (path.includes(".")) { + // Get the portion of the api path to the right of the provider namespace by splitting the path by '.' and taking the last element + const splitNamespace = path.split(".") + if (path.includes("/")) { + const segments = splitNamespace[splitNamespace.length - 1].split("/") + + // If the last segment split by '/' has even segments, then the operation is a list operation + if (segments.length % 2 == 0) { + return true + } + } + } + + return false + } + private getXmsResources() { for (const name of Object.keys(this.innerDoc.definitions || {})) { const model = this.getInternalModel(name) @@ -295,7 +314,9 @@ export class ArmHelper { ) const resWithPutOrPatch = includeGet ? localResourceModels.filter((re) => - re.operations.some((op) => op.httpMethod === "get" || op.httpMethod === "put" || op.httpMethod == "patch"), + re.operations.some( + (op) => (op.httpMethod === "get" && !this.isListOperation(op)) || op.httpMethod === "put" || op.httpMethod == "patch", + ), ) : localResourceModels.filter((re) => re.operations.some((op) => op.httpMethod === "put" || op.httpMethod == "patch")) const reWithPostOnly = resWithXmsRes.filter((re) => re.operations.every((op) => op.httpMethod === "post"))