@scalar/api-client 3.9.0 → 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 +19 -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 +10 -17
- 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 +15 -5
- 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 +23 -6
- 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/RequestBlock.vue.script.js.map +1 -1
- 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/blocks/scalar-auth-selector-block/components/AuthSelector.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 +11 -11
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"find-client.d.ts","sourceRoot":"","sources":["../../../../../src/v2/blocks/operation-code-sample/helpers/find-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAE3E,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,yCAAyC,CAAA;AAExH,eAAO,MAAM,cAAc,eAAe,CAAA;AAE1C,
|
|
1
|
+
{"version":3,"file":"find-client.d.ts","sourceRoot":"","sources":["../../../../../src/v2/blocks/operation-code-sample/helpers/find-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAE3E,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,yCAAyC,CAAA;AAExH,eAAO,MAAM,cAAc,eAAe,CAAA;AAE1C;;;;;;;;;GASG;AACH,MAAM,MAAM,gBAAgB,GAAG,gBAAgB,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAA;AAEvE,oEAAoE;AACpE,eAAO,MAAM,QAAQ,GAAI,IAAI,GAAG,KAAG,EAAE,IAAI,gBAAgB,CAAC,MAAM,CAAmC,CAAA;AAEnG,gGAAgG;AAChG,eAAO,MAAM,gBAAgB,GAAI,IAAI,GAAG,KAAG,EAAE,IAAI,gBACqB,CAAA;AAEtE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,UAAU,GACrB,cAAc,uBAAuB,EAAE,EACvC,WAAW,gBAAgB,GAAG,SAAS,KACtC,YAAY,GAAG,kBAAkB,GAAG,SAmCtC,CAAA"}
|
|
@@ -1,55 +1,48 @@
|
|
|
1
1
|
import { AVAILABLE_CLIENTS } from "@scalar/snippetz";
|
|
2
2
|
//#region src/v2/blocks/operation-code-sample/helpers/find-client.ts
|
|
3
3
|
var DEFAULT_CLIENT = "shell/curl";
|
|
4
|
-
/** Type guard to check if a string is a valid client id */
|
|
4
|
+
/** Type guard to check if a string is a valid built-in client id */
|
|
5
5
|
var isClient = (id) => AVAILABLE_CLIENTS.includes(id);
|
|
6
|
+
/** Type guard for any selection the picker can restore (built-in client or custom sample id) */
|
|
7
|
+
var isSelectedClient = (id) => isClient(id) || typeof id === "string" && id.startsWith("custom/");
|
|
6
8
|
/**
|
|
7
|
-
* Finds and returns the appropriate client option
|
|
9
|
+
* Finds and returns the appropriate client option to select for an operation.
|
|
8
10
|
*
|
|
9
|
-
*
|
|
10
|
-
* request example block. It prioritizes a specific client ID if provided, otherwise
|
|
11
|
-
* falls back to the first available option.
|
|
11
|
+
* Selection rules, given the globally selected client/sample id:
|
|
12
12
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* options: [
|
|
25
|
-
* { id: 'js/fetch', label: 'Fetch API', lang: 'js' },
|
|
26
|
-
* { id: 'js/axios', label: 'Axios', lang: 'js' }
|
|
27
|
-
* ]
|
|
28
|
-
* }
|
|
29
|
-
* ]
|
|
30
|
-
*
|
|
31
|
-
* // Find specific client
|
|
32
|
-
* const client = findClient(clientGroups, 'js/fetch')
|
|
33
|
-
* // Returns: { id: 'js/fetch', label: 'Fetch API', lang: 'js' }
|
|
13
|
+
* 1. A custom sample is selected (`custom/<lang>`): show the matching sample on
|
|
14
|
+
* this operation. If this operation has no sample for that exact language, we
|
|
15
|
+
* keep showing a custom sample (its first one) so the selection stays "global".
|
|
16
|
+
* 2. An explicit built-in client is selected: it wins, even when the operation
|
|
17
|
+
* also has custom samples. This includes the default client (`shell/curl`):
|
|
18
|
+
* a built-in id only reaches us through a real selection (config, persistence,
|
|
19
|
+
* or the picker), never as an implicit default, so a deliberate cURL pick must
|
|
20
|
+
* stick instead of snapping back to an SDK example.
|
|
21
|
+
* 3. Otherwise (nothing selected yet): prefer a custom sample when the operation
|
|
22
|
+
* has one, so custom examples are the default.
|
|
23
|
+
* 4. Fall back to the default built-in client, then the first option.
|
|
34
24
|
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* ```
|
|
25
|
+
* @param clientGroups - Array of client option groups, each containing a label and array of client options
|
|
26
|
+
* @param clientId - Optional selection to restore (e.g. 'js/fetch' or 'custom/python')
|
|
27
|
+
* @returns The selected client option, or undefined when there is nothing to select
|
|
39
28
|
*/
|
|
40
29
|
var findClient = (clientGroups, clientId) => {
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
30
|
+
const findById = (id) => {
|
|
31
|
+
for (const group of clientGroups) {
|
|
32
|
+
const option = group.options.find((option) => option.id === id);
|
|
33
|
+
if (option) return option;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
const firstCustom = clientGroups.find((group) => group.key === "custom")?.options[0];
|
|
37
|
+
if (clientId?.startsWith("custom")) return findById(clientId) ?? firstCustom ?? findById("shell/curl") ?? clientGroups[0]?.options[0];
|
|
38
|
+
if (clientId) {
|
|
39
|
+
const option = findById(clientId);
|
|
48
40
|
if (option) return option;
|
|
49
41
|
}
|
|
50
|
-
return
|
|
42
|
+
if (firstCustom) return firstCustom;
|
|
43
|
+
return findById("shell/curl") ?? clientGroups[0]?.options[0];
|
|
51
44
|
};
|
|
52
45
|
//#endregion
|
|
53
|
-
export { DEFAULT_CLIENT, findClient, isClient };
|
|
46
|
+
export { DEFAULT_CLIENT, findClient, isClient, isSelectedClient };
|
|
54
47
|
|
|
55
48
|
//# sourceMappingURL=find-client.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"find-client.js","names":[],"sources":["../../../../../src/v2/blocks/operation-code-sample/helpers/find-client.ts"],"sourcesContent":["import { AVAILABLE_CLIENTS, type AvailableClients } from '@scalar/snippetz'\n\nimport type { ClientOption, CustomClientOption, CustomClientOptionGroup } from '@/v2/blocks/operation-code-sample/types'\n\nexport const DEFAULT_CLIENT = 'shell/curl'\n\n/** Type guard to check if a string is a valid client id */\nexport const isClient = (id: any): id is AvailableClients[number] => AVAILABLE_CLIENTS.includes(id)\n\n
|
|
1
|
+
{"version":3,"file":"find-client.js","names":[],"sources":["../../../../../src/v2/blocks/operation-code-sample/helpers/find-client.ts"],"sourcesContent":["import { AVAILABLE_CLIENTS, type AvailableClients } from '@scalar/snippetz'\n\nimport type { ClientOption, CustomClientOption, CustomClientOptionGroup } from '@/v2/blocks/operation-code-sample/types'\n\nexport const DEFAULT_CLIENT = 'shell/curl'\n\n/**\n * A selection the code sample picker understands: either a built-in client id\n * (e.g. `js/fetch`) or a custom sample id (e.g. `custom/python`).\n *\n * The custom part is typed as `string & {}` rather than the `custom/${string}`\n * template literal: unioning that template literal with the (very large) built-in\n * client-id union trips TypeScript's \"union too complex\" limit inside Vue's\n * `defineProps` macro. `string & {}` keeps editor hints for the known client ids\n * without expanding the union.\n */\nexport type SelectedClientId = AvailableClients[number] | (string & {})\n\n/** Type guard to check if a string is a valid built-in client id */\nexport const isClient = (id: any): id is AvailableClients[number] => AVAILABLE_CLIENTS.includes(id)\n\n/** Type guard for any selection the picker can restore (built-in client or custom sample id) */\nexport const isSelectedClient = (id: any): id is SelectedClientId =>\n isClient(id) || (typeof id === 'string' && id.startsWith('custom/'))\n\n/**\n * Finds and returns the appropriate client option to select for an operation.\n *\n * Selection rules, given the globally selected client/sample id:\n *\n * 1. A custom sample is selected (`custom/<lang>`): show the matching sample on\n * this operation. If this operation has no sample for that exact language, we\n * keep showing a custom sample (its first one) so the selection stays \"global\".\n * 2. An explicit built-in client is selected: it wins, even when the operation\n * also has custom samples. This includes the default client (`shell/curl`):\n * a built-in id only reaches us through a real selection (config, persistence,\n * or the picker), never as an implicit default, so a deliberate cURL pick must\n * stick instead of snapping back to an SDK example.\n * 3. Otherwise (nothing selected yet): prefer a custom sample when the operation\n * has one, so custom examples are the default.\n * 4. Fall back to the default built-in client, then the first option.\n *\n * @param clientGroups - Array of client option groups, each containing a label and array of client options\n * @param clientId - Optional selection to restore (e.g. 'js/fetch' or 'custom/python')\n * @returns The selected client option, or undefined when there is nothing to select\n */\nexport const findClient = (\n clientGroups: CustomClientOptionGroup[],\n clientId?: SelectedClientId | undefined,\n): ClientOption | CustomClientOption | undefined => {\n const findById = (id: string) => {\n for (const group of clientGroups) {\n const option = group.options.find((option) => option.id === id)\n if (option) {\n return option\n }\n }\n return undefined\n }\n\n const firstCustom = clientGroups.find((group) => group.key === 'custom')?.options[0]\n\n // 1. A custom sample is selected: match the language, otherwise stay on a custom sample\n if (clientId?.startsWith('custom')) {\n return findById(clientId) ?? firstCustom ?? findById(DEFAULT_CLIENT) ?? clientGroups[0]?.options[0]\n }\n\n // 2. An explicit built-in client wins, even when custom samples exist. A built-in\n // id (including the default `shell/curl`) only reaches us through a real\n // selection, so it must stick rather than snap back to a custom sample.\n if (clientId) {\n const option = findById(clientId)\n if (option) {\n return option\n }\n }\n\n // 3. Nothing selected yet: prefer a custom sample when the operation has one\n if (firstCustom) {\n return firstCustom\n }\n\n // 4. Otherwise fall back to the default built-in client, then the first option\n return findById(DEFAULT_CLIENT) ?? clientGroups[0]?.options[0]\n}\n"],"mappings":";;AAIA,IAAa,iBAAiB;;AAe9B,IAAa,YAAY,OAA4C,kBAAkB,SAAS,GAAG;;AAGnG,IAAa,oBAAoB,OAC/B,SAAS,GAAG,IAAK,OAAO,OAAO,YAAY,GAAG,WAAW,UAAU;;;;;;;;;;;;;;;;;;;;;;AAuBrE,IAAa,cACX,cACA,aACkD;CAClD,MAAM,YAAY,OAAe;AAC/B,OAAK,MAAM,SAAS,cAAc;GAChC,MAAM,SAAS,MAAM,QAAQ,MAAM,WAAW,OAAO,OAAO,GAAG;AAC/D,OAAI,OACF,QAAO;;;CAMb,MAAM,cAAc,aAAa,MAAM,UAAU,MAAM,QAAQ,SAAS,EAAE,QAAQ;AAGlF,KAAI,UAAU,WAAW,SAAS,CAChC,QAAO,SAAS,SAAS,IAAI,eAAe,SAAA,aAAwB,IAAI,aAAa,IAAI,QAAQ;AAMnG,KAAI,UAAU;EACZ,MAAM,SAAS,SAAS,SAAS;AACjC,MAAI,OACF,QAAO;;AAKX,KAAI,YACF,QAAO;AAIT,QAAO,SAAA,aAAwB,IAAI,aAAa,IAAI,QAAQ"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turn a free-form language identifier into a display label for the code sample picker.
|
|
3
|
+
*
|
|
4
|
+
* @param lang - The language identifier from a custom code sample (e.g. `typescript`)
|
|
5
|
+
* @returns A properly cased label (e.g. `TypeScript`), or `undefined` when no language is given
|
|
6
|
+
*/
|
|
7
|
+
export declare const formatLanguage: (lang?: string) => string | undefined;
|
|
8
|
+
//# sourceMappingURL=format-language.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format-language.d.ts","sourceRoot":"","sources":["../../../../../src/v2/blocks/operation-code-sample/helpers/format-language.ts"],"names":[],"mappings":"AAyDA;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GAAI,OAAO,MAAM,KAAG,MAAM,GAAG,SAMvD,CAAA"}
|
|
@@ -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"}
|
|
@@ -1,15 +1,25 @@
|
|
|
1
1
|
import { type AvailableClients } from '@scalar/snippetz';
|
|
2
|
+
import type { XCodeSample } from '@scalar/workspace-store/schemas/extensions/operation';
|
|
2
3
|
import type { ClientOptionGroup } from '../../../../v2/blocks/operation-code-sample/types';
|
|
3
4
|
/** Type of custom code sample IDs */
|
|
4
5
|
export type CustomCodeSampleId = `custom/${string}`;
|
|
5
6
|
/**
|
|
6
|
-
*
|
|
7
|
+
* Build stable, language-keyed ids for an operation's custom code samples.
|
|
7
8
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
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
|
|
11
21
|
*/
|
|
12
|
-
export declare const
|
|
22
|
+
export declare const getCustomClientIds: (samples: XCodeSample[]) => CustomCodeSampleId[];
|
|
13
23
|
/**
|
|
14
24
|
* Generate client options for the request example block by filtering by allowed clients
|
|
15
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;
|
|
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"}
|
|
@@ -2,13 +2,30 @@ 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
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Build stable, language-keyed ids for an operation's custom code samples.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
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
|
|
10
19
|
*/
|
|
11
|
-
var
|
|
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
|
+
};
|
|
12
29
|
/**
|
|
13
30
|
* Generate client options for the request example block by filtering by allowed clients
|
|
14
31
|
*
|
|
@@ -41,6 +58,6 @@ var generateClientOptions = (allowedClients = AVAILABLE_CLIENTS) => {
|
|
|
41
58
|
});
|
|
42
59
|
};
|
|
43
60
|
//#endregion
|
|
44
|
-
export { generateClientOptions,
|
|
61
|
+
export { generateClientOptions, getCustomClientIds };
|
|
45
62
|
|
|
46
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 { 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 *
|
|
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"}
|