Skip to content

Commit f1d1d05

Browse files
authored
Sorting: ignore casing when sorting component properties (#168)
* Sorting: ignore casing when sorting component properties * github: Update checkout actions
1 parent 4d3e731 commit f1d1d05

6 files changed

Lines changed: 333 additions & 4 deletions

File tree

.github/workflows/npm-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212

1313
strategy:
1414
matrix:
15-
node-version: [ '18', '20' ]
15+
node-version: [ '20', '22' ]
1616

1717
steps:
1818
- uses: actions/checkout@v4

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.1] - 2025-07-04
4+
5+
- Sorting: ignore casing when sorting component properties (#165)
6+
37
## [1.27.0] - 2025-06-18
48

59
- Sorting: Added sortComponentsProps feature (#165)

test/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const tests = !localTesting
1616
? fs.readdirSync(__dirname).filter(file => {
1717
return fs.statSync(path.join(__dirname, file)).isDirectory() && !file.startsWith('_');
1818
})
19-
: ['yaml-sort-required'];
19+
: ['yaml-sort-component-props'];
2020

2121
describe('openapi-format tests', () => {
2222
let consoleLogSpy, consoleWarnSpy;

test/yaml-sort-component-props/input.yaml

Lines changed: 175 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,178 @@ components:
1313
lastName:
1414
type: string
1515
firstName:
16-
type: string
16+
type: string
17+
Schema:
18+
description: |-
19+
The `Schema` object allows the definition of input and output data types.
20+
These types can be objects, but also primitives and arrays.
21+
Represents a select subset of an [OpenAPI 3.0 schema
22+
object](https://spec.openapis.org/oas/v3.0.3#schema).
23+
type: object
24+
properties:
25+
anyOf:
26+
description: >-
27+
Optional. The value should be validated against any (one or more) of the
28+
subschemas
29+
30+
in the list.
31+
type: array
32+
items:
33+
$ref: '#/components/schemas/Schema'
34+
default:
35+
description: >-
36+
Optional. Default value of the field. Per JSON Schema, this field is
37+
intended for
38+
39+
documentation generators and doesn't affect validation. Thus it's
40+
included
41+
42+
here and ignored so that developers who send schemas with a `default`
43+
field
44+
45+
don't get unknown-field errors.
46+
description:
47+
description: >-
48+
Optional. A brief description of the parameter. This could contain
49+
examples of use.
50+
51+
Parameter description may be formatted as Markdown.
52+
type: string
53+
enum:
54+
description: >-
55+
Optional. Possible values of the element of Type.STRING with enum
56+
format.
57+
58+
For example we can define an Enum Direction as :
59+
60+
{type:STRING, format:enum, enum:["EAST", NORTH", "SOUTH", "WEST"]}
61+
type: array
62+
items:
63+
type: string
64+
example:
65+
description: >-
66+
Optional. Example of the object. Will only populated when the object is
67+
the root.
68+
format:
69+
description: >-
70+
Optional. The format of the data. This is used only for primitive
71+
datatypes.
72+
73+
Supported formats:
74+
for NUMBER type: float, double
75+
for INTEGER type: int32, int64
76+
for STRING type: enum, date-time
77+
type: string
78+
items:
79+
description: Optional. Schema of the elements of Type.ARRAY.
80+
allOf:
81+
- $ref: '#/components/schemas/Schema'
82+
maxItems:
83+
description: Optional. Maximum number of the elements for Type.ARRAY.
84+
type: string
85+
format: int64
86+
maximum:
87+
description: Optional. Maximum value of the Type.INTEGER and Type.NUMBER
88+
type: number
89+
format: double
90+
maxLength:
91+
description: Optional. Maximum length of the Type.STRING
92+
type: string
93+
format: int64
94+
maxProperties:
95+
description: Optional. Maximum number of the properties for Type.OBJECT.
96+
type: string
97+
format: int64
98+
minimum:
99+
description: |-
100+
Optional. SCHEMA FIELDS FOR TYPE INTEGER and NUMBER
101+
Minimum value of the Type.INTEGER and Type.NUMBER
102+
type: number
103+
format: double
104+
minItems:
105+
description: Optional. Minimum number of the elements for Type.ARRAY.
106+
type: string
107+
format: int64
108+
minLength:
109+
description: |-
110+
Optional. SCHEMA FIELDS FOR TYPE STRING
111+
Minimum length of the Type.STRING
112+
type: string
113+
format: int64
114+
minProperties:
115+
description: Optional. Minimum number of the properties for Type.OBJECT.
116+
type: string
117+
format: int64
118+
nullable:
119+
description: Optional. Indicates if the value may be null.
120+
type: boolean
121+
pattern:
122+
description: >-
123+
Optional. Pattern of the Type.STRING to restrict a string to a regular
124+
expression.
125+
type: string
126+
properties:
127+
description: Optional. Properties of Type.OBJECT.
128+
type: object
129+
additionalProperties:
130+
$ref: '#/components/schemas/Schema'
131+
propertyOrdering:
132+
description: >-
133+
Optional. The order of the properties.
134+
135+
Not a standard field in open api spec. Used to determine the order of
136+
the
137+
138+
properties in the response.
139+
type: array
140+
items:
141+
type: string
142+
required:
143+
description: Optional. Required properties of Type.OBJECT.
144+
type: array
145+
items:
146+
type: string
147+
title:
148+
description: Optional. The title of the schema.
149+
type: string
150+
type:
151+
description: Required. Data type.
152+
allOf:
153+
- $ref: '#/components/schemas/Type'
154+
required:
155+
- type
156+
CountTokensResponse:
157+
description: |-
158+
A response from `CountTokens`.
159+
160+
It returns the model's `token_count` for the `prompt`.
161+
type: object
162+
properties:
163+
cacheTokensDetails:
164+
description: >-
165+
Output only. List of modalities that were processed in the cached
166+
content.
167+
type: array
168+
items:
169+
$ref: '#/components/schemas/ModalityTokenCount'
170+
readOnly: true
171+
cachedContentTokenCount:
172+
description: Number of tokens in the cached part of the prompt (the cached content).
173+
type: integer
174+
format: int32
175+
promptTokensDetails:
176+
description: >-
177+
Output only. List of modalities that were processed in the request
178+
input.
179+
type: array
180+
items:
181+
$ref: '#/components/schemas/ModalityTokenCount'
182+
readOnly: true
183+
totalTokens:
184+
description: >-
185+
The number of tokens that the `Model` tokenizes the `prompt` into.
186+
Always
187+
188+
non-negative.
189+
type: integer
190+
format: int32

test/yaml-sort-component-props/output.yaml

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,149 @@ components:
1414
type: string
1515
lastName:
1616
type: string
17+
Schema:
18+
description: |-
19+
The `Schema` object allows the definition of input and output data types.
20+
These types can be objects, but also primitives and arrays.
21+
Represents a select subset of an [OpenAPI 3.0 schema
22+
object](https://spec.openapis.org/oas/v3.0.3#schema).
23+
type: object
24+
properties:
25+
anyOf:
26+
description: |-
27+
Optional. The value should be validated against any (one or more) of the subschemas
28+
in the list.
29+
type: array
30+
items:
31+
$ref: '#/components/schemas/Schema'
32+
default:
33+
description: |-
34+
Optional. Default value of the field. Per JSON Schema, this field is intended for
35+
documentation generators and doesn't affect validation. Thus it's included
36+
here and ignored so that developers who send schemas with a `default` field
37+
don't get unknown-field errors.
38+
description:
39+
description: |-
40+
Optional. A brief description of the parameter. This could contain examples of use.
41+
Parameter description may be formatted as Markdown.
42+
type: string
43+
enum:
44+
description: |-
45+
Optional. Possible values of the element of Type.STRING with enum format.
46+
For example we can define an Enum Direction as :
47+
{type:STRING, format:enum, enum:["EAST", NORTH", "SOUTH", "WEST"]}
48+
type: array
49+
items:
50+
type: string
51+
example:
52+
description: Optional. Example of the object. Will only populated when the object is the root.
53+
format:
54+
description: |-
55+
Optional. The format of the data. This is used only for primitive datatypes.
56+
Supported formats:
57+
for NUMBER type: float, double
58+
for INTEGER type: int32, int64
59+
for STRING type: enum, date-time
60+
type: string
61+
items:
62+
description: Optional. Schema of the elements of Type.ARRAY.
63+
allOf:
64+
- $ref: '#/components/schemas/Schema'
65+
maximum:
66+
description: Optional. Maximum value of the Type.INTEGER and Type.NUMBER
67+
type: number
68+
format: double
69+
maxItems:
70+
description: Optional. Maximum number of the elements for Type.ARRAY.
71+
type: string
72+
format: int64
73+
maxLength:
74+
description: Optional. Maximum length of the Type.STRING
75+
type: string
76+
format: int64
77+
maxProperties:
78+
description: Optional. Maximum number of the properties for Type.OBJECT.
79+
type: string
80+
format: int64
81+
minimum:
82+
description: |-
83+
Optional. SCHEMA FIELDS FOR TYPE INTEGER and NUMBER
84+
Minimum value of the Type.INTEGER and Type.NUMBER
85+
type: number
86+
format: double
87+
minItems:
88+
description: Optional. Minimum number of the elements for Type.ARRAY.
89+
type: string
90+
format: int64
91+
minLength:
92+
description: |-
93+
Optional. SCHEMA FIELDS FOR TYPE STRING
94+
Minimum length of the Type.STRING
95+
type: string
96+
format: int64
97+
minProperties:
98+
description: Optional. Minimum number of the properties for Type.OBJECT.
99+
type: string
100+
format: int64
101+
nullable:
102+
description: Optional. Indicates if the value may be null.
103+
type: boolean
104+
pattern:
105+
description: Optional. Pattern of the Type.STRING to restrict a string to a regular expression.
106+
type: string
107+
properties:
108+
description: Optional. Properties of Type.OBJECT.
109+
type: object
110+
additionalProperties:
111+
$ref: '#/components/schemas/Schema'
112+
propertyOrdering:
113+
description: |-
114+
Optional. The order of the properties.
115+
Not a standard field in open api spec. Used to determine the order of the
116+
properties in the response.
117+
type: array
118+
items:
119+
type: string
120+
required:
121+
description: Optional. Required properties of Type.OBJECT.
122+
type: array
123+
items:
124+
type: string
125+
title:
126+
description: Optional. The title of the schema.
127+
type: string
128+
type:
129+
description: Required. Data type.
130+
allOf:
131+
- $ref: '#/components/schemas/Type'
132+
required:
133+
- type
134+
CountTokensResponse:
135+
description: |-
136+
A response from `CountTokens`.
137+
138+
It returns the model's `token_count` for the `prompt`.
139+
type: object
140+
properties:
141+
cachedContentTokenCount:
142+
description: Number of tokens in the cached part of the prompt (the cached content).
143+
type: integer
144+
format: int32
145+
cacheTokensDetails:
146+
description: Output only. List of modalities that were processed in the cached content.
147+
type: array
148+
items:
149+
$ref: '#/components/schemas/ModalityTokenCount'
150+
readOnly: true
151+
promptTokensDetails:
152+
description: Output only. List of modalities that were processed in the request input.
153+
type: array
154+
items:
155+
$ref: '#/components/schemas/ModalityTokenCount'
156+
readOnly: true
157+
totalTokens:
158+
description: |-
159+
The number of tokens that the `Model` tokenizes the `prompt` into. Always
160+
non-negative.
161+
type: integer
162+
format: int32

utils/sorting.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@ function propComparator(priorityArr) {
4040
if (ia !== -1) {
4141
return ib !== -1 ? ia - ib : -1;
4242
}
43-
return ib !== -1 || a > b ? 1 : a < b ? -1 : 0;
43+
if (ib !== -1) {
44+
return 1;
45+
}
46+
const aLower = a.toLowerCase();
47+
const bLower = b.toLowerCase();
48+
return aLower > bLower ? 1 : aLower < bLower ? -1 : 0;
4449
};
4550
}
4651

0 commit comments

Comments
 (0)