Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 6 additions & 0 deletions packages/rulesets/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log - @microsoft.azure/openapi-validator-rulesets

## 2.2.3

### Patches

- [MutabilityWithReadOnly] Add null check to given clause filter to prevent null property objects from being processed

## 2.2.2

### Patches
Expand Down
2 changes: 1 addition & 1 deletion packages/rulesets/generated/spectral/az-arm.js
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,7 @@ const ruleset$1 = {
severity: "error",
resolved: true,
formats: [oas2],
given: ["$[paths,'x-ms-paths']..*[?(@.readOnly !== undefined && @['x-ms-mutability'] !== undefined)]"],
given: ["$[paths,'x-ms-paths']..*[?(@ != null && @.readOnly !== undefined && @['x-ms-mutability'] !== undefined)]"],
then: {
function: mutabilityWithReadOnly,
},
Expand Down
2 changes: 1 addition & 1 deletion packages/rulesets/generated/spectral/az-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ const ruleset = {
severity: "error",
resolved: true,
formats: [oas2],
given: ["$[paths,'x-ms-paths']..*[?(@.readOnly !== undefined && @['x-ms-mutability'] !== undefined)]"],
given: ["$[paths,'x-ms-paths']..*[?(@ != null && @.readOnly !== undefined && @['x-ms-mutability'] !== undefined)]"],
then: {
function: mutabilityWithReadOnly,
},
Expand Down
2 changes: 1 addition & 1 deletion packages/rulesets/generated/spectral/az-dataplane.js
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ const ruleset$1 = {
severity: "error",
resolved: true,
formats: [oas2],
given: ["$[paths,'x-ms-paths']..*[?(@.readOnly !== undefined && @['x-ms-mutability'] !== undefined)]"],
given: ["$[paths,'x-ms-paths']..*[?(@ != null && @.readOnly !== undefined && @['x-ms-mutability'] !== undefined)]"],
then: {
function: mutabilityWithReadOnly,
},
Expand Down
2 changes: 1 addition & 1 deletion packages/rulesets/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@microsoft.azure/openapi-validator-rulesets",
"version": "2.2.2",
"version": "2.2.3",
Comment thread
mikeharder marked this conversation as resolved.
Outdated
"description": "Azure OpenAPI Validator",
"main": "dist/index.js",
"files": [
Expand Down
2 changes: 1 addition & 1 deletion packages/rulesets/src/spectral/az-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ const ruleset: any = {
severity: "error",
resolved: true,
formats: [oas2],
given: ["$[paths,'x-ms-paths']..*[?(@.readOnly !== undefined && @['x-ms-mutability'] !== undefined)]"],
given: ["$[paths,'x-ms-paths']..*[?(@ != null && @.readOnly !== undefined && @['x-ms-mutability'] !== undefined)]"],
Comment thread
mikeharder marked this conversation as resolved.
then: {
function: mutabilityWithReadOnly,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,19 @@ test("MutabilityWithReadOnly: properties ignored by given clause", () => {
expect(results.length).toBe(0);
});
});

test("MutabilityWithReadOnly: null property values are filtered by given clause", () => {
const myOpenApiDocument = createOpenApiDoc({
nullProperty: null,
validProperty: {
type: "string",
readOnly: true,
"x-ms-mutability": ["read"],
},
});
return linter.run(myOpenApiDocument).then((results) => {
// Null property should be filtered out by the given clause (@ != null check)
// Only the valid property should pass through, and it's valid so 0 errors
expect(results.length).toBe(0);
});
});
Loading