Skip to content

Commit

Permalink
fix: camel case function (#90)
Browse files Browse the repository at this point in the history
updated camel case function to allow for two consecutive uppercase
letters
No changes were observed in impact or performance tests.
  • Loading branch information
EthanHonzikSPS authored Aug 20, 2024
1 parent 245b633 commit a1e57d5
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
4 changes: 2 additions & 2 deletions rulesets/src/naming.ruleset.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.)
Expand Down
59 changes: 59 additions & 0 deletions rulesets/test/naming/sps-camel-case-properties.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a1e57d5

Please sign in to comment.