Skip to content

Commit a0ce1fa

Browse files
authored
Sorting: fix encodeLargeNumbers to respect comma values (#171)
1 parent 3c8da1f commit a0ce1fa

6 files changed

Lines changed: 92 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## unreleased
22

3+
## [1.27.2] - 2025-07-04
4+
5+
- Sorting: fix encodeLargeNumbers to respect comma values (#170)
6+
37
## [1.27.1] - 2025-07-04
48

59
- Sorting: ignore casing when sorting component properties (#165)

test/util-file.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,12 @@ describe('openapi-format CLI file tests', () => {
395395
const output = encodeLargeNumbers(input);
396396
expect(output).toBe(' "large: "123456789.123456789===",\n key": "123",\n "other": "456"');
397397
});
398+
399+
test('should not modify numbers that are part of a comma separated string', () => {
400+
const input = 'location: 10.12345678912345, 10.12345678912345';
401+
const output = encodeLargeNumbers(input);
402+
expect(output).toBe(input);
403+
});
398404
});
399405

400406
describe('addQuotesToRefInString function', () => {

test/yaml-big-numbers/input.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
openapi: 3.0.0
2+
info:
3+
title: TEST API
4+
version: 1.0.0
5+
paths:
6+
/test:
7+
post:
8+
requestBody:
9+
content:
10+
application/json:
11+
schema:
12+
type: object
13+
properties:
14+
location: string
15+
test_property: string
16+
examples:
17+
Example1:
18+
$ref: '#/components/examples/Test1'
19+
Example2:
20+
$ref: '#/components/examples/Test2'
21+
responses:
22+
'201':
23+
description: Succcess
24+
content:
25+
application/json:
26+
schema:
27+
type: object
28+
properties:
29+
type: string
30+
components:
31+
examples:
32+
Test1:
33+
value:
34+
location: 10.12345678912345, 10.12345678912345
35+
test_property: test
36+
Test2:
37+
value:
38+
location: 10.12345678912345, 10.12345678912345
39+
test_property: test

test/yaml-big-numbers/options.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
verbose: true
2+
output: output.yaml
3+
no-sort: false

test/yaml-big-numbers/output.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
openapi: 3.0.0
2+
info:
3+
title: TEST API
4+
version: 1.0.0
5+
paths:
6+
/test:
7+
post:
8+
requestBody:
9+
content:
10+
application/json:
11+
schema:
12+
type: object
13+
properties:
14+
location: string
15+
test_property: string
16+
examples:
17+
Example1:
18+
$ref: '#/components/examples/Test1'
19+
Example2:
20+
$ref: '#/components/examples/Test2'
21+
responses:
22+
'201':
23+
description: Succcess
24+
content:
25+
application/json:
26+
schema:
27+
type: object
28+
properties:
29+
type: string
30+
components:
31+
examples:
32+
Test1:
33+
value:
34+
location: '10.12345678912345, 10.12345678912345'
35+
test_property: test
36+
Test2:
37+
value:
38+
location: '10.12345678912345, 10.12345678912345'
39+
test_property: test

utils/file.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ async function getRemoteFile(filePath) {
279279
*/
280280
function encodeLargeNumbers(inputContent) {
281281
// Convert large number value safely before parsing
282-
const regexEncodeLargeNumber = /: ([0-9]+(\.[0-9]+)?)\b(?!\.[0-9])(,|\n)/g; // match > : 123456789.123456789
282+
const regexEncodeLargeNumber = /: ([0-9]+(\.[0-9]+)?)(?!\.[0-9])(,(?!\s*[0-9])|\n)/g; // match > : 123456789.123456789
283283
return inputContent.replace(regexEncodeLargeNumber, rawInput => {
284284
const endChar = rawInput.endsWith(',') ? ',' : '\n';
285285
const rgx = new RegExp(endChar, 'g');

0 commit comments

Comments
 (0)