Skip to content

Commit 5fa85f8

Browse files
committed
chore: use kong
1 parent 40f22c9 commit 5fa85f8

File tree

10 files changed

+44
-27
lines changed

10 files changed

+44
-27
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"@babel/core": "7.25.2",
3434
"@babel/eslint-parser": "7.25.1",
3535
"@eslint-community/eslint-plugin-eslint-comments": "4.4.0",
36+
"@har-sdk/oas": "^2.10.0",
3637
"@openapitools/openapi-generator-cli": "2.13.12",
3738
"@redocly/cli": "1.25.4",
3839
"@stylistic/eslint-plugin": "2.8.0",

scripts/.eslintrc.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ module.exports = {
3333
],
3434
'@typescript-eslint/sort-type-union-intersection-members': 0,
3535
complexity: 0,
36+
'max-depth': 0,
3637
'no-param-reassign': 0,
3738
'@typescript-eslint/consistent-type-assertions': 0,
3839
'@typescript-eslint/consistent-type-imports': 0,

scripts/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"@actions/core": "1.10.1",
2626
"@actions/exec": "1.1.1",
2727
"@actions/io": "1.1.3",
28+
"@har-sdk/oas": "2.10.0",
2829
"@octokit/rest": "21.0.2",
2930
"@types/express": "5.0.0",
3031
"@types/folder-hash": "4.0.4",
@@ -47,10 +48,10 @@
4748
"express": "4.21.0",
4849
"folder-hash": "4.0.4",
4950
"fs-extra": "11.2.0",
51+
"httpsnippet": "3.0.1",
5052
"js-yaml": "4.1.0",
5153
"knip": "5.30.4",
5254
"micromatch": "4.0.8",
53-
"openapi-snippet": "^0.14.0",
5455
"semver": "7.6.3",
5556
"spinnies": "0.5.1",
5657
"typescript": "5.6.2",

scripts/specs/format.ts

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import fsp from 'fs/promises';
22

3+
import oas2har from '@har-sdk/oas';
4+
import { HarRequest, HTTPSnippet } from 'httpsnippet';
35
import yaml from 'js-yaml';
4-
import OpenAPISnippet from 'openapi-snippet';
56

67
import { Cache } from '../cache.js';
78
import { GENERATORS, exists, run, toAbsolutePath } from '../common.js';
@@ -60,6 +61,7 @@ export async function transformBundle({
6061
}
6162

6263
const bundledSpec = yaml.load(await fsp.readFile(bundledPath, 'utf8')) as Spec;
64+
const harRequests = await oas2har.oas2har(bundledSpec as any, { includeVendorExamples: true });
6365
const tagsDefinitions = bundledSpec.tags;
6466
const snippetSamples = docs ? await transformSnippetsToCodeSamples(clientName) : ({} as SnippetSamples);
6567

@@ -101,19 +103,30 @@ export async function transformBundle({
101103
}
102104
}
103105

104-
try {
105-
const results = OpenAPISnippet.getEndpointSnippets(bundledSpec, pathKey, method, ['shell_curl']);
106+
// skip custom path for cURL
107+
if (pathKey !== '/{path}') {
108+
const harRequest = harRequests.find((baseHarRequest) =>
109+
baseHarRequest.url.includes(pathKey.replace('{indexName}', 'ALGOLIA_INDEX_NAME')),
110+
);
106111

107-
if (results.snippets.length > 0) {
108-
specMethod['x-codeSamples'].push({
109-
lang: 'cURL',
110-
label: 'curl',
111-
source: results.snippets[0].content,
112-
});
112+
if (!harRequest?.headers) {
113+
break;
113114
}
114-
} catch (err) {
115-
// eslint-disable-next-line no-console
116-
console.error(`unable to generate cURL snippet for path ${pathKey}.${method}: `, err);
115+
for (const harRequestHeader of harRequest.headers) {
116+
if (harRequestHeader.name === bundledSpec.components.securitySchemes.appId.name) {
117+
harRequestHeader.value = 'ALGOLIA_APPLICATION_ID';
118+
}
119+
120+
if (harRequestHeader.name === bundledSpec.components.securitySchemes.apiKey.name) {
121+
harRequestHeader.value = 'ALGOLIA_API_KEY';
122+
}
123+
}
124+
125+
specMethod['x-codeSamples'].push({
126+
lang: 'cURL',
127+
label: 'curl',
128+
source: new HTTPSnippet(harRequest as HarRequest).convert('shell', 'curl', { indent: '\t' }),
129+
});
117130
}
118131

119132
if (!bundledSpec.paths[pathKey][method].tags) {

scripts/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export type Spec = {
4646
paths: Path;
4747
components: {
4848
schemas: Record<string, any>;
49+
securitySchemes: { appId: Record<string, any>; apiKey: Record<string, any> };
4950
};
5051
};
5152

specs/common/parameters.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ IndexName:
66
required: true
77
schema:
88
type: string
9-
example: YourIndexName
9+
example: ALGOLIA_INDEX_NAME
1010

1111
ObjectID:
1212
name: objectID
@@ -24,7 +24,7 @@ Index:
2424
required: true
2525
schema:
2626
type: string
27-
example: YourIndexName
27+
example: ALGOLIA_INDEX_NAME
2828

2929
StartDate:
3030
in: query

specs/insights/common/schemas/EventAttributes.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ eventName:
1313
index:
1414
type: string
1515
description: Index name (case-sensitive) to which the event's items belong.
16-
example: YourIndexName
16+
example: ALGOLIA_INDEX_NAME
1717

1818
userToken:
1919
type: string

specs/recommend/spec.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,23 +73,23 @@ servers:
7373
- url: https://{appId}.algolianet.com
7474
variables:
7575
appId:
76-
default: myAppId
76+
default: ALGOLIA_APPLICATION_ID
7777
- url: https://{appId}-1.algolianet.com
7878
variables:
7979
appId:
80-
default: myAppId
80+
default: ALGOLIA_APPLICATION_ID
8181
- url: https://{appId}-2.algolianet.com
8282
variables:
8383
appId:
84-
default: myAppId
84+
default: ALGOLIA_APPLICATION_ID
8585
- url: https://{appId}-3.algolianet.com
8686
variables:
8787
appId:
88-
default: myAppId
88+
default: ALGOLIA_APPLICATION_ID
8989
- url: https://{appId}-dsn.algolianet.com
9090
variables:
9191
appId:
92-
default: myAppId
92+
default: ALGOLIA_APPLICATION_ID
9393
security:
9494
- appId: []
9595
apiKey: []

specs/search/paths/keys/common/parameters.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ KeyString:
44
required: true
55
schema:
66
type: string
7-
example: YourAPIKey
7+
example: ALGOLIA_API_KEY
88
description: API key.

specs/search/spec.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,23 +89,23 @@ servers:
8989
- url: https://{appId}.algolia.net
9090
variables:
9191
appId:
92-
default: myAppId
92+
default: ALGOLIA_APPLICATION_ID
9393
- url: https://{appId}-1.algolianet.com
9494
variables:
9595
appId:
96-
default: myAppId
96+
default: ALGOLIA_APPLICATION_ID
9797
- url: https://{appId}-2.algolianet.com
9898
variables:
9999
appId:
100-
default: myAppId
100+
default: ALGOLIA_APPLICATION_ID
101101
- url: https://{appId}-3.algolianet.com
102102
variables:
103103
appId:
104-
default: myAppId
104+
default: ALGOLIA_APPLICATION_ID
105105
- url: https://{appId}-dsn.algolia.net
106106
variables:
107107
appId:
108-
default: myAppId
108+
default: ALGOLIA_APPLICATION_ID
109109
security:
110110
- appId: []
111111
apiKey: []

0 commit comments

Comments
 (0)