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

Test false "false positive" for ProvisioningStateMustBeReadOnly #561

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
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@microsoft.azure/openapi-validator-rulesets",
"comment": "Add test for ProvisioingStateMustBeReadOnly ",
"type": "patch"
}
],
"packageName": "@microsoft.azure/openapi-validator-rulesets"
}
2 changes: 1 addition & 1 deletion packages/rulesets/src/spectral/az-arm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ const ruleset: any = {
ProvisioningStateMustBeReadOnly: {
description: "This is a rule introduced to validate if provisioningState property is set to readOnly or not.",
message: "{{error}}",
severity: "off", // See https://github.com/Azure/azure-sdk-tools/issues/6191#issuecomment-1571334585
severity: "warn",
stagingOnly: true,
resolved: true,
formats: [oas2],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,106 @@ test("ProvisioningStateMustBeReadOnly should find errors when multiple verbs spe
})
})

test("ProvisioningStateSpecified should find errors when readOnly property is present in the envelope property", () => {
const oasDoc = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

really nice to see this test being added!

swagger: "2.0",
paths: {
"/foo": {
put: {
tags: ["SampleTag"],
operationId: "Foo_Update",
description: "Test Description",
parameters: [
{
name: "foo_put",
in: "body",
schema: {
$ref: "#/definitions/FooRequestParams",
},
},
],
responses: {
"200": {
description: "Success",
schema: {
$ref: "#/definitions/FooProps",
},
},
"201": {
schema: {
$ref: "#/definitions/FooRule",
},
},
},
"x-ms-long-running-operation": true,
"x-ms-long-running-operation-options": {
"final-state-via": "azure-async-operation",
},
},
},
},
definitions: {
FooRequestParams: {
allOf: [
{
$ref: "#/definitions/FooProps",
},
],
},
ProvisioningState: {
type: "string",
enum: ["Succeeded", "Failed", "Canceled"],
"x-ms-enum": {
name: "ProvisioningState",
modelAsString: true,
},
},
FooResource: {
"x-ms-azure-resource": true,
properties: {
provisioningState: {
$ref: "#/definitions/ProvisioningState",
readOnly: true,
type: "string",
description: "Provisioning state of the foo rule.",
enum: ["Creating", "Canceled", "Deleting", "Failed"],
},
},
},
FooRule: {
type: "object",
properties: {
properties: {
$ref: "#/definitions/FooResource",
"x-ms-client-flatten": true,
},
},
required: ["properties"],
},
FooProps: {
properties: {
servicePrecedence: {
description:
"A precedence value that is used to decide between services when identifying the QoS values to use for a particular SIM. A lower value means a higher priority. This value should be unique among all services configured in the mobile network.",
type: "integer",
format: "int32",
minimum: 0,
maximum: 255,
},
id: {
type: "string",
},
},
},
},
}
return linter.run(oasDoc).then((results) => {
expect(results.length).toBe(1)
expect(results[0].path.join(".")).toBe("paths./foo.put.responses.201.schema")
expect(results[0].message).toContain("provisioningState property must be set to readOnly.")
})
})

test("ProvisioningStateSpecified should find no errors", () => {
const oasDoc = {
swagger: "2.0",
Expand Down Expand Up @@ -258,10 +358,20 @@ test("ProvisioningStateSpecified should find no errors", () => {
},
],
},
ProvisioningState: {
type: "string",
enum: ["Succeeded", "Failed", "Canceled"],
"x-ms-enum": {
name: "ProvisioningState",
modelAsString: true,
},
readOnly: true,
},
FooResource: {
"x-ms-azure-resource": true,
properties: {
provisioningState: {
$ref: "#/definitions/ProvisioningState",
readOnly: true,
type: "string",
description: "Provisioning state of the foo rule.",
Expand Down