Skip to content

Commit 9b2e727

Browse files
committed
feat(specs): add cURL snippets
1 parent 20b147d commit 9b2e727

File tree

3 files changed

+279
-6
lines changed

3 files changed

+279
-6
lines changed

scripts/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"js-yaml": "4.1.0",
5151
"knip": "5.30.4",
5252
"micromatch": "4.0.8",
53+
"openapi-snippet": "^0.14.0",
5354
"semver": "7.6.3",
5455
"spinnies": "0.5.1",
5556
"typescript": "5.6.2",

scripts/specs/format.ts

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

33
import yaml from 'js-yaml';
4+
import OpenAPISnippet from 'openapi-snippet';
45

56
import { Cache } from '../cache.js';
67
import { GENERATORS, exists, run, toAbsolutePath } from '../common.js';
@@ -100,6 +101,21 @@ export async function transformBundle({
100101
}
101102
}
102103

104+
try {
105+
const results = OpenAPISnippet.getEndpointSnippets(bundledSpec, pathKey, method, ['shell_curl']);
106+
107+
if (results.snippets.length > 0) {
108+
specMethod['x-codeSamples'].push({
109+
lang: 'cURL',
110+
label: 'curl',
111+
source: results.snippets[0].content,
112+
});
113+
}
114+
} catch (err) {
115+
// eslint-disable-next-line no-console
116+
console.error(`unable to generate cURL snippet for path ${pathKey}.${method}: `, err);
117+
}
118+
103119
if (!bundledSpec.paths[pathKey][method].tags) {
104120
continue;
105121
}

0 commit comments

Comments
 (0)