From a1e57d5ecc8b41d686fd5f68b644b714fca4d4f7 Mon Sep 17 00:00:00 2001 From: Ethan Honzik <105084033+EthanHonzikSPS@users.noreply.github.com> Date: Tue, 20 Aug 2024 12:03:35 -0500 Subject: [PATCH] fix: camel case function (#90) updated camel case function to allow for two consecutive uppercase letters No changes were observed in impact or performance tests. --- rulesets/src/naming.ruleset.yml | 4 +- .../naming/sps-camel-case-properties.test.js | 59 +++++++++++++++++++ 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/rulesets/src/naming.ruleset.yml b/rulesets/src/naming.ruleset.yml index fa40a73..cf91ade 100644 --- a/rulesets/src/naming.ruleset.yml +++ b/rulesets/src/naming.ruleset.yml @@ -16,9 +16,9 @@ rules: formats: [oas3] given: "$..properties.*~" then: - function: casing + function: pattern functionOptions: - type: camel + match: ^[a-z][a-z0-9]*(([A-Z]{2}|[A-Z])[a-z0-9]+)*$ sps-disallowed-prepositions: description: Property names SHOULD NOT include prepositions (e.g. "for", "during", "at", etc.) diff --git a/rulesets/test/naming/sps-camel-case-properties.test.js b/rulesets/test/naming/sps-camel-case-properties.test.js index 3398c04..7342688 100644 --- a/rulesets/test/naming/sps-camel-case-properties.test.js +++ b/rulesets/test/naming/sps-camel-case-properties.test.js @@ -9,6 +9,65 @@ describe("sps-camel-case-properties", () => { spectral = new SpectralTestHarness(ruleset); }); + + test("valid property names with two capital letters in a row", async () => { + const spec = ` + openapi: 3.0.1 + paths: + /users: + post: + requestBody: + content: + application/json: + schema: + type: object + properties: + censusScheduleKLocation: + type: string + responses: + '200': + description: Successful operation + content: + application/json: + schema: + type: object + properties: + userIDcode: + type: string + `; + + await spectral.validateSuccess(spec, ruleName); + }); + + test("invalid property names with more than two capital letters in a row", async () => { + const spec = ` + openapi: 3.0.1 + paths: + /users: + post: + requestBody: + content: + application/json: + schema: + type: object + properties: + invalidTESt: + type: string + responses: + '200': + description: Successful operation + content: + application/json: + schema: + type: object + properties: + invalidTESTtest: + type: string + `; + + await spectral.validateFailure(spec, ruleName, "Error", 2); + }); + test("valid property names", async () => { const spec = ` openapi: 3.0.1