@scalar/api-client 3.8.5 → 3.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +41 -0
- package/dist/plugins/posthog/sanitize-event-payload.d.ts.map +1 -1
- package/dist/plugins/posthog/sanitize-event-payload.js +2 -0
- package/dist/plugins/posthog/sanitize-event-payload.js.map +1 -1
- package/dist/style.css +16 -19
- package/dist/v2/blocks/channel-operation-block/helpers/connect-websocket.d.ts +46 -0
- package/dist/v2/blocks/channel-operation-block/helpers/connect-websocket.d.ts.map +1 -0
- package/dist/v2/blocks/channel-operation-block/helpers/websocket-session.d.ts +59 -0
- package/dist/v2/blocks/channel-operation-block/helpers/websocket-session.d.ts.map +1 -0
- package/dist/v2/blocks/channel-operation-block/index.d.ts +3 -0
- package/dist/v2/blocks/channel-operation-block/index.d.ts.map +1 -0
- package/dist/v2/blocks/operation-block/OperationBlock.vue.d.ts.map +1 -1
- package/dist/v2/blocks/operation-block/OperationBlock.vue.js.map +1 -1
- package/dist/v2/blocks/operation-block/OperationBlock.vue.script.js +4 -0
- package/dist/v2/blocks/operation-block/OperationBlock.vue.script.js.map +1 -1
- package/dist/v2/blocks/operation-code-sample/components/OperationCodeSample.vue.d.ts +7 -4
- package/dist/v2/blocks/operation-code-sample/components/OperationCodeSample.vue.d.ts.map +1 -1
- package/dist/v2/blocks/operation-code-sample/components/OperationCodeSample.vue.js +1 -1
- package/dist/v2/blocks/operation-code-sample/components/OperationCodeSample.vue.js.map +1 -1
- package/dist/v2/blocks/operation-code-sample/components/OperationCodeSample.vue.script.js +28 -15
- package/dist/v2/blocks/operation-code-sample/components/OperationCodeSample.vue.script.js.map +1 -1
- package/dist/v2/blocks/operation-code-sample/helpers/find-client.d.ts +31 -31
- package/dist/v2/blocks/operation-code-sample/helpers/find-client.d.ts.map +1 -1
- package/dist/v2/blocks/operation-code-sample/helpers/find-client.js +32 -39
- package/dist/v2/blocks/operation-code-sample/helpers/find-client.js.map +1 -1
- package/dist/v2/blocks/operation-code-sample/helpers/format-language.d.ts +8 -0
- package/dist/v2/blocks/operation-code-sample/helpers/format-language.d.ts.map +1 -0
- package/dist/v2/blocks/operation-code-sample/helpers/format-language.js +70 -0
- package/dist/v2/blocks/operation-code-sample/helpers/format-language.js.map +1 -0
- package/dist/v2/blocks/operation-code-sample/helpers/generate-client-options.d.ts +17 -2
- package/dist/v2/blocks/operation-code-sample/helpers/generate-client-options.d.ts.map +1 -1
- package/dist/v2/blocks/operation-code-sample/helpers/generate-client-options.js +26 -3
- package/dist/v2/blocks/operation-code-sample/helpers/generate-client-options.js.map +1 -1
- package/dist/v2/blocks/operation-code-sample/helpers/generate-code-snippet.d.ts.map +1 -1
- package/dist/v2/blocks/operation-code-sample/helpers/generate-code-snippet.js +2 -2
- package/dist/v2/blocks/operation-code-sample/helpers/generate-code-snippet.js.map +1 -1
- package/dist/v2/blocks/operation-code-sample/helpers/get-clients.d.ts +2 -1
- package/dist/v2/blocks/operation-code-sample/helpers/get-clients.d.ts.map +1 -1
- package/dist/v2/blocks/operation-code-sample/helpers/get-clients.js +23 -17
- package/dist/v2/blocks/operation-code-sample/helpers/get-clients.js.map +1 -1
- package/dist/v2/blocks/operation-code-sample/helpers/get-custom-code-samples.d.ts +38 -3
- package/dist/v2/blocks/operation-code-sample/helpers/get-custom-code-samples.d.ts.map +1 -1
- package/dist/v2/blocks/operation-code-sample/helpers/get-custom-code-samples.js +74 -8
- package/dist/v2/blocks/operation-code-sample/helpers/get-custom-code-samples.js.map +1 -1
- package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/process-body.d.ts.map +1 -1
- package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/process-body.js +12 -87
- package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/process-body.js.map +1 -1
- package/dist/v2/blocks/operation-code-sample/index.d.ts +1 -1
- package/dist/v2/blocks/operation-code-sample/index.d.ts.map +1 -1
- package/dist/v2/blocks/operation-code-sample/index.js +2 -2
- package/dist/v2/blocks/request-block/components/RequestCodeSnippet.vue.d.ts.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestCodeSnippet.vue.js.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestCodeSnippet.vue.script.js +11 -6
- package/dist/v2/blocks/request-block/components/RequestCodeSnippet.vue.script.js.map +1 -1
- package/dist/v2/constants.js +1 -1
- package/dist/v2/workspace-events.d.ts.map +1 -1
- package/dist/v2/workspace-events.js +2 -0
- package/dist/v2/workspace-events.js.map +1 -1
- package/dist/vue-styles.css +7 -7
- package/package.json +19 -14
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { capitalize } from "@scalar/helpers/string/capitalize";
|
|
2
|
+
//#region src/v2/blocks/operation-code-sample/helpers/format-language.ts
|
|
3
|
+
/**
|
|
4
|
+
* Display names for the most common languages found in custom code samples.
|
|
5
|
+
*
|
|
6
|
+
* Custom samples (`x-scalar-examples`, `x-readme`, `x-stainless-*`, …) carry a
|
|
7
|
+
* free-form `lang` string that we otherwise show verbatim in the picker. This
|
|
8
|
+
* map gives the common ones a properly cased label (e.g. `typescript` →
|
|
9
|
+
* `TypeScript`). Anything not listed falls back to a simple capitalization.
|
|
10
|
+
*/
|
|
11
|
+
var LANGUAGE_LABELS = {
|
|
12
|
+
c: "C",
|
|
13
|
+
clojure: "Clojure",
|
|
14
|
+
cpp: "C++",
|
|
15
|
+
"c++": "C++",
|
|
16
|
+
csharp: "C#",
|
|
17
|
+
"c#": "C#",
|
|
18
|
+
css: "CSS",
|
|
19
|
+
curl: "cURL",
|
|
20
|
+
dart: "Dart",
|
|
21
|
+
fsharp: "F#",
|
|
22
|
+
"f#": "F#",
|
|
23
|
+
go: "Go",
|
|
24
|
+
golang: "Go",
|
|
25
|
+
graphql: "GraphQL",
|
|
26
|
+
html: "HTML",
|
|
27
|
+
http: "HTTP",
|
|
28
|
+
java: "Java",
|
|
29
|
+
javascript: "JavaScript",
|
|
30
|
+
js: "JavaScript",
|
|
31
|
+
json: "JSON",
|
|
32
|
+
kotlin: "Kotlin",
|
|
33
|
+
node: "Node.js",
|
|
34
|
+
nodejs: "Node.js",
|
|
35
|
+
objc: "Objective-C",
|
|
36
|
+
"objective-c": "Objective-C",
|
|
37
|
+
ocaml: "OCaml",
|
|
38
|
+
php: "PHP",
|
|
39
|
+
powershell: "PowerShell",
|
|
40
|
+
py: "Python",
|
|
41
|
+
python: "Python",
|
|
42
|
+
r: "R",
|
|
43
|
+
ruby: "Ruby",
|
|
44
|
+
rust: "Rust",
|
|
45
|
+
scala: "Scala",
|
|
46
|
+
sh: "Shell",
|
|
47
|
+
shell: "Shell",
|
|
48
|
+
bash: "Shell",
|
|
49
|
+
sql: "SQL",
|
|
50
|
+
swift: "Swift",
|
|
51
|
+
ts: "TypeScript",
|
|
52
|
+
typescript: "TypeScript",
|
|
53
|
+
xml: "XML",
|
|
54
|
+
yaml: "YAML",
|
|
55
|
+
yml: "YAML"
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Turn a free-form language identifier into a display label for the code sample picker.
|
|
59
|
+
*
|
|
60
|
+
* @param lang - The language identifier from a custom code sample (e.g. `typescript`)
|
|
61
|
+
* @returns A properly cased label (e.g. `TypeScript`), or `undefined` when no language is given
|
|
62
|
+
*/
|
|
63
|
+
var formatLanguage = (lang) => {
|
|
64
|
+
if (!lang) return;
|
|
65
|
+
return LANGUAGE_LABELS[lang.toLowerCase()] ?? capitalize(lang);
|
|
66
|
+
};
|
|
67
|
+
//#endregion
|
|
68
|
+
export { formatLanguage };
|
|
69
|
+
|
|
70
|
+
//# sourceMappingURL=format-language.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format-language.js","names":[],"sources":["../../../../../src/v2/blocks/operation-code-sample/helpers/format-language.ts"],"sourcesContent":["import { capitalize } from '@scalar/helpers/string/capitalize'\n\n/**\n * Display names for the most common languages found in custom code samples.\n *\n * Custom samples (`x-scalar-examples`, `x-readme`, `x-stainless-*`, …) carry a\n * free-form `lang` string that we otherwise show verbatim in the picker. This\n * map gives the common ones a properly cased label (e.g. `typescript` →\n * `TypeScript`). Anything not listed falls back to a simple capitalization.\n */\nconst LANGUAGE_LABELS: Record<string, string> = {\n c: 'C',\n clojure: 'Clojure',\n cpp: 'C++',\n 'c++': 'C++',\n csharp: 'C#',\n 'c#': 'C#',\n css: 'CSS',\n curl: 'cURL',\n dart: 'Dart',\n fsharp: 'F#',\n 'f#': 'F#',\n go: 'Go',\n golang: 'Go',\n graphql: 'GraphQL',\n html: 'HTML',\n http: 'HTTP',\n java: 'Java',\n javascript: 'JavaScript',\n js: 'JavaScript',\n json: 'JSON',\n kotlin: 'Kotlin',\n node: 'Node.js',\n nodejs: 'Node.js',\n objc: 'Objective-C',\n 'objective-c': 'Objective-C',\n ocaml: 'OCaml',\n php: 'PHP',\n powershell: 'PowerShell',\n py: 'Python',\n python: 'Python',\n r: 'R',\n ruby: 'Ruby',\n rust: 'Rust',\n scala: 'Scala',\n sh: 'Shell',\n shell: 'Shell',\n bash: 'Shell',\n sql: 'SQL',\n swift: 'Swift',\n ts: 'TypeScript',\n typescript: 'TypeScript',\n xml: 'XML',\n yaml: 'YAML',\n yml: 'YAML',\n}\n\n/**\n * Turn a free-form language identifier into a display label for the code sample picker.\n *\n * @param lang - The language identifier from a custom code sample (e.g. `typescript`)\n * @returns A properly cased label (e.g. `TypeScript`), or `undefined` when no language is given\n */\nexport const formatLanguage = (lang?: string): string | undefined => {\n if (!lang) {\n return undefined\n }\n\n return LANGUAGE_LABELS[lang.toLowerCase()] ?? capitalize(lang)\n}\n"],"mappings":";;;;;;;;;;AAUA,IAAM,kBAA0C;CAC9C,GAAG;CACH,SAAS;CACT,KAAK;CACL,OAAO;CACP,QAAQ;CACR,MAAM;CACN,KAAK;CACL,MAAM;CACN,MAAM;CACN,QAAQ;CACR,MAAM;CACN,IAAI;CACJ,QAAQ;CACR,SAAS;CACT,MAAM;CACN,MAAM;CACN,MAAM;CACN,YAAY;CACZ,IAAI;CACJ,MAAM;CACN,QAAQ;CACR,MAAM;CACN,QAAQ;CACR,MAAM;CACN,eAAe;CACf,OAAO;CACP,KAAK;CACL,YAAY;CACZ,IAAI;CACJ,QAAQ;CACR,GAAG;CACH,MAAM;CACN,MAAM;CACN,OAAO;CACP,IAAI;CACJ,OAAO;CACP,MAAM;CACN,KAAK;CACL,OAAO;CACP,IAAI;CACJ,YAAY;CACZ,KAAK;CACL,MAAM;CACN,KAAK;CACN;;;;;;;AAQD,IAAa,kBAAkB,SAAsC;AACnE,KAAI,CAAC,KACH;AAGF,QAAO,gBAAgB,KAAK,aAAa,KAAK,WAAW,KAAK"}
|
|
@@ -3,8 +3,23 @@ import type { XCodeSample } from '@scalar/workspace-store/schemas/extensions/ope
|
|
|
3
3
|
import type { ClientOptionGroup } from '../../../../v2/blocks/operation-code-sample/types';
|
|
4
4
|
/** Type of custom code sample IDs */
|
|
5
5
|
export type CustomCodeSampleId = `custom/${string}`;
|
|
6
|
-
/**
|
|
7
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Build stable, language-keyed ids for an operation's custom code samples.
|
|
8
|
+
*
|
|
9
|
+
* Custom samples are defined per operation, but a selection (e.g. the Python SDK
|
|
10
|
+
* example) should sync across every operation that ships the same language. So we
|
|
11
|
+
* key the id by language rather than by position: the first sample of a language
|
|
12
|
+
* becomes `custom/<lang>`, and any further samples that repeat a language fall back
|
|
13
|
+
* to `custom/<lang>/<n>` so they stay individually selectable within the operation.
|
|
14
|
+
*
|
|
15
|
+
* The language is lower-cased so a selection still matches when operations (or
|
|
16
|
+
* extensions) spell the same language with different casing (e.g. `Python` vs
|
|
17
|
+
* `python`).
|
|
18
|
+
*
|
|
19
|
+
* @param samples - The custom code samples for a single operation
|
|
20
|
+
* @returns A list of ids aligned by index with the input samples
|
|
21
|
+
*/
|
|
22
|
+
export declare const getCustomClientIds: (samples: XCodeSample[]) => CustomCodeSampleId[];
|
|
8
23
|
/**
|
|
9
24
|
* Generate client options for the request example block by filtering by allowed clients
|
|
10
25
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-client-options.d.ts","sourceRoot":"","sources":["../../../../../src/v2/blocks/operation-code-sample/helpers/generate-client-options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,gBAAgB,EAAY,MAAM,kBAAkB,CAAA;AACrF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sDAAsD,CAAA;AAGvF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yCAAyC,CAAA;AAEhF,qCAAqC;AACrC,MAAM,MAAM,kBAAkB,GAAG,UAAU,MAAM,EAAE,CAAA;AAEnD
|
|
1
|
+
{"version":3,"file":"generate-client-options.d.ts","sourceRoot":"","sources":["../../../../../src/v2/blocks/operation-code-sample/helpers/generate-client-options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,gBAAgB,EAAY,MAAM,kBAAkB,CAAA;AACrF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sDAAsD,CAAA;AAGvF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yCAAyC,CAAA;AAEhF,qCAAqC;AACrC,MAAM,MAAM,kBAAkB,GAAG,UAAU,MAAM,EAAE,CAAA;AAEnD;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,kBAAkB,GAAI,SAAS,WAAW,EAAE,KAAG,kBAAkB,EAU7E,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,GAAI,iBAAgB,gBAAoC,KAAG,iBAAiB,EAuC7G,CAAA"}
|
|
@@ -1,8 +1,31 @@
|
|
|
1
1
|
import { capitalize } from "vue";
|
|
2
2
|
import { AVAILABLE_CLIENTS, snippetz } from "@scalar/snippetz";
|
|
3
3
|
//#region src/v2/blocks/operation-code-sample/helpers/generate-client-options.ts
|
|
4
|
-
/**
|
|
5
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Build stable, language-keyed ids for an operation's custom code samples.
|
|
6
|
+
*
|
|
7
|
+
* Custom samples are defined per operation, but a selection (e.g. the Python SDK
|
|
8
|
+
* example) should sync across every operation that ships the same language. So we
|
|
9
|
+
* key the id by language rather than by position: the first sample of a language
|
|
10
|
+
* becomes `custom/<lang>`, and any further samples that repeat a language fall back
|
|
11
|
+
* to `custom/<lang>/<n>` so they stay individually selectable within the operation.
|
|
12
|
+
*
|
|
13
|
+
* The language is lower-cased so a selection still matches when operations (or
|
|
14
|
+
* extensions) spell the same language with different casing (e.g. `Python` vs
|
|
15
|
+
* `python`).
|
|
16
|
+
*
|
|
17
|
+
* @param samples - The custom code samples for a single operation
|
|
18
|
+
* @returns A list of ids aligned by index with the input samples
|
|
19
|
+
*/
|
|
20
|
+
var getCustomClientIds = (samples) => {
|
|
21
|
+
const countByLang = /* @__PURE__ */ new Map();
|
|
22
|
+
return samples.map((sample) => {
|
|
23
|
+
const lang = (sample.lang || "plaintext").toLowerCase();
|
|
24
|
+
const seen = countByLang.get(lang) ?? 0;
|
|
25
|
+
countByLang.set(lang, seen + 1);
|
|
26
|
+
return seen === 0 ? `custom/${lang}` : `custom/${lang}/${seen}`;
|
|
27
|
+
});
|
|
28
|
+
};
|
|
6
29
|
/**
|
|
7
30
|
* Generate client options for the request example block by filtering by allowed clients
|
|
8
31
|
*
|
|
@@ -35,6 +58,6 @@ var generateClientOptions = (allowedClients = AVAILABLE_CLIENTS) => {
|
|
|
35
58
|
});
|
|
36
59
|
};
|
|
37
60
|
//#endregion
|
|
38
|
-
export { generateClientOptions,
|
|
61
|
+
export { generateClientOptions, getCustomClientIds };
|
|
39
62
|
|
|
40
63
|
//# sourceMappingURL=generate-client-options.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-client-options.js","names":[],"sources":["../../../../../src/v2/blocks/operation-code-sample/helpers/generate-client-options.ts"],"sourcesContent":["import { AVAILABLE_CLIENTS, type AvailableClients, snippetz } from '@scalar/snippetz'\nimport type { XCodeSample } from '@scalar/workspace-store/schemas/extensions/operation'\nimport { capitalize } from 'vue'\n\nimport type { ClientOptionGroup } from '@/v2/blocks/operation-code-sample/types'\n\n/** Type of custom code sample IDs */\nexport type CustomCodeSampleId = `custom/${string}`\n\n
|
|
1
|
+
{"version":3,"file":"generate-client-options.js","names":[],"sources":["../../../../../src/v2/blocks/operation-code-sample/helpers/generate-client-options.ts"],"sourcesContent":["import { AVAILABLE_CLIENTS, type AvailableClients, snippetz } from '@scalar/snippetz'\nimport type { XCodeSample } from '@scalar/workspace-store/schemas/extensions/operation'\nimport { capitalize } from 'vue'\n\nimport type { ClientOptionGroup } from '@/v2/blocks/operation-code-sample/types'\n\n/** Type of custom code sample IDs */\nexport type CustomCodeSampleId = `custom/${string}`\n\n/**\n * Build stable, language-keyed ids for an operation's custom code samples.\n *\n * Custom samples are defined per operation, but a selection (e.g. the Python SDK\n * example) should sync across every operation that ships the same language. So we\n * key the id by language rather than by position: the first sample of a language\n * becomes `custom/<lang>`, and any further samples that repeat a language fall back\n * to `custom/<lang>/<n>` so they stay individually selectable within the operation.\n *\n * The language is lower-cased so a selection still matches when operations (or\n * extensions) spell the same language with different casing (e.g. `Python` vs\n * `python`).\n *\n * @param samples - The custom code samples for a single operation\n * @returns A list of ids aligned by index with the input samples\n */\nexport const getCustomClientIds = (samples: XCodeSample[]): CustomCodeSampleId[] => {\n const countByLang = new Map<string, number>()\n\n return samples.map((sample): CustomCodeSampleId => {\n const lang = (sample.lang || 'plaintext').toLowerCase()\n const seen = countByLang.get(lang) ?? 0\n countByLang.set(lang, seen + 1)\n\n return seen === 0 ? `custom/${lang}` : `custom/${lang}/${seen}`\n })\n}\n\n/**\n * Generate client options for the request example block by filtering by allowed clients\n *\n * @param allowedClients - The list of allowed clients to include in the options\n * @returns A list of client option groups\n */\nexport const generateClientOptions = (allowedClients: AvailableClients = AVAILABLE_CLIENTS): ClientOptionGroup[] => {\n /** Create set of allowlist for quicker lookups */\n const allowedClientsSet = new Set(allowedClients)\n\n const options = snippetz()\n .clients()\n .flatMap((group) => {\n const options = group.clients.flatMap((plugin) => {\n const id = `${group.key}/${plugin.client}` as AvailableClients[number]\n\n // If the client is not allowed, skip it\n if (!allowedClientsSet.has(id)) {\n return []\n }\n\n return {\n id,\n lang: plugin.client === 'curl' ? ('curl' as const) : group.key,\n title: `${capitalize(group.title)} ${plugin.title}`,\n label: plugin.title,\n targetKey: group.key,\n targetTitle: group.title,\n clientKey: plugin.client,\n }\n })\n\n // If no clients are allowed, skip this group\n if (options.length === 0) {\n return []\n }\n\n return {\n label: group.title,\n key: group.key,\n options,\n }\n })\n\n return options\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAyBA,IAAa,sBAAsB,YAAiD;CAClF,MAAM,8BAAc,IAAI,KAAqB;AAE7C,QAAO,QAAQ,KAAK,WAA+B;EACjD,MAAM,QAAQ,OAAO,QAAQ,aAAa,aAAa;EACvD,MAAM,OAAO,YAAY,IAAI,KAAK,IAAI;AACtC,cAAY,IAAI,MAAM,OAAO,EAAE;AAE/B,SAAO,SAAS,IAAI,UAAU,SAAS,UAAU,KAAK,GAAG;GACzD;;;;;;;;AASJ,IAAa,yBAAyB,iBAAmC,sBAA2C;;CAElH,MAAM,oBAAoB,IAAI,IAAI,eAAe;AAoCjD,QAlCgB,UAAU,CACvB,SAAS,CACT,SAAS,UAAU;EAClB,MAAM,UAAU,MAAM,QAAQ,SAAS,WAAW;GAChD,MAAM,KAAK,GAAG,MAAM,IAAI,GAAG,OAAO;AAGlC,OAAI,CAAC,kBAAkB,IAAI,GAAG,CAC5B,QAAO,EAAE;AAGX,UAAO;IACL;IACA,MAAM,OAAO,WAAW,SAAU,SAAmB,MAAM;IAC3D,OAAO,GAAG,WAAW,MAAM,MAAM,CAAC,GAAG,OAAO;IAC5C,OAAO,OAAO;IACd,WAAW,MAAM;IACjB,aAAa,MAAM;IACnB,WAAW,OAAO;IACnB;IACD;AAGF,MAAI,QAAQ,WAAW,EACrB,QAAO,EAAE;AAGX,SAAO;GACL,OAAO,MAAM;GACb,KAAK,MAAM;GACX;GACD;GACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-code-snippet.d.ts","sourceRoot":"","sources":["../../../../../src/v2/blocks/operation-code-sample/helpers/generate-code-snippet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAA;AACnE,OAAO,KAAK,EAAE,eAAe,EAAsB,MAAM,kBAAkB,CAAA;AAC3E,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,yCAAyC,CAAA;AACzF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qEAAqE,CAAA;AACxG,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sDAAsD,CAAA;AACvF,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,8DAA8D,CAAA;AAIjH,OAAO,EAAE,KAAK,kBAAkB,
|
|
1
|
+
{"version":3,"file":"generate-code-snippet.d.ts","sourceRoot":"","sources":["../../../../../src/v2/blocks/operation-code-sample/helpers/generate-code-snippet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAA;AACnE,OAAO,KAAK,EAAE,eAAe,EAAsB,MAAM,kBAAkB,CAAA;AAC3E,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,yCAAyC,CAAA;AACzF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qEAAqE,CAAA;AACxG,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sDAAsD,CAAA;AACvF,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,8DAA8D,CAAA;AAIjH,OAAO,EAAE,KAAK,kBAAkB,EAAsB,MAAM,2BAA2B,CAAA;AAGvF,KAAK,wBAAwB,GAAG;IAC9B,wGAAwG;IACxG,QAAQ,EAAE,eAAe,GAAG,kBAAkB,GAAG,SAAS,CAAA;IAC1D,qFAAqF;IACrF,WAAW,EAAE,MAAM,GAAG,SAAS,CAAA;IAC/B,mFAAmF;IACnF,iBAAiB,EAAE,WAAW,EAAE,CAAA;IAChC,0EAA0E;IAC1E,OAAO,EAAE,MAAM,GAAG,SAAS,CAAA;IAC3B,gEAAgE;IAChE,MAAM,EAAE,UAAU,CAAA;IAClB,wEAAwE;IACxE,SAAS,EAAE,eAAe,CAAA;IAC1B,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAA;IACZ,iFAAiF;IACjF,eAAe,EAAE,0BAA0B,EAAE,CAAA;IAC7C,mEAAmE;IACnE,MAAM,EAAE,YAAY,GAAG,IAAI,CAAA;IAC3B,mCAAmC;IACnC,aAAa,CAAC,EAAE,aAAa,EAAE,CAAA;IAC/B,qFAAqF;IACrF,qBAAqB,CAAC,EAAE,OAAO,CAAA;IAC/B,gFAAgF;IAChF,+BAA+B,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACxD,gDAAgD;IAChD,yBAAyB,CAAC,EAAE,OAAO,CAAA;CACpC,CAAA;AAED,sEAAsE;AACtE,eAAO,MAAM,mBAAmB,GAAI,4MAcjC,wBAAwB,KAAG,MAyC7B,CAAA"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { operationToHar } from "./operation-to-har/operation-to-har.js";
|
|
2
|
-
import {
|
|
2
|
+
import { getCustomClientIds } from "./generate-client-options.js";
|
|
3
3
|
import { getSnippet } from "./get-snippet.js";
|
|
4
4
|
//#region src/v2/blocks/operation-code-sample/helpers/generate-code-snippet.ts
|
|
5
5
|
/** Generate the code snippet for the selected example OR operation */
|
|
6
6
|
var generateCodeSnippet = ({ clientId, customCodeSamples, includeDefaultHeaders = false, operation, method, path, example, contentType, server, securitySchemes, globalCookies, requestBodyCompositionSelection, defaultDisabledParameters }) => {
|
|
7
7
|
try {
|
|
8
8
|
if (!clientId) return "";
|
|
9
|
-
if (clientId.startsWith("custom")) return customCodeSamples
|
|
9
|
+
if (clientId.startsWith("custom")) return customCodeSamples[getCustomClientIds(customCodeSamples).indexOf(clientId)]?.source ?? "Custom example not found";
|
|
10
10
|
const harRequest = operationToHar({
|
|
11
11
|
operation,
|
|
12
12
|
contentType,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-code-snippet.js","names":[],"sources":["../../../../../src/v2/blocks/operation-code-sample/helpers/generate-code-snippet.ts"],"sourcesContent":["import type { HttpMethod } from '@scalar/helpers/http/http-methods'\nimport type { AvailableClient, ClientId, TargetId } from '@scalar/snippetz'\nimport type { SecuritySchemeObjectSecret } from '@scalar/workspace-store/request-example'\nimport type { XScalarCookie } from '@scalar/workspace-store/schemas/extensions/general/x-scalar-cookies'\nimport type { XCodeSample } from '@scalar/workspace-store/schemas/extensions/operation'\nimport type { OperationObject, ServerObject } from '@scalar/workspace-store/schemas/v3.1/strict/openapi-document'\n\nimport { operationToHar } from '@/v2/blocks/operation-code-sample/helpers/operation-to-har/operation-to-har'\n\nimport { type CustomCodeSampleId,
|
|
1
|
+
{"version":3,"file":"generate-code-snippet.js","names":[],"sources":["../../../../../src/v2/blocks/operation-code-sample/helpers/generate-code-snippet.ts"],"sourcesContent":["import type { HttpMethod } from '@scalar/helpers/http/http-methods'\nimport type { AvailableClient, ClientId, TargetId } from '@scalar/snippetz'\nimport type { SecuritySchemeObjectSecret } from '@scalar/workspace-store/request-example'\nimport type { XScalarCookie } from '@scalar/workspace-store/schemas/extensions/general/x-scalar-cookies'\nimport type { XCodeSample } from '@scalar/workspace-store/schemas/extensions/operation'\nimport type { OperationObject, ServerObject } from '@scalar/workspace-store/schemas/v3.1/strict/openapi-document'\n\nimport { operationToHar } from '@/v2/blocks/operation-code-sample/helpers/operation-to-har/operation-to-har'\n\nimport { type CustomCodeSampleId, getCustomClientIds } from './generate-client-options'\nimport { getSnippet } from './get-snippet'\n\ntype GenerateCodeSnippetProps = {\n /** The selected client/language for code generation (e.g., 'node/fetch') or a custom code sample ID. */\n clientId: AvailableClient | CustomCodeSampleId | undefined\n /** The Content-Type header value for the request body (e.g., 'application/json'). */\n contentType: string | undefined\n /** Array of custom code samples defined in the OpenAPI x-codeSamples extension. */\n customCodeSamples: XCodeSample[]\n /** The specific example value to use when generating the code snippet. */\n example: string | undefined\n /** The HTTP method for the operation (e.g., GET, POST, PUT). */\n method: HttpMethod\n /** The OpenAPI operation object containing request/response details. */\n operation: OperationObject\n /** The API endpoint path (e.g., '/users/{id}'). */\n path: string\n /** Array of security schemes to apply to the request (e.g., API keys, OAuth). */\n securitySchemes: SecuritySchemeObjectSecret[]\n /** The server object defining the base URL for the API request. */\n server: ServerObject | null\n /** Workspace + document cookies */\n globalCookies?: XScalarCookie[]\n /** Whether to include default headers (e.g., Accept, Content-Type) automatically. */\n includeDefaultHeaders?: boolean\n /** Selected oneOf/anyOf variants for nested request body example generation. */\n requestBodyCompositionSelection?: Record<string, number>\n /** Whether to disable parameters by default. */\n defaultDisabledParameters?: boolean\n}\n\n/** Generate the code snippet for the selected example OR operation */\nexport const generateCodeSnippet = ({\n clientId,\n customCodeSamples,\n includeDefaultHeaders = false,\n operation,\n method,\n path,\n example,\n contentType,\n server,\n securitySchemes,\n globalCookies,\n requestBodyCompositionSelection,\n defaultDisabledParameters,\n}: GenerateCodeSnippetProps): string => {\n try {\n if (!clientId) {\n return ''\n }\n\n // Use the selected custom example, matched by its language-keyed id\n if (clientId.startsWith('custom')) {\n const ids = getCustomClientIds(customCodeSamples)\n const index = ids.indexOf(clientId as CustomCodeSampleId)\n\n return customCodeSamples[index]?.source ?? 'Custom example not found'\n }\n\n const harRequest = operationToHar({\n operation,\n contentType,\n method,\n path,\n server,\n securitySchemes,\n example,\n globalCookies,\n includeDefaultHeaders,\n requestBodyCompositionSelection,\n defaultDisabledParameters,\n })\n\n const [targetKey, clientKey] = clientId.split('/') as [TargetId, ClientId<TargetId>]\n\n const [error, payload] = getSnippet(targetKey, clientKey, harRequest)\n if (error) {\n console.error('[generateCodeSnippet]', error)\n return error.message ?? 'Error generating code snippet'\n }\n\n return payload\n } catch (error) {\n console.error('[generateCodeSnippet]', error)\n return 'Error generating code snippet'\n }\n}\n"],"mappings":";;;;;AA0CA,IAAa,uBAAuB,EAClC,UACA,mBACA,wBAAwB,OACxB,WACA,QACA,MACA,SACA,aACA,QACA,iBACA,eACA,iCACA,gCACsC;AACtC,KAAI;AACF,MAAI,CAAC,SACH,QAAO;AAIT,MAAI,SAAS,WAAW,SAAS,CAI/B,QAAO,kBAHK,mBAAmB,kBAAkB,CAC/B,QAAQ,SAA+B,GAExB,UAAU;EAG7C,MAAM,aAAa,eAAe;GAChC;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACD,CAAC;EAEF,MAAM,CAAC,WAAW,aAAa,SAAS,MAAM,IAAI;EAElD,MAAM,CAAC,OAAO,WAAW,WAAW,WAAW,WAAW,WAAW;AACrE,MAAI,OAAO;AACT,WAAQ,MAAM,yBAAyB,MAAM;AAC7C,UAAO,MAAM,WAAW;;AAG1B,SAAO;UACA,OAAO;AACd,UAAQ,MAAM,yBAAyB,MAAM;AAC7C,SAAO"}
|
|
@@ -6,7 +6,8 @@ import type { CustomClientOptionGroup } from '../../../../v2/blocks/operation-co
|
|
|
6
6
|
*
|
|
7
7
|
* @param customCodeSamples - The custom code samples from the operation to merge with the client options
|
|
8
8
|
* @param clientOptions - The client options to merge with the custom code samples
|
|
9
|
+
* @param label - The label for the custom samples group (e.g. "SDK" or "Code Examples")
|
|
9
10
|
* @returns A list of client option groups
|
|
10
11
|
*/
|
|
11
|
-
export declare const getClients: (customCodeSamples: XCodeSample[], clientOptions: ClientOptionGroup[]) => CustomClientOptionGroup[];
|
|
12
|
+
export declare const getClients: (customCodeSamples: XCodeSample[], clientOptions: ClientOptionGroup[], label?: string) => CustomClientOptionGroup[];
|
|
12
13
|
//# sourceMappingURL=get-clients.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-clients.d.ts","sourceRoot":"","sources":["../../../../../src/v2/blocks/operation-code-sample/helpers/get-clients.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sDAAsD,CAAA;AAEvF,OAAO,KAAK,EAAE,iBAAiB,EAAsB,MAAM,mCAAmC,CAAA;
|
|
1
|
+
{"version":3,"file":"get-clients.d.ts","sourceRoot":"","sources":["../../../../../src/v2/blocks/operation-code-sample/helpers/get-clients.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sDAAsD,CAAA;AAEvF,OAAO,KAAK,EAAE,iBAAiB,EAAsB,MAAM,mCAAmC,CAAA;AAI9F,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,yCAAyC,CAAA;AAEtF;;;;;;;GAOG;AACH,eAAO,MAAM,UAAU,GACrB,mBAAmB,WAAW,EAAE,EAChC,eAAe,iBAAiB,EAAE,EAClC,QAAO,MAAkC,KACxC,uBAAuB,EA+BzB,CAAA"}
|
|
@@ -1,28 +1,34 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { formatLanguage } from "./format-language.js";
|
|
2
|
+
import { getCustomClientIds } from "./generate-client-options.js";
|
|
3
|
+
import { CODE_EXAMPLES_GROUP_LABEL } from "./get-custom-code-samples.js";
|
|
2
4
|
//#region src/v2/blocks/operation-code-sample/helpers/get-clients.ts
|
|
3
5
|
/**
|
|
4
6
|
* Merges custom code samples with the client options
|
|
5
7
|
*
|
|
6
8
|
* @param customCodeSamples - The custom code samples from the operation to merge with the client options
|
|
7
9
|
* @param clientOptions - The client options to merge with the custom code samples
|
|
10
|
+
* @param label - The label for the custom samples group (e.g. "SDK" or "Code Examples")
|
|
8
11
|
* @returns A list of client option groups
|
|
9
12
|
*/
|
|
10
|
-
var getClients = (customCodeSamples, clientOptions) => {
|
|
11
|
-
if (customCodeSamples.length)
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
id
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
13
|
+
var getClients = (customCodeSamples, clientOptions, label = CODE_EXAMPLES_GROUP_LABEL) => {
|
|
14
|
+
if (customCodeSamples.length) {
|
|
15
|
+
const ids = getCustomClientIds(customCodeSamples);
|
|
16
|
+
return [{
|
|
17
|
+
label,
|
|
18
|
+
key: "custom",
|
|
19
|
+
options: customCodeSamples.map((sample, index) => {
|
|
20
|
+
const id = ids[index] ?? `custom/${index}`;
|
|
21
|
+
const label = sample.label || formatLanguage(sample.lang) || id;
|
|
22
|
+
return {
|
|
23
|
+
id,
|
|
24
|
+
lang: sample.lang || "plaintext",
|
|
25
|
+
title: label,
|
|
26
|
+
label,
|
|
27
|
+
clientKey: "custom"
|
|
28
|
+
};
|
|
29
|
+
})
|
|
30
|
+
}, ...clientOptions];
|
|
31
|
+
}
|
|
26
32
|
return clientOptions;
|
|
27
33
|
};
|
|
28
34
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-clients.js","names":[],"sources":["../../../../../src/v2/blocks/operation-code-sample/helpers/get-clients.ts"],"sourcesContent":["import type { TargetId } from '@scalar/types/snippetz'\nimport type { XCodeSample } from '@scalar/workspace-store/schemas/extensions/operation'\n\nimport type { ClientOptionGroup, CustomClientOption } from '@/v2/blocks/operation-code-sample'\nimport {
|
|
1
|
+
{"version":3,"file":"get-clients.js","names":[],"sources":["../../../../../src/v2/blocks/operation-code-sample/helpers/get-clients.ts"],"sourcesContent":["import type { TargetId } from '@scalar/types/snippetz'\nimport type { XCodeSample } from '@scalar/workspace-store/schemas/extensions/operation'\n\nimport type { ClientOptionGroup, CustomClientOption } from '@/v2/blocks/operation-code-sample'\nimport { formatLanguage } from '@/v2/blocks/operation-code-sample/helpers/format-language'\nimport { getCustomClientIds } from '@/v2/blocks/operation-code-sample/helpers/generate-client-options'\nimport { CODE_EXAMPLES_GROUP_LABEL } from '@/v2/blocks/operation-code-sample/helpers/get-custom-code-samples'\nimport type { CustomClientOptionGroup } from '@/v2/blocks/operation-code-sample/types'\n\n/**\n * Merges custom code samples with the client options\n *\n * @param customCodeSamples - The custom code samples from the operation to merge with the client options\n * @param clientOptions - The client options to merge with the custom code samples\n * @param label - The label for the custom samples group (e.g. \"SDK\" or \"Code Examples\")\n * @returns A list of client option groups\n */\nexport const getClients = (\n customCodeSamples: XCodeSample[],\n clientOptions: ClientOptionGroup[],\n label: string = CODE_EXAMPLES_GROUP_LABEL,\n): CustomClientOptionGroup[] => {\n // Handle custom code examples\n if (customCodeSamples.length) {\n // Language-keyed ids so the same sample can be selected across operations\n const ids = getCustomClientIds(customCodeSamples)\n\n const customClients = customCodeSamples.map((sample, index) => {\n const id = ids[index] ?? `custom/${index}`\n const label = sample.label || formatLanguage(sample.lang) || id\n const lang = (sample.lang as TargetId) || 'plaintext'\n\n return {\n id,\n lang,\n title: label,\n label,\n clientKey: 'custom',\n } satisfies CustomClientOption\n })\n\n return [\n {\n label,\n key: 'custom',\n options: customClients,\n },\n ...clientOptions,\n ]\n }\n\n return clientOptions\n}\n"],"mappings":";;;;;;;;;;;;AAiBA,IAAa,cACX,mBACA,eACA,QAAgB,8BACc;AAE9B,KAAI,kBAAkB,QAAQ;EAE5B,MAAM,MAAM,mBAAmB,kBAAkB;AAgBjD,SAAO,CACL;GACE;GACA,KAAK;GACL,SAlBkB,kBAAkB,KAAK,QAAQ,UAAU;IAC7D,MAAM,KAAK,IAAI,UAAU,UAAU;IACnC,MAAM,QAAQ,OAAO,SAAS,eAAe,OAAO,KAAK,IAAI;AAG7D,WAAO;KACL;KACA,MAJY,OAAO,QAAqB;KAKxC,OAAO;KACP;KACA,WAAW;KACZ;KACD;GAOC,EACD,GAAG,cACJ;;AAGH,QAAO"}
|
|
@@ -1,10 +1,45 @@
|
|
|
1
1
|
import type { XCodeSample } from '@scalar/workspace-store/schemas/extensions/operation';
|
|
2
2
|
import type { OperationObject } from '@scalar/workspace-store/schemas/v3.1/strict/openapi-document';
|
|
3
|
+
/** Picker group label for samples generated by an SDK provider (Scalar, Stainless, …). */
|
|
4
|
+
declare const SDK_GROUP_LABEL = "SDK";
|
|
5
|
+
/** Picker group label for generic or docs-platform samples (the standard `x-codeSamples` family, ReadMe, …). */
|
|
6
|
+
export declare const CODE_EXAMPLES_GROUP_LABEL = "Code Examples";
|
|
7
|
+
type CustomCodeSampleGroupLabel = typeof SDK_GROUP_LABEL | typeof CODE_EXAMPLES_GROUP_LABEL;
|
|
8
|
+
type CustomCodeSamples = {
|
|
9
|
+
/**
|
|
10
|
+
* Group label for the code sample picker.
|
|
11
|
+
*
|
|
12
|
+
* Samples that come from an SDK provider extension (`x-scalar-examples`,
|
|
13
|
+
* `x-stainless-snippets`, `x-stainless-examples`) surface under "SDK". Generic
|
|
14
|
+
* or docs-platform samples (`x-readme`, the `x-codeSamples` family) surface
|
|
15
|
+
* under "Code Examples".
|
|
16
|
+
*/
|
|
17
|
+
label: CustomCodeSampleGroupLabel;
|
|
18
|
+
/** The custom code samples, in picker order. */
|
|
19
|
+
samples: XCodeSample[];
|
|
20
|
+
};
|
|
3
21
|
/**
|
|
4
|
-
* Grabs any custom code samples from the operation
|
|
22
|
+
* Grabs any custom code samples from the operation.
|
|
23
|
+
*
|
|
24
|
+
* Several tools write code samples into OpenAPI under different extensions. When
|
|
25
|
+
* more than one is present we use the highest-priority source only, rather than
|
|
26
|
+
* showing duplicates from every tool. Priority, highest first:
|
|
27
|
+
*
|
|
28
|
+
* 1. `x-scalar-examples` (SDK)
|
|
29
|
+
* 2. `x-stainless-snippets` (SDK, overrides `x-stainless-examples`)
|
|
30
|
+
* 3. `x-stainless-examples` (SDK)
|
|
31
|
+
* 4. `x-readme.code-samples` (Code Examples)
|
|
32
|
+
* 5. `x-codeSamples` / `x-code-samples` / `x-custom-examples` (Code Examples)
|
|
33
|
+
*
|
|
34
|
+
* The winning source also determines the picker group label: SDK-provider
|
|
35
|
+
* extensions surface under "SDK", everything else under "Code Examples".
|
|
36
|
+
*
|
|
37
|
+
* Note that Speakeasy does not have its own extension — it writes into the
|
|
38
|
+
* standard `x-codeSamples`, so its snippets surface under "Code Examples".
|
|
5
39
|
*
|
|
6
40
|
* @param operation - The operation to get the custom code samples from
|
|
7
|
-
* @returns
|
|
41
|
+
* @returns The picker group label and the custom code samples which exist in the operation
|
|
8
42
|
*/
|
|
9
|
-
export declare const getCustomCodeSamples: (operation: OperationObject) =>
|
|
43
|
+
export declare const getCustomCodeSamples: (operation: OperationObject) => CustomCodeSamples;
|
|
44
|
+
export {};
|
|
10
45
|
//# sourceMappingURL=get-custom-code-samples.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-custom-code-samples.d.ts","sourceRoot":"","sources":["../../../../../src/v2/blocks/operation-code-sample/helpers/get-custom-code-samples.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"get-custom-code-samples.d.ts","sourceRoot":"","sources":["../../../../../src/v2/blocks/operation-code-sample/helpers/get-custom-code-samples.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EAGZ,MAAM,sDAAsD,CAAA;AAC7D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8DAA8D,CAAA;AA+BnG,0FAA0F;AAC1F,QAAA,MAAM,eAAe,QAAQ,CAAA;AAE7B,gHAAgH;AAChH,eAAO,MAAM,yBAAyB,kBAAkB,CAAA;AAExD,KAAK,0BAA0B,GAAG,OAAO,eAAe,GAAG,OAAO,yBAAyB,CAAA;AAE3F,KAAK,iBAAiB,GAAG;IACvB;;;;;;;OAOG;IACH,KAAK,EAAE,0BAA0B,CAAA;IACjC,gDAAgD;IAChD,OAAO,EAAE,WAAW,EAAE,CAAA;CACvB,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,oBAAoB,GAAI,WAAW,eAAe,KAAG,iBAuBjE,CAAA"}
|
|
@@ -1,18 +1,84 @@
|
|
|
1
1
|
//#region src/v2/blocks/operation-code-sample/helpers/get-custom-code-samples.ts
|
|
2
|
+
/** Turns a `{ language: source }` map (x-stainless-snippets) into code samples. */
|
|
3
|
+
var fromSnippetMap = (snippets, label) => Object.entries(snippets ?? {}).map(([lang, source]) => ({
|
|
4
|
+
lang,
|
|
5
|
+
source,
|
|
6
|
+
...label ? { label } : {}
|
|
7
|
+
}));
|
|
2
8
|
/**
|
|
3
|
-
*
|
|
9
|
+
* Turns `x-stainless-examples` / `x-scalar-examples` into code samples.
|
|
10
|
+
*
|
|
11
|
+
* Each example carries per-language request snippets and an optional title that
|
|
12
|
+
* we surface as the picker label. The response is only used for documentation,
|
|
13
|
+
* so it is ignored here.
|
|
14
|
+
*/
|
|
15
|
+
var fromLanguageExamples = (examples) => {
|
|
16
|
+
if (!examples) return [];
|
|
17
|
+
return (Array.isArray(examples) ? examples : [examples]).flatMap((example) => fromSnippetMap(example.request, example.title));
|
|
18
|
+
};
|
|
19
|
+
/** Turns ReadMe's `x-readme.code-samples` into code samples. */
|
|
20
|
+
var fromReadmeSamples = (samples) => (samples ?? []).map((sample) => ({
|
|
21
|
+
lang: sample.language,
|
|
22
|
+
source: sample.code,
|
|
23
|
+
...sample.name ? { label: sample.name } : {}
|
|
24
|
+
}));
|
|
25
|
+
/** Picker group label for samples generated by an SDK provider (Scalar, Stainless, …). */
|
|
26
|
+
var SDK_GROUP_LABEL = "SDK";
|
|
27
|
+
/** Picker group label for generic or docs-platform samples (the standard `x-codeSamples` family, ReadMe, …). */
|
|
28
|
+
var CODE_EXAMPLES_GROUP_LABEL = "Code Examples";
|
|
29
|
+
/**
|
|
30
|
+
* Grabs any custom code samples from the operation.
|
|
31
|
+
*
|
|
32
|
+
* Several tools write code samples into OpenAPI under different extensions. When
|
|
33
|
+
* more than one is present we use the highest-priority source only, rather than
|
|
34
|
+
* showing duplicates from every tool. Priority, highest first:
|
|
35
|
+
*
|
|
36
|
+
* 1. `x-scalar-examples` (SDK)
|
|
37
|
+
* 2. `x-stainless-snippets` (SDK, overrides `x-stainless-examples`)
|
|
38
|
+
* 3. `x-stainless-examples` (SDK)
|
|
39
|
+
* 4. `x-readme.code-samples` (Code Examples)
|
|
40
|
+
* 5. `x-codeSamples` / `x-code-samples` / `x-custom-examples` (Code Examples)
|
|
41
|
+
*
|
|
42
|
+
* The winning source also determines the picker group label: SDK-provider
|
|
43
|
+
* extensions surface under "SDK", everything else under "Code Examples".
|
|
44
|
+
*
|
|
45
|
+
* Note that Speakeasy does not have its own extension — it writes into the
|
|
46
|
+
* standard `x-codeSamples`, so its snippets surface under "Code Examples".
|
|
4
47
|
*
|
|
5
48
|
* @param operation - The operation to get the custom code samples from
|
|
6
|
-
* @returns
|
|
49
|
+
* @returns The picker group label and the custom code samples which exist in the operation
|
|
7
50
|
*/
|
|
8
51
|
var getCustomCodeSamples = (operation) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
52
|
+
const scalarExamples = operation["x-scalar-examples"] ?? [];
|
|
53
|
+
if (scalarExamples.length) return {
|
|
54
|
+
label: SDK_GROUP_LABEL,
|
|
55
|
+
samples: scalarExamples
|
|
56
|
+
};
|
|
57
|
+
const stainlessSnippets = fromSnippetMap(operation["x-stainless-snippets"]);
|
|
58
|
+
if (stainlessSnippets.length) return {
|
|
59
|
+
label: SDK_GROUP_LABEL,
|
|
60
|
+
samples: stainlessSnippets
|
|
61
|
+
};
|
|
62
|
+
const stainlessExamples = fromLanguageExamples(operation["x-stainless-examples"]);
|
|
63
|
+
if (stainlessExamples.length) return {
|
|
64
|
+
label: SDK_GROUP_LABEL,
|
|
65
|
+
samples: stainlessExamples
|
|
66
|
+
};
|
|
67
|
+
const readmeSamples = fromReadmeSamples(operation["x-readme"]?.["code-samples"]);
|
|
68
|
+
if (readmeSamples.length) return {
|
|
69
|
+
label: CODE_EXAMPLES_GROUP_LABEL,
|
|
70
|
+
samples: readmeSamples
|
|
71
|
+
};
|
|
72
|
+
return {
|
|
73
|
+
label: CODE_EXAMPLES_GROUP_LABEL,
|
|
74
|
+
samples: [
|
|
75
|
+
"x-custom-examples",
|
|
76
|
+
"x-codeSamples",
|
|
77
|
+
"x-code-samples"
|
|
78
|
+
].flatMap((key) => operation[key] ?? [])
|
|
79
|
+
};
|
|
14
80
|
};
|
|
15
81
|
//#endregion
|
|
16
|
-
export { getCustomCodeSamples };
|
|
82
|
+
export { CODE_EXAMPLES_GROUP_LABEL, getCustomCodeSamples };
|
|
17
83
|
|
|
18
84
|
//# sourceMappingURL=get-custom-code-samples.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-custom-code-samples.js","names":[],"sources":["../../../../../src/v2/blocks/operation-code-sample/helpers/get-custom-code-samples.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"get-custom-code-samples.js","names":[],"sources":["../../../../../src/v2/blocks/operation-code-sample/helpers/get-custom-code-samples.ts"],"sourcesContent":["import type {\n XCodeSample,\n XLanguageExample,\n XReadmeCodeSample,\n} from '@scalar/workspace-store/schemas/extensions/operation'\nimport type { OperationObject } from '@scalar/workspace-store/schemas/v3.1/strict/openapi-document'\n\n/** Turns a `{ language: source }` map (x-stainless-snippets) into code samples. */\nconst fromSnippetMap = (snippets: Record<string, string> | undefined, label?: string): XCodeSample[] =>\n Object.entries(snippets ?? {}).map(([lang, source]) => ({ lang, source, ...(label ? { label } : {}) }))\n\n/**\n * Turns `x-stainless-examples` / `x-scalar-examples` into code samples.\n *\n * Each example carries per-language request snippets and an optional title that\n * we surface as the picker label. The response is only used for documentation,\n * so it is ignored here.\n */\nconst fromLanguageExamples = (examples: XLanguageExample | XLanguageExample[] | undefined): XCodeSample[] => {\n if (!examples) {\n return []\n }\n\n return (Array.isArray(examples) ? examples : [examples]).flatMap((example) =>\n fromSnippetMap(example.request, example.title),\n )\n}\n\n/** Turns ReadMe's `x-readme.code-samples` into code samples. */\nconst fromReadmeSamples = (samples: XReadmeCodeSample[] | undefined): XCodeSample[] =>\n (samples ?? []).map((sample) => ({\n lang: sample.language,\n source: sample.code,\n ...(sample.name ? { label: sample.name } : {}),\n }))\n\n/** Picker group label for samples generated by an SDK provider (Scalar, Stainless, …). */\nconst SDK_GROUP_LABEL = 'SDK'\n\n/** Picker group label for generic or docs-platform samples (the standard `x-codeSamples` family, ReadMe, …). */\nexport const CODE_EXAMPLES_GROUP_LABEL = 'Code Examples'\n\ntype CustomCodeSampleGroupLabel = typeof SDK_GROUP_LABEL | typeof CODE_EXAMPLES_GROUP_LABEL\n\ntype CustomCodeSamples = {\n /**\n * Group label for the code sample picker.\n *\n * Samples that come from an SDK provider extension (`x-scalar-examples`,\n * `x-stainless-snippets`, `x-stainless-examples`) surface under \"SDK\". Generic\n * or docs-platform samples (`x-readme`, the `x-codeSamples` family) surface\n * under \"Code Examples\".\n */\n label: CustomCodeSampleGroupLabel\n /** The custom code samples, in picker order. */\n samples: XCodeSample[]\n}\n\n/**\n * Grabs any custom code samples from the operation.\n *\n * Several tools write code samples into OpenAPI under different extensions. When\n * more than one is present we use the highest-priority source only, rather than\n * showing duplicates from every tool. Priority, highest first:\n *\n * 1. `x-scalar-examples` (SDK)\n * 2. `x-stainless-snippets` (SDK, overrides `x-stainless-examples`)\n * 3. `x-stainless-examples` (SDK)\n * 4. `x-readme.code-samples` (Code Examples)\n * 5. `x-codeSamples` / `x-code-samples` / `x-custom-examples` (Code Examples)\n *\n * The winning source also determines the picker group label: SDK-provider\n * extensions surface under \"SDK\", everything else under \"Code Examples\".\n *\n * Note that Speakeasy does not have its own extension — it writes into the\n * standard `x-codeSamples`, so its snippets surface under \"Code Examples\".\n *\n * @param operation - The operation to get the custom code samples from\n * @returns The picker group label and the custom code samples which exist in the operation\n */\nexport const getCustomCodeSamples = (operation: OperationObject): CustomCodeSamples => {\n const scalarExamples = operation['x-scalar-examples'] ?? []\n if (scalarExamples.length) {\n return { label: SDK_GROUP_LABEL, samples: scalarExamples }\n }\n\n const stainlessSnippets = fromSnippetMap(operation['x-stainless-snippets'])\n if (stainlessSnippets.length) {\n return { label: SDK_GROUP_LABEL, samples: stainlessSnippets }\n }\n\n const stainlessExamples = fromLanguageExamples(operation['x-stainless-examples'])\n if (stainlessExamples.length) {\n return { label: SDK_GROUP_LABEL, samples: stainlessExamples }\n }\n\n const readmeSamples = fromReadmeSamples(operation['x-readme']?.['code-samples'])\n if (readmeSamples.length) {\n return { label: CODE_EXAMPLES_GROUP_LABEL, samples: readmeSamples }\n }\n\n const customCodeKeys = ['x-custom-examples', 'x-codeSamples', 'x-code-samples'] as const\n return { label: CODE_EXAMPLES_GROUP_LABEL, samples: customCodeKeys.flatMap((key) => operation[key] ?? []) }\n}\n"],"mappings":";;AAQA,IAAM,kBAAkB,UAA8C,UACpE,OAAO,QAAQ,YAAY,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,aAAa;CAAE;CAAM;CAAQ,GAAI,QAAQ,EAAE,OAAO,GAAG,EAAE;CAAG,EAAE;;;;;;;;AASzG,IAAM,wBAAwB,aAA+E;AAC3G,KAAI,CAAC,SACH,QAAO,EAAE;AAGX,SAAQ,MAAM,QAAQ,SAAS,GAAG,WAAW,CAAC,SAAS,EAAE,SAAS,YAChE,eAAe,QAAQ,SAAS,QAAQ,MAAM,CAC/C;;;AAIH,IAAM,qBAAqB,aACxB,WAAW,EAAE,EAAE,KAAK,YAAY;CAC/B,MAAM,OAAO;CACb,QAAQ,OAAO;CACf,GAAI,OAAO,OAAO,EAAE,OAAO,OAAO,MAAM,GAAG,EAAE;CAC9C,EAAE;;AAGL,IAAM,kBAAkB;;AAGxB,IAAa,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;AAwCzC,IAAa,wBAAwB,cAAkD;CACrF,MAAM,iBAAiB,UAAU,wBAAwB,EAAE;AAC3D,KAAI,eAAe,OACjB,QAAO;EAAE,OAAO;EAAiB,SAAS;EAAgB;CAG5D,MAAM,oBAAoB,eAAe,UAAU,wBAAwB;AAC3E,KAAI,kBAAkB,OACpB,QAAO;EAAE,OAAO;EAAiB,SAAS;EAAmB;CAG/D,MAAM,oBAAoB,qBAAqB,UAAU,wBAAwB;AACjF,KAAI,kBAAkB,OACpB,QAAO;EAAE,OAAO;EAAiB,SAAS;EAAmB;CAG/D,MAAM,gBAAgB,kBAAkB,UAAU,cAAc,gBAAgB;AAChF,KAAI,cAAc,OAChB,QAAO;EAAE,OAAO;EAA2B,SAAS;EAAe;AAIrE,QAAO;EAAE,OAAO;EAA2B,SADpB;GAAC;GAAqB;GAAiB;GAAiB,CACZ,SAAS,QAAQ,UAAU,QAAQ,EAAE,CAAC;EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"process-body.d.ts","sourceRoot":"","sources":["../../../../../../src/v2/blocks/operation-code-sample/helpers/operation-to-har/process-body.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"process-body.d.ts","sourceRoot":"","sources":["../../../../../../src/v2/blocks/operation-code-sample/helpers/operation-to-har/process-body.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAEV,iBAAiB,EAElB,MAAM,8DAA8D,CAAA;AAErE,OAAO,KAAK,EAAS,QAAQ,EAAE,MAAM,YAAY,CAAA;AAEjD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAE7D,KAAK,gBAAgB,GAAG,IAAI,CAAC,mBAAmB,EAAE,aAAa,GAAG,SAAS,GAAG,iCAAiC,CAAC,GAAG;IACjH,WAAW,EAAE,iBAAiB,CAAA;CAC/B,CAAA;AAyJD;;;GAGG;AACH,eAAO,MAAM,WAAW,GAAI,yEAKzB,gBAAgB,KAAG,QAAQ,GAAG,SAyFhC,CAAA"}
|
|
@@ -1,20 +1,10 @@
|
|
|
1
1
|
import { getResolvedRefDeep } from "../get-resolved-ref-deep.js";
|
|
2
|
-
import { getExample, getExampleFromSchema,
|
|
2
|
+
import { getExample, getExampleFromSchema, serializeFormPropertyWithEncoding } from "@scalar/workspace-store/request-example";
|
|
3
3
|
import { getResolvedRef } from "@scalar/workspace-store/helpers/get-resolved-ref";
|
|
4
4
|
import { json2xml } from "@scalar/helpers/file/json2xml";
|
|
5
5
|
import { unpackProxyObject } from "@scalar/workspace-store/helpers/unpack-proxy";
|
|
6
6
|
//#region src/v2/blocks/operation-code-sample/helpers/operation-to-har/process-body.ts
|
|
7
7
|
/**
|
|
8
|
-
* Stringify a value emitted by `serializeFormStyle` into a HAR param value.
|
|
9
|
-
*
|
|
10
|
-
* Form-style serialization only addresses one level of nesting per RFC6570;
|
|
11
|
-
* deeper structures (an object or array still sitting in `entry.value`) are
|
|
12
|
-
* spec-undefined. JSON-stringify them so authors get readable output instead
|
|
13
|
-
* of `String(value)` returning `"[object Object]"`. Primitives pass through
|
|
14
|
-
* `String()` to preserve the existing wire shape (e.g. `true` → `"true"`).
|
|
15
|
-
*/
|
|
16
|
-
var stringifyEntryValue = (value) => value !== null && typeof value === "object" ? JSON.stringify(value) : String(value);
|
|
17
|
-
/**
|
|
18
8
|
* Converts a form-data body into HAR `Param[]` entries for `multipart/form-data`
|
|
19
9
|
* and `application/x-www-form-urlencoded` requests.
|
|
20
10
|
*
|
|
@@ -56,83 +46,18 @@ var objectToFormParams = (obj, encoding, parentKey, isMultipart = false) => {
|
|
|
56
46
|
*/
|
|
57
47
|
const explicitContentType = hasFormStyle || !isMultipart ? void 0 : partEncoding?.contentType;
|
|
58
48
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* Primitives skip this branch and fall through to the String(value) path below since
|
|
66
|
-
* style is a no-op for primitives. Files skip too, as do arrays containing Files —
|
|
67
|
-
* RFC6570 expansion of binary data is undefined per §Appendix C, and the array branch
|
|
68
|
-
* below already emits one `@filename` part per File.
|
|
69
|
-
*
|
|
70
|
-
* allowReserved only affects percent-encoding, which is a no-op at the HAR layer per
|
|
71
|
-
* OAS 3.1.2 ("`allowReserved` has no effect" for multipart); its presence still opts
|
|
72
|
-
* into this branch per spec.
|
|
49
|
+
* When the encoding sets style/explode/allowReserved, serialize the value RFC6570-style
|
|
50
|
+
* (bracket/exploded notation) and ignore contentType. See `serializeFormPropertyWithEncoding`
|
|
51
|
+
* for the per-style rules; it returns null for primitives, Files, and arrays of Files, which
|
|
52
|
+
* then fall through to the dedicated branches below. HAR represents multipart and urlencoded
|
|
53
|
+
* the same way via `PostData.params`, so the resulting parts work for both.
|
|
73
54
|
*/
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
*/
|
|
81
|
-
const style = partEncoding?.style ?? "form";
|
|
82
|
-
const explode = partEncoding?.explode ?? style === "form";
|
|
83
|
-
if (style === "deepObject") if (Array.isArray(unpacked)) {
|
|
84
|
-
/**
|
|
85
|
-
* OAS 3.1.1 marks deepObject-on-array as n/a; fall back to the form/explode:true
|
|
86
|
-
* shape so the array still reaches the wire instead of being silently dropped.
|
|
87
|
-
*/
|
|
88
|
-
const serialized = serializeFormStyle(unpacked, true);
|
|
89
|
-
if (Array.isArray(serialized)) for (const entry of serialized) params.push({
|
|
90
|
-
name: entry.key || key,
|
|
91
|
-
value: stringifyEntryValue(entry.value)
|
|
92
|
-
});
|
|
93
|
-
else params.push({
|
|
94
|
-
name: key,
|
|
95
|
-
value: String(serialized)
|
|
96
|
-
});
|
|
97
|
-
} else
|
|
98
|
-
/**
|
|
99
|
-
* explode:false with deepObject is undefined per spec; we invoke the serializer
|
|
100
|
-
* either way so authors get useful output instead of nothing.
|
|
101
|
-
*/
|
|
102
|
-
for (const entry of serializeDeepObjectStyle(key, unpacked)) params.push({
|
|
103
|
-
name: entry.key,
|
|
104
|
-
value: String(entry.value)
|
|
105
|
-
});
|
|
106
|
-
else if (style === "spaceDelimited") params.push({
|
|
107
|
-
name: key,
|
|
108
|
-
value: String(serializeSpaceDelimitedStyle(unpacked))
|
|
109
|
-
});
|
|
110
|
-
else if (style === "pipeDelimited") params.push({
|
|
111
|
-
name: key,
|
|
112
|
-
value: String(serializePipeDelimitedStyle(unpacked))
|
|
113
|
-
});
|
|
114
|
-
else {
|
|
115
|
-
const serialized = serializeFormStyle(unpacked, explode);
|
|
116
|
-
if (Array.isArray(serialized)) for (const entry of serialized)
|
|
117
|
-
/**
|
|
118
|
-
* Arrays: entry.key === '' → fall back to the outer name.
|
|
119
|
-
* Objects: entry.key is the inner property name (spec strips the outer name).
|
|
120
|
-
*
|
|
121
|
-
* Nested objects/arrays inside entry.value are spec-undefined (RFC6570 form-style
|
|
122
|
-
* only addresses one level of nesting); JSON-stringify them instead of letting
|
|
123
|
-
* String() emit "[object Object]". The escape hatch for cleaner output is
|
|
124
|
-
* style: deepObject + explode: true.
|
|
125
|
-
*/
|
|
126
|
-
params.push({
|
|
127
|
-
name: entry.key || key,
|
|
128
|
-
value: stringifyEntryValue(entry.value)
|
|
129
|
-
});
|
|
130
|
-
else params.push({
|
|
131
|
-
name: key,
|
|
132
|
-
value: String(serialized)
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
} else if (value instanceof File) {
|
|
55
|
+
const styleParams = parentKey ? null : serializeFormPropertyWithEncoding(key, value, partEncoding);
|
|
56
|
+
if (styleParams) for (const param of styleParams) params.push({
|
|
57
|
+
name: param.key,
|
|
58
|
+
value: param.value
|
|
59
|
+
});
|
|
60
|
+
else if (value instanceof File) {
|
|
136
61
|
/**
|
|
137
62
|
* File values render as `@filename` references, the conventional cURL syntax for an
|
|
138
63
|
* attached file. Picked up by snippet renderers downstream (e.g. `--form 'x=@file.png'`).
|