Skip to content

Commit

Permalink
fix: camelCase assertion for single letter (#1735)
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitryAnansky authored Sep 13, 2024
1 parent 46dac00 commit cc3b4b4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/fresh-cheetahs-love.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@redocly/openapi-core": patch
"@redocly/cli": patch
---

Fixed `camelCase` assertion for single-letter values.
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,14 @@ describe('oas3 assertions', () => {
expect(asserts.casing(['testExample', 'fooBar'], 'camelCase', assertionProperties)).toEqual(
[]
);
expect(asserts.casing(['f'], 'camelCase', assertionProperties)).toEqual([]);
expect(asserts.casing(['Q'], 'camelCase', assertionProperties)).toEqual([
{
message: '"Q" should use camelCase',
location: baseLocation.child('Q').key(),
},
]);
expect(asserts.casing(['fQ'], 'camelCase', assertionProperties)).toEqual([]);
expect(asserts.casing(['testExample', 'FooBar'], 'camelCase', assertionProperties)).toEqual(
[
{
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/rules/common/assertions/asserts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ export const asserts: Asserts = {
if (typeof value === 'undefined' || isPlainObject(value)) return []; // property doesn't exist or is an object, no need to lint it with this assert
const values = Array.isArray(value) ? value : [value];
const casingRegexes: Record<string, RegExp> = {
camelCase: /^[a-z][a-zA-Z0-9]+$/g,
camelCase: /^[a-z][a-zA-Z0-9]*$/g,
'kebab-case': /^([a-z][a-z0-9]*)(-[a-z0-9]+)*$/g,
snake_case: /^([a-z][a-z0-9]*)(_[a-z0-9]+)*$/g,
PascalCase: /^[A-Z][a-zA-Z0-9]+$/g,
Expand Down

1 comment on commit cc3b4b4

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements 78.52% 4953/6308
🟡 Branches 67.24% 2046/3043
🟡 Functions 72.84% 818/1123
🟡 Lines 78.81% 4672/5928

Test suite run success

802 tests passing in 121 suites.

Report generated by 🧪jest coverage report action from cc3b4b4

Please sign in to comment.