Skip to content

Commit 13007e3

Browse files
Copilotabraham
andcommitted
Improve generic response names with named components
Co-authored-by: abraham <[email protected]>
1 parent 29d9d7d commit 13007e3

File tree

3 files changed

+211
-49
lines changed

3 files changed

+211
-49
lines changed

dist/schema.json

Lines changed: 64 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5230,15 +5230,7 @@
52305230
"content": {
52315231
"application/json": {
52325232
"schema": {
5233-
"type": "object",
5234-
"properties": {
5235-
"async_refresh": {
5236-
"$ref": "#/components/schemas/AsyncRefresh"
5237-
}
5238-
},
5239-
"required": [
5240-
"async_refresh"
5241-
]
5233+
"$ref": "#/components/schemas/AsyncRefreshResponse"
52425234
}
52435235
}
52445236
}
@@ -16708,18 +16700,12 @@
1670816700
"content": {
1670916701
"application/json": {
1671016702
"schema": {
16711-
"type": "object",
16712-
"properties": {
16713-
"merged": {
16714-
"type": "boolean"
16715-
}
16716-
},
16717-
"required": [
16718-
"merged"
16719-
]
16703+
"$ref": "#/components/schemas/MergedResponse"
1672016704
},
16721-
"example": {
16722-
"merged": false
16705+
"examples": {
16706+
"MergedResponse200Example": {
16707+
"$ref": "#/components/examples/MergedResponse200Example"
16708+
}
1672316709
}
1672416710
}
1672516711
}
@@ -16841,18 +16827,12 @@
1684116827
"content": {
1684216828
"application/json": {
1684316829
"schema": {
16844-
"type": "object",
16845-
"properties": {
16846-
"count": {
16847-
"type": "integer"
16848-
}
16849-
},
16850-
"required": [
16851-
"count"
16852-
]
16830+
"$ref": "#/components/schemas/CountResponse"
1685316831
},
16854-
"example": {
16855-
"count": 42
16832+
"examples": {
16833+
"CountResponse200Example": {
16834+
"$ref": "#/components/examples/CountResponse200Example"
16835+
}
1685616836
}
1685716837
}
1685816838
}
@@ -17784,18 +17764,12 @@
1778417764
"content": {
1778517765
"application/json": {
1778617766
"schema": {
17787-
"type": "object",
17788-
"properties": {
17789-
"count": {
17790-
"type": "integer"
17791-
}
17792-
},
17793-
"required": [
17794-
"count"
17795-
]
17767+
"$ref": "#/components/schemas/CountResponse"
1779617768
},
17797-
"example": {
17798-
"count": 42
17769+
"examples": {
17770+
"CountResponse200Example": {
17771+
"$ref": "#/components/examples/CountResponse200Example"
17772+
}
1779917773
}
1780017774
}
1780117775
}
@@ -36899,6 +36873,42 @@
3689936873
"details"
3690036874
]
3690136875
},
36876+
"AsyncRefreshResponse": {
36877+
"type": "object",
36878+
"description": "Response wrapper containing a AsyncRefresh entity",
36879+
"properties": {
36880+
"async_refresh": {
36881+
"$ref": "#/components/schemas/AsyncRefresh"
36882+
}
36883+
},
36884+
"required": [
36885+
"async_refresh"
36886+
]
36887+
},
36888+
"CountResponse": {
36889+
"type": "object",
36890+
"description": "Response wrapper containing a count value",
36891+
"properties": {
36892+
"count": {
36893+
"type": "integer"
36894+
}
36895+
},
36896+
"required": [
36897+
"count"
36898+
]
36899+
},
36900+
"MergedResponse": {
36901+
"type": "object",
36902+
"description": "Response wrapper containing a merged value",
36903+
"properties": {
36904+
"merged": {
36905+
"type": "boolean"
36906+
}
36907+
},
36908+
"required": [
36909+
"merged"
36910+
]
36911+
},
3690236912
"BaseStatus": {
3690336913
"type": "object",
3690436914
"description": "Common fields for all status creation requests",
@@ -38617,6 +38627,18 @@
3861738627
}
3861838628
]
3861938629
},
38630+
"MergedResponse200Example": {
38631+
"summary": "Example for MergedResponse",
38632+
"value": {
38633+
"merged": false
38634+
}
38635+
},
38636+
"CountResponse200Example": {
38637+
"summary": "Example for CountResponse",
38638+
"value": {
38639+
"count": 42
38640+
}
38641+
},
3862038642
"GroupedNotificationsResults200Example": {
3862138643
"summary": "Example for GroupedNotificationsResults",
3862238644
"value": {

src/__tests__/generators/TypeParser.hashWrapper.test.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,15 @@ describe('TypeParser - Hash wrapper pattern handling', () => {
3636
spec
3737
);
3838

39+
// Should create a named response component
3940
expect(result).toEqual({
41+
$ref: '#/components/schemas/CountResponse',
42+
});
43+
44+
// Should add the component to the spec
45+
expect(spec.components?.schemas?.['CountResponse']).toEqual({
4046
type: 'object',
47+
description: 'Response wrapper containing a count value',
4148
properties: {
4249
count: {
4350
type: 'integer',
@@ -53,8 +60,15 @@ describe('TypeParser - Hash wrapper pattern handling', () => {
5360
spec
5461
);
5562

63+
// Should create a named response component
5664
expect(result).toEqual({
65+
$ref: '#/components/schemas/MergedResponse',
66+
});
67+
68+
// Should add the component to the spec
69+
expect(spec.components?.schemas?.['MergedResponse']).toEqual({
5770
type: 'object',
71+
description: 'Response wrapper containing a merged value',
5872
properties: {
5973
merged: {
6074
type: 'integer',
@@ -72,8 +86,15 @@ describe('TypeParser - Hash wrapper pattern handling', () => {
7286
spec
7387
);
7488

89+
// Should create a named response component based on entity name
7590
expect(result).toEqual({
91+
$ref: '#/components/schemas/AsyncRefreshResponse',
92+
});
93+
94+
// Should add the response wrapper component to the spec
95+
expect(spec.components?.schemas?.['AsyncRefreshResponse']).toEqual({
7696
type: 'object',
97+
description: 'Response wrapper containing a AsyncRefresh entity',
7798
properties: {
7899
async_refresh: {
79100
$ref: '#/components/schemas/AsyncRefresh',
@@ -98,8 +119,15 @@ describe('TypeParser - Hash wrapper pattern handling', () => {
98119
spec
99120
);
100121

122+
// Should create a named response component based on entity name
101123
expect(result).toEqual({
124+
$ref: '#/components/schemas/StatusResponse',
125+
});
126+
127+
// Should add the response wrapper component to the spec
128+
expect(spec.components?.schemas?.['StatusResponse']).toEqual({
102129
type: 'object',
130+
description: 'Response wrapper containing a Status entity',
103131
properties: {
104132
status: {
105133
$ref: '#/components/schemas/Status',
@@ -127,8 +155,15 @@ describe('TypeParser - Hash wrapper pattern handling', () => {
127155
spec
128156
);
129157

158+
// Should create a named response component
130159
expect(result).toEqual({
160+
$ref: '#/components/schemas/MergedResponse',
161+
});
162+
163+
// Should add the component to the spec
164+
expect(spec.components?.schemas?.['MergedResponse']).toEqual({
131165
type: 'object',
166+
description: 'Response wrapper containing a merged value',
132167
properties: {
133168
merged: {
134169
type: 'boolean',
@@ -144,8 +179,15 @@ describe('TypeParser - Hash wrapper pattern handling', () => {
144179
spec
145180
);
146181

182+
// Should create a named response component
147183
expect(result).toEqual({
184+
$ref: '#/components/schemas/TotalResponse',
185+
});
186+
187+
// Should add the component to the spec
188+
expect(spec.components?.schemas?.['TotalResponse']).toEqual({
148189
type: 'object',
190+
description: 'Response wrapper containing a total value',
149191
properties: {
150192
total: {
151193
type: 'integer',
@@ -161,8 +203,15 @@ describe('TypeParser - Hash wrapper pattern handling', () => {
161203
spec
162204
);
163205

206+
// Should create a named response component
164207
expect(result).toEqual({
208+
$ref: '#/components/schemas/NameResponse',
209+
});
210+
211+
// Should add the component to the spec
212+
expect(spec.components?.schemas?.['NameResponse']).toEqual({
165213
type: 'object',
214+
description: 'Response wrapper containing a name value',
166215
properties: {
167216
name: {
168217
type: 'string',
@@ -180,8 +229,15 @@ describe('TypeParser - Hash wrapper pattern handling', () => {
180229
spec
181230
);
182231

232+
// Should create a named response component
183233
expect(result).toEqual({
234+
$ref: '#/components/schemas/CountResponse',
235+
});
236+
237+
// Should add the component to the spec
238+
expect(spec.components?.schemas?.['CountResponse']).toEqual({
184239
type: 'object',
240+
description: 'Response wrapper containing a count value',
185241
properties: {
186242
count: {
187243
type: 'integer',
@@ -197,8 +253,15 @@ describe('TypeParser - Hash wrapper pattern handling', () => {
197253
spec
198254
);
199255

256+
// Should create a named response component based on entity name
200257
expect(result).toEqual({
258+
$ref: '#/components/schemas/AsyncRefreshResponse',
259+
});
260+
261+
// Should add the response wrapper component to the spec
262+
expect(spec.components?.schemas?.['AsyncRefreshResponse']).toEqual({
201263
type: 'object',
264+
description: 'Response wrapper containing a AsyncRefresh entity',
202265
properties: {
203266
async_refresh: {
204267
$ref: '#/components/schemas/AsyncRefresh',
@@ -214,8 +277,15 @@ describe('TypeParser - Hash wrapper pattern handling', () => {
214277
spec
215278
);
216279

280+
// Should create a named response component
217281
expect(result).toEqual({
282+
$ref: '#/components/schemas/EnabledResponse',
283+
});
284+
285+
// Should add the component to the spec
286+
expect(spec.components?.schemas?.['EnabledResponse']).toEqual({
218287
type: 'object',
288+
description: 'Response wrapper containing a enabled value',
219289
properties: {
220290
enabled: {
221291
type: 'boolean',

0 commit comments

Comments
 (0)