Skip to content

Commit

Permalink
Rkmanda/fix body top level properties for list (#729)
Browse files Browse the repository at this point in the history
* Exclude List calls from BodyTopLevelProperties rule

* fix

* There was lint error replaced var with let

* added listoperation check with Get condition and added test

---------

Co-authored-by: Tejaswi Salaigari <[email protected]>
  • Loading branch information
rkmanda and tejaswiMinnu authored Aug 12, 2024
1 parent 66fe65f commit 35f6dea
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
23 changes: 22 additions & 1 deletion packages/rulesets/src/native/utilities/arm-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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"))
Expand Down

0 comments on commit 35f6dea

Please sign in to comment.