Skip to content
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
8 changes: 4 additions & 4 deletions rulesets/src/naming.ruleset.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ rules:

##### Domain References #####
sps-ref-property-name:
description: Property with the name 'ref' MUST be of type 'sps-ref' following URN-like reference formats.
description: Property with the name 'ref' MUST use a format 'sps-ref'.
severity: error
formats: [oas3]
given: '$..properties..[?((@property=== "ref" || @property === "Ref") && @.$ref == null && @.allOf == null && @.oneOf == null && @.type != null)]'
resolved: false
then:
- field: "format"
- field: format
function: truthy
- field: "format"
- field: format
function: pattern
functionOptions:
match: "sps-ref"
match: "^sps-ref$"

sps-ref-schema:
description: Properties following 'sps-ref' format MUST use the standardized schema - maxLength (255), minLength(7), pattern (includes 'sps'), type (string).
Expand Down
54 changes: 54 additions & 0 deletions rulesets/test/naming/sps-ref-property-name.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,58 @@ describe("sps-ref-property-name", () => {
`;
await spectral.validateSuccess(spec, ruleName);
});

test("Ref property fails with format containing 'sps-ref' but not exact match", async () => {
const spec = `
openapi: 3.0.1
paths: {}
components:
schemas:
MySchema:
type: object
properties:
ref:
type: string
format: custom-sps-ref
value:
type: string
`;
await spectral.validateFailure(spec, ruleName, "Error");
});

test("Ref property fails with format 'sps-ref-extended'", async () => {
const spec = `
openapi: 3.0.1
paths: {}
components:
schemas:
MySchema:
type: object
properties:
ref:
type: string
format: sps-ref-extended
value:
type: string
`;
await spectral.validateFailure(spec, ruleName, "Error");
});

test("Ref property fails with format 'my-sps-ref'", async () => {
const spec = `
openapi: 3.0.1
paths: {}
components:
schemas:
MySchema:
type: object
properties:
ref:
type: string
format: my-sps-ref
value:
type: string
`;
await spectral.validateFailure(spec, ruleName, "Error");
});
});
Loading