Skip to content

Commit 0eadd37

Browse files
authored
Merge cde8d7e into 6a2f9f8
2 parents 6a2f9f8 + cde8d7e commit 0eadd37

File tree

9 files changed

+272
-22
lines changed

9 files changed

+272
-22
lines changed

scripts/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"@actions/core": "1.11.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",
@@ -43,6 +44,7 @@
4344
"express": "4.21.0",
4445
"folder-hash": "4.0.4",
4546
"fs-extra": "11.2.0",
47+
"httpsnippet": "3.0.1",
4648
"js-yaml": "4.1.0",
4749
"knip": "5.30.4",
4850
"micromatch": "4.0.8",

scripts/specs/format.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
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';
46

57
import { Cache } from '../cache.js';
6-
import { GENERATORS, exists, run, toAbsolutePath } from '../common.js';
8+
import { exists, GENERATORS, run, toAbsolutePath } from '../common.js';
79
import { createSpinner } from '../spinners.js';
810
import type { Spec } from '../types.js';
911

@@ -59,6 +61,7 @@ export async function transformBundle({
5961
}
6062

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

@@ -100,6 +103,33 @@ export async function transformBundle({
100103
}
101104
}
102105

106+
// skip custom path for cURL
107+
if (pathKey !== '/{path}' && specMethod['x-codeSamples']) {
108+
const harRequest = harRequests.find((baseHarRequest) =>
109+
baseHarRequest.url.includes(pathKey.replace('{indexName}', 'ALGOLIA_INDEX_NAME')),
110+
);
111+
112+
if (!harRequest?.headers) {
113+
break;
114+
}
115+
116+
for (const harRequestHeader of harRequest.headers) {
117+
if (harRequestHeader.name === bundledSpec.components.securitySchemes.appId?.name) {
118+
harRequestHeader.value = 'ALGOLIA_APPLICATION_ID';
119+
}
120+
121+
if (harRequestHeader.name === bundledSpec.components.securitySchemes.apiKey?.name) {
122+
harRequestHeader.value = 'ALGOLIA_API_KEY';
123+
}
124+
}
125+
126+
specMethod['x-codeSamples'].push({
127+
lang: 'cURL',
128+
label: 'curl',
129+
source: `${new HTTPSnippet(harRequest as HarRequest).convert('shell', 'curl')}`,
130+
});
131+
}
132+
103133
if (!bundledSpec.paths[pathKey][method].tags) {
104134
continue;
105135
}

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: Partial<{ 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)