diff --git a/rulesets/src/naming.ruleset.yml b/rulesets/src/naming.ruleset.yml index cf91ade..9186a40 100644 --- a/rulesets/src/naming.ruleset.yml +++ b/rulesets/src/naming.ruleset.yml @@ -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). diff --git a/rulesets/test/naming/sps-ref-property-name.test.js b/rulesets/test/naming/sps-ref-property-name.test.js index d90c23e..c61cca3 100644 --- a/rulesets/test/naming/sps-ref-property-name.test.js +++ b/rulesets/test/naming/sps-ref-property-name.test.js @@ -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"); + }); });