Skip to content

Implement RPC-Policy-V1-03 #486

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

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
Draft
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
18 changes: 18 additions & 0 deletions packages/rulesets/src/spectral/az-arm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { oas2 } from "@stoplight/spectral-formats"
import { falsy, pattern, truthy } from "@stoplight/spectral-functions"
import common from "./az-common"
import verifyArmPath from "./functions/arm-path-validation"
import avoidFreeFormObjects from "./functions/avoid-free-form-objects"
import bodyParamRepeatedInfo from "./functions/body-param-repeated-info"
import { camelCase } from "./functions/camel-case"
import collectionObjectPropertiesNaming from "./functions/collection-object-properties-naming"
Expand Down Expand Up @@ -584,6 +585,23 @@ const ruleset: any = {
},
},

///
/// ARM RPC rules for Policy
///

// RPC Code: RPC-Policy-V1-03
AvoidFreeFormObjects: {
description: "Per ARM PRC guidelines free-form objects should be avoided",
message: "{{error}}",
severity: "error",
resolved: true,
formats: [oas2],
given: "$.definitions",
then: {
function: avoidFreeFormObjects,
},
},

///
/// ARM rules without an RPC code
///
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { getProperty } from "./utils"

export const avoidFreeFormObjects = (pathItem: any, _opts: any, ctx: any) => {
if (pathItem === null || typeof pathItem !== "object") {
return []
}

const neededHttpVerbs = ["put", "patch"]
const putCodes = ["200", "201"]
const patchCodes = ["200"]
const path = ctx.path || []
const errors = []

for (const verb of neededHttpVerbs) {
if (pathItem[verb]) {
let codes = []
if (verb === "patch") {
codes = patchCodes
} else {
codes = putCodes
}

for (const code of codes) {
if (!getProperty(pathItem[verb].responses[code]?.schema, "provisioningState")) {
errors.push({
message: `${code} response in long running ${verb} operation is missing ProvisioningState property. A LRO PUT and PATCH operations response schema must have ProvisioningState specified.`,
path,
})
}
}
}
}

return errors
}

export default avoidFreeFormObjects
Loading