Skip to content
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

Rkmanda/fix body top level properties for list #729

Merged
merged 5 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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