Skip to content

Commit 1b78b39

Browse files
committed
fix: backport v5 operationId accessor changes
1 parent 5c34902 commit 1b78b39

File tree

7 files changed

+948
-542
lines changed

7 files changed

+948
-542
lines changed

package-lock.json

Lines changed: 425 additions & 266 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"openapi": "3.0.0",
3+
"info": {
4+
"version": "1.0.0",
5+
"title": "Single Path"
6+
},
7+
"servers": [
8+
{
9+
"url": "https://httpbin.org"
10+
}
11+
],
12+
"paths": {
13+
"/anything": {
14+
"get": {
15+
"operationId": "get-pet",
16+
"responses": {
17+
"200": {
18+
"description": "OK"
19+
}
20+
}
21+
}
22+
}
23+
}
24+
}

packages/api/__tests__/index.test.js

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const examplesDir = path.join(__dirname, 'examples');
1414

1515
let petstoreSdk;
1616
let readmeSdk;
17+
let operationIdsSDK;
1718
const petstoreServerUrl = 'http://petstore.swagger.io/api';
1819

1920
beforeEach(async () => {
@@ -26,6 +27,10 @@ beforeEach(async () => {
2627
require.resolve('@readme/oas-examples/3.0/json/readme.json'),
2728
'utf8'
2829
),
30+
[`${[examplesDir]}/operation-ids.json`]: await realFs.readFile(
31+
require.resolve('./__fixtures__/operation-ids.oas.json'),
32+
'utf8'
33+
),
2934
[`${[examplesDir]}/uspto.json`]: await realFs.readFile(
3035
require.resolve('@readme/oas-examples/3.0/json/uspto.json'),
3136
'utf8'
@@ -39,6 +44,10 @@ beforeEach(async () => {
3944
const readme = path.join(examplesDir, 'readme.json');
4045
await new Cache(readme).saveFile();
4146
readmeSdk = api(readme);
47+
48+
const operationIds = path.join(examplesDir, 'operation-ids.json');
49+
await new Cache(readme).saveFile();
50+
operationIdsSDK = api(operationIds);
4251
});
4352

4453
afterEach(() => {
@@ -79,8 +88,11 @@ describe('#preloading', () => {
7988
'head',
8089
'patch',
8190
'trace',
91+
'listDataSets',
8292
'list-data-sets',
93+
'listSearchableFields',
8394
'list-searchable-fields',
95+
'performSearch',
8496
'perform-search',
8597
]);
8698

@@ -113,8 +125,26 @@ describe('#accessors', () => {
113125
}).not.toThrow();
114126
});
115127

116-
it('should work with operationIds that have contain spaces', () => {
117-
expect(typeof petstoreSdk['find pet by id']).toBe('function');
128+
it('should work with operationIds that have contain spaces', async () => {
129+
const mock = nock(petstoreServerUrl).get('/pets/1234').twice().reply(200, 'it worked!');
130+
131+
await expect(petstoreSdk['find pet by id']({ id: 1234 })).resolves.toBe('it worked!');
132+
133+
// Because we don't want people using ugly operationIDs like the above we transform them into
134+
// JS-friendly method accessors also.
135+
await expect(petstoreSdk.findPetById({ id: 1234 })).resolves.toBe('it worked!');
136+
mock.done();
137+
});
138+
139+
it('should work with operationIds that contain hyphens', async () => {
140+
const mock = nock('https://httpbin.org').get('/anything').twice().reply(200, 'it worked!');
141+
142+
await expect(operationIdsSDK['get-pet']()).resolves.toBe('it worked!');
143+
144+
// Because we don't want people using ugly operationIDs like the above we transform them into
145+
// JS-friendly method accessors also.
146+
await expect(operationIdsSDK.getPet()).resolves.toBe('it worked!');
147+
mock.done();
118148
});
119149

120150
it('should work for other methods', () => {

0 commit comments

Comments
 (0)