@scalar/blocks 0.5.1 → 0.5.3
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 +25 -0
- package/dist/code-example/components/CodeExample.vue.d.ts +2 -0
- package/dist/code-example/components/CodeExample.vue.d.ts.map +1 -1
- package/dist/code-example/components/CodeExample.vue.js +1 -1
- package/dist/code-example/components/CodeExample.vue.js.map +1 -1
- package/dist/code-example/components/CodeExample.vue.script.js +71 -68
- package/dist/code-example/components/CodeExample.vue.script.js.map +1 -1
- package/dist/code-example/helpers/generate-client-options.d.ts.map +1 -1
- package/dist/code-example/helpers/generate-client-options.js.map +1 -1
- package/dist/code-example/helpers/get-clients.d.ts.map +1 -1
- package/dist/code-example/helpers/get-clients.js.map +1 -1
- package/dist/code-example/helpers/operation-to-har/process-body.d.ts.map +1 -1
- package/dist/code-example/helpers/operation-to-har/process-body.js +42 -42
- package/dist/code-example/helpers/operation-to-har/process-body.js.map +1 -1
- package/dist/code-example/helpers/operation-to-har/process-parameters.d.ts.map +1 -1
- package/dist/code-example/helpers/operation-to-har/process-parameters.js +63 -62
- package/dist/code-example/helpers/operation-to-har/process-parameters.js.map +1 -1
- package/dist/code-example/mount.d.ts.map +1 -1
- package/dist/code-example/mount.js +1 -1
- package/dist/code-example/mount.js.map +1 -1
- package/dist/constants.js +1 -1
- package/dist/schema/Schema.vue.d.ts.map +1 -1
- package/dist/schema/Schema.vue.js +1 -1
- package/dist/schema/Schema.vue.js.map +1 -1
- package/dist/schema/Schema.vue.script.js +122 -116
- package/dist/schema/Schema.vue.script.js.map +1 -1
- package/dist/schema/SchemaComposition.vue.d.ts.map +1 -1
- package/dist/schema/SchemaComposition.vue.js +1 -1
- package/dist/schema/SchemaComposition.vue.js.map +1 -1
- package/dist/schema/SchemaComposition.vue.script.js +110 -106
- package/dist/schema/SchemaComposition.vue.script.js.map +1 -1
- package/dist/schema/SchemaEnumPropertyItem.vue.js.map +1 -1
- package/dist/schema/SchemaEnumPropertyItem.vue.script.js +2 -2
- package/dist/schema/SchemaEnumPropertyItem.vue.script.js.map +1 -1
- package/dist/schema/SchemaObjectProperties.vue.js.map +1 -1
- package/dist/schema/SchemaObjectProperties.vue.script.js +1 -1
- package/dist/schema/SchemaObjectProperties.vue.script.js.map +1 -1
- package/dist/schema/SchemaProperty.vue.d.ts +1 -1
- package/dist/schema/SchemaProperty.vue.d.ts.map +1 -1
- package/dist/schema/SchemaProperty.vue.js +1 -1
- package/dist/schema/SchemaProperty.vue.js.map +1 -1
- package/dist/schema/SchemaProperty.vue.script.js +179 -164
- package/dist/schema/SchemaProperty.vue.script.js.map +1 -1
- package/dist/schema/SchemaPropertyHeading.vue.d.ts +5 -3
- package/dist/schema/SchemaPropertyHeading.vue.d.ts.map +1 -1
- package/dist/schema/SchemaPropertyHeading.vue.js +1 -1
- package/dist/schema/SchemaPropertyHeading.vue.js.map +1 -1
- package/dist/schema/SchemaPropertyHeading.vue.script.js +122 -117
- package/dist/schema/SchemaPropertyHeading.vue.script.js.map +1 -1
- package/dist/schema/SchemaPropertyPattern.vue.js +1 -1
- package/dist/schema/SchemaPropertyPattern.vue.js.map +1 -1
- package/dist/schema/SchemaPropertyPattern.vue.script.js +1 -1
- package/dist/schema/SchemaPropertyPattern.vue.script.js.map +1 -1
- package/dist/schema/discriminator-metadata.d.ts +13 -0
- package/dist/schema/discriminator-metadata.d.ts.map +1 -0
- package/dist/schema/discriminator-metadata.js +6 -0
- package/dist/schema/discriminator-metadata.js.map +1 -0
- package/dist/schema/helpers/get-compositions-to-render.d.ts +3 -1
- package/dist/schema/helpers/get-compositions-to-render.d.ts.map +1 -1
- package/dist/schema/helpers/get-compositions-to-render.js +25 -24
- package/dist/schema/helpers/get-compositions-to-render.js.map +1 -1
- package/dist/schema/helpers/get-property-description.d.ts +6 -3
- package/dist/schema/helpers/get-property-description.d.ts.map +1 -1
- package/dist/schema/helpers/get-property-description.js +10 -10
- package/dist/schema/helpers/get-property-description.js.map +1 -1
- package/dist/schema/helpers/has-complex-array-items.d.ts.map +1 -1
- package/dist/schema/helpers/has-complex-array-items.js +6 -2
- package/dist/schema/helpers/has-complex-array-items.js.map +1 -1
- package/dist/schema/helpers/merge-all-of-schemas.d.ts.map +1 -1
- package/dist/schema/helpers/merge-all-of-schemas.js +2 -2
- package/dist/schema/helpers/merge-all-of-schemas.js.map +1 -1
- package/dist/schema/helpers/optimize-value-for-display.d.ts.map +1 -1
- package/dist/schema/helpers/optimize-value-for-display.js +34 -33
- package/dist/schema/helpers/optimize-value-for-display.js.map +1 -1
- package/dist/schema/helpers/partition-all-of-compositions.d.ts.map +1 -1
- package/dist/schema/helpers/partition-all-of-compositions.js +39 -27
- package/dist/schema/helpers/partition-all-of-compositions.js.map +1 -1
- package/dist/schema/helpers/schema-name.js +1 -1
- package/dist/schema/helpers/schema-name.js.map +1 -1
- package/dist/schema/index.d.ts +2 -0
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +13 -11
- package/dist/schema/localization/index.d.ts +11 -1
- package/dist/schema/localization/index.d.ts.map +1 -1
- package/dist/schema/localization/locales/ar.d.ts +10 -0
- package/dist/schema/localization/locales/ar.d.ts.map +1 -1
- package/dist/schema/localization/locales/ar.js +11 -1
- package/dist/schema/localization/locales/ar.js.map +1 -1
- package/dist/schema/localization/locales/de.d.ts +10 -0
- package/dist/schema/localization/locales/de.d.ts.map +1 -1
- package/dist/schema/localization/locales/de.js +11 -1
- package/dist/schema/localization/locales/de.js.map +1 -1
- package/dist/schema/localization/locales/en.d.ts +10 -0
- package/dist/schema/localization/locales/en.d.ts.map +1 -1
- package/dist/schema/localization/locales/en.js +11 -1
- package/dist/schema/localization/locales/en.js.map +1 -1
- package/dist/schema/localization/locales/es.d.ts +10 -0
- package/dist/schema/localization/locales/es.d.ts.map +1 -1
- package/dist/schema/localization/locales/es.js +11 -1
- package/dist/schema/localization/locales/es.js.map +1 -1
- package/dist/schema/localization/locales/fr.d.ts +10 -0
- package/dist/schema/localization/locales/fr.d.ts.map +1 -1
- package/dist/schema/localization/locales/fr.js +11 -1
- package/dist/schema/localization/locales/fr.js.map +1 -1
- package/dist/schema/localization/locales/pt.d.ts +10 -0
- package/dist/schema/localization/locales/pt.d.ts.map +1 -1
- package/dist/schema/localization/locales/pt.js +11 -1
- package/dist/schema/localization/locales/pt.js.map +1 -1
- package/dist/schema/localization/locales/ru.d.ts +10 -0
- package/dist/schema/localization/locales/ru.d.ts.map +1 -1
- package/dist/schema/localization/locales/ru.js +11 -1
- package/dist/schema/localization/locales/ru.js.map +1 -1
- package/dist/schema/localization/locales/zh-cn.d.ts +10 -0
- package/dist/schema/localization/locales/zh-cn.d.ts.map +1 -1
- package/dist/schema/localization/locales/zh-cn.js +11 -1
- package/dist/schema/localization/locales/zh-cn.js.map +1 -1
- package/dist/schema/localization/locales/zh-tw.d.ts +69 -0
- package/dist/schema/localization/locales/zh-tw.d.ts.map +1 -0
- package/dist/schema/localization/locales/zh-tw.js +70 -0
- package/dist/schema/localization/locales/zh-tw.js.map +1 -0
- package/dist/schema/localization/translations.d.ts +147 -0
- package/dist/schema/localization/translations.d.ts.map +1 -1
- package/dist/schema/localization/translations.js +5 -3
- package/dist/schema/localization/translations.js.map +1 -1
- package/dist/schema/types.d.ts +2 -0
- package/dist/schema/types.d.ts.map +1 -1
- package/dist/shared/ExternalDocs.vue.d.ts +9 -0
- package/dist/shared/ExternalDocs.vue.d.ts.map +1 -0
- package/dist/shared/ExternalDocs.vue.js +7 -0
- package/dist/shared/ExternalDocs.vue.js.map +1 -0
- package/dist/shared/ExternalDocs.vue.script.js +46 -0
- package/dist/shared/ExternalDocs.vue.script.js.map +1 -0
- package/dist/shared/index.d.ts +1 -0
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index.js +4 -3
- package/dist/style.css +63 -19
- package/dist/styles/schema-tree.css +3 -1
- package/dist/vue-styles.css +1 -1
- package/package.json +10 -10
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-client-options.d.ts","sourceRoot":"","sources":["../../../src/code-example/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,UAAU,CAAA;AAEjD,qCAAqC;AACrC,MAAM,MAAM,kBAAkB,GAAG,UAAU,MAAM,EAAE,CAAA;AAEnD;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,kBAAkB,GAAI,SAAS,WAAW,EAAE,KAAG,kBAAkB,
|
|
1
|
+
{"version":3,"file":"generate-client-options.d.ts","sourceRoot":"","sources":["../../../src/code-example/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,UAAU,CAAA;AAEjD,qCAAqC;AACrC,MAAM,MAAM,kBAAkB,GAAG,UAAU,MAAM,EAAE,CAAA;AAEnD;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,kBAAkB,GAAI,SAAS,WAAW,EAAE,KAAG,kBAAkB,EAsB7E,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,GAAI,iBAAgB,gBAAoC,KAAG,iBAAiB,EAuC7G,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-client-options.js","names":[],"sources":["../../../src/code-example/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 '../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 * Linked request examples with the same language and label share an id.\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 const linkedGroups = new Map<string, CustomCodeSampleId>()\n\n return samples.map((sample): CustomCodeSampleId => {\n const lang = (sample.lang || 'plaintext').toLowerCase()\n const group = JSON.stringify([lang, sample.label ?? ''])\n const existing = sample.example !== undefined ? linkedGroups.get(group) : undefined\n if (existing) return existing\n\n const seen = countByLang.get(lang) ?? 0\n countByLang.set(lang, seen + 1)\n\n const id: CustomCodeSampleId = seen === 0 ? `custom/${lang}` : `custom/${lang}/${seen}`\n // Named request examples share one language option; legacy samples remain separate.\n if (sample.example !== undefined) linkedGroups.set(group, id)\n return id\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: AvailableClients[number] = `${group.key}/${plugin.client}`\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":";;;AA0BA,IAAa,KAAsB,MAAiD;CAClF,IAAM,oBAAc,IAAI,IAAoB,GACtC,oBAAe,IAAI,IAAgC;CAEzD,OAAO,EAAQ,KAAK,MAA+B;EACjD,IAAM,KAAQ,EAAO,QAAQ,YAAA,CAAa,YAAY,GAChD,IAAQ,KAAK,UAAU,CAAC,GAAM,EAAO,SAAS,EAAE,CAAC,GACjD,IAAW,EAAO,YAAY,KAAA,IAAsC,KAAA,IAA1B,EAAa,IAAI,CAAK;EACtE,IAAI,
|
|
1
|
+
{"version":3,"file":"generate-client-options.js","names":[],"sources":["../../../src/code-example/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 '../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 * Linked request examples with the same language and label share an id.\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 const linkedGroups = new Map<string, CustomCodeSampleId>()\n\n return samples.map((sample): CustomCodeSampleId => {\n const lang = (sample.lang || 'plaintext').toLowerCase()\n const group = JSON.stringify([lang, sample.label ?? ''])\n const existing = sample.example !== undefined ? linkedGroups.get(group) : undefined\n if (existing) {\n return existing\n }\n\n const seen = countByLang.get(lang) ?? 0\n countByLang.set(lang, seen + 1)\n\n const id: CustomCodeSampleId = seen === 0 ? `custom/${lang}` : `custom/${lang}/${seen}`\n // Named request examples share one language option; legacy samples remain separate.\n if (sample.example !== undefined) {\n linkedGroups.set(group, id)\n }\n return id\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: AvailableClients[number] = `${group.key}/${plugin.client}`\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":";;;AA0BA,IAAa,KAAsB,MAAiD;CAClF,IAAM,oBAAc,IAAI,IAAoB,GACtC,oBAAe,IAAI,IAAgC;CAEzD,OAAO,EAAQ,KAAK,MAA+B;EACjD,IAAM,KAAQ,EAAO,QAAQ,YAAA,CAAa,YAAY,GAChD,IAAQ,KAAK,UAAU,CAAC,GAAM,EAAO,SAAS,EAAE,CAAC,GACjD,IAAW,EAAO,YAAY,KAAA,IAAsC,KAAA,IAA1B,EAAa,IAAI,CAAK;EACtE,IAAI,GACF,OAAO;EAGT,IAAM,IAAO,EAAY,IAAI,CAAI,KAAK;EACtC,EAAY,IAAI,GAAM,IAAO,CAAC;EAE9B,IAAM,IAAyB,MAAS,IAAI,UAAU,MAAS,UAAU,EAAK,GAAG;EAKjF,OAHI,EAAO,YAAY,KAAA,KACrB,EAAa,IAAI,GAAO,CAAE,GAErB;CACT,CAAC;AACH,GAQa,KAAyB,IAAmC,MAA2C;CAElH,IAAM,IAAoB,IAAI,IAAI,CAAc;CAoChD,OAlCgB,EAAS,CAAC,CACvB,QAAQ,CAAC,CACT,SAAS,MAAU;EAClB,IAAM,IAAU,EAAM,QAAQ,SAAS,MAAW;GAChD,IAAM,IAA+B,GAAG,EAAM,IAAI,GAAG,EAAO;GAO5D,OAJK,EAAkB,IAAI,CAAE,IAItB;IACL;IACA,MAAM,EAAO,WAAW,SAAU,SAAmB,EAAM;IAC3D,OAAO,GAAG,EAAW,EAAM,KAAK,EAAE,GAAG,EAAO;IAC5C,OAAO,EAAO;IACd,WAAW,EAAM;IACjB,aAAa,EAAM;IACnB,WAAW,EAAO;GACpB,IAXS,CAAC;EAYZ,CAAC;EAOD,OAJI,EAAQ,WAAW,IACd,CAAC,IAGH;GACL,OAAO,EAAM;GACb,KAAK,EAAM;GACX;EACF;CACF,CAEK;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-clients.d.ts","sourceRoot":"","sources":["../../../src/code-example/helpers/get-clients.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sDAAsD,CAAA;AAEvF,OAAO,KAAK,EAAE,iBAAiB,EAAsB,uBAAuB,EAAE,MAAM,UAAU,CAAA;AAK9F;;;;;;;GAOG;AACH,eAAO,MAAM,UAAU,GACrB,mBAAmB,WAAW,EAAE,EAChC,eAAe,iBAAiB,EAAE,EAClC,QAAO,MAAkC,KACxC,uBAAuB,
|
|
1
|
+
{"version":3,"file":"get-clients.d.ts","sourceRoot":"","sources":["../../../src/code-example/helpers/get-clients.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sDAAsD,CAAA;AAEvF,OAAO,KAAK,EAAE,iBAAiB,EAAsB,uBAAuB,EAAE,MAAM,UAAU,CAAA;AAK9F;;;;;;;GAOG;AACH,eAAO,MAAM,UAAU,GACrB,mBAAmB,WAAW,EAAE,EAChC,eAAe,iBAAiB,EAAE,EAClC,QAAO,MAAkC,KACxC,uBAAuB,EAkCzB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-clients.js","names":[],"sources":["../../../src/code-example/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, CustomClientOptionGroup } from '../types'\nimport { formatLanguage } from './format-language'\nimport { getCustomClientIds } from './generate-client-options'\nimport { CODE_EXAMPLES_GROUP_LABEL } from './get-custom-code-samples'\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.flatMap((sample, index) => {\n const id = ids[index] ?? `custom/${index}`\n if (ids.indexOf(id) !== index) return []\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":";;;;AAgBA,IAAa,KACX,GACA,GACA,IAAgB,MACc;CAE9B,IAAI,EAAkB,QAAQ;EAE5B,IAAM,IAAM,EAAmB,CAAiB;
|
|
1
|
+
{"version":3,"file":"get-clients.js","names":[],"sources":["../../../src/code-example/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, CustomClientOptionGroup } from '../types'\nimport { formatLanguage } from './format-language'\nimport { getCustomClientIds } from './generate-client-options'\nimport { CODE_EXAMPLES_GROUP_LABEL } from './get-custom-code-samples'\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.flatMap((sample, index) => {\n const id = ids[index] ?? `custom/${index}`\n if (ids.indexOf(id) !== index) {\n return []\n }\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":";;;;AAgBA,IAAa,KACX,GACA,GACA,IAAgB,MACc;CAE9B,IAAI,EAAkB,QAAQ;EAE5B,IAAM,IAAM,EAAmB,CAAiB;EAmBhD,OAAO,CACL;GACE;GACA,KAAK;GACL,SArBkB,EAAkB,SAAS,GAAQ,MAAU;IACjE,IAAM,IAAK,EAAI,MAAU,UAAU;IACnC,IAAI,EAAI,QAAQ,CAAE,MAAM,GACtB,OAAO,CAAC;IAEV,IAAM,IAAQ,EAAO,SAAS,EAAe,EAAO,IAAI,KAAK;IAG7D,OAAO;KACL;KACA,MAJY,EAAO,QAAqB;KAKxC,OAAO;KACP;KACA,WAAW;IACb;GACF,CAMa;EACX,GACA,GAAG,CACL;CACF;CAEA,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"process-body.d.ts","sourceRoot":"","sources":["../../../../src/code-example/helpers/operation-to-har/process-body.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAEV,iBAAiB,EAElB,MAAM,8DAA8D,CAAA;AACrE,OAAO,KAAK,EAAS,QAAQ,EAAE,MAAM,YAAY,CAAA;AAEjD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAE7D,KAAK,gBAAgB,GAAG,IAAI,CAC1B,mBAAmB,EACnB,aAAa,GAAG,SAAS,GAAG,iCAAiC,GAAG,gBAAgB,CACjF,GAAG;IACF,WAAW,EAAE,iBAAiB,CAAA;CAC/B,CAAA;AA0LD;;;GAGG;AACH,eAAO,MAAM,WAAW,GAAI,yFAMzB,gBAAgB,KAAG,QAAQ,GAAG,
|
|
1
|
+
{"version":3,"file":"process-body.d.ts","sourceRoot":"","sources":["../../../../src/code-example/helpers/operation-to-har/process-body.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAEV,iBAAiB,EAElB,MAAM,8DAA8D,CAAA;AACrE,OAAO,KAAK,EAAS,QAAQ,EAAE,MAAM,YAAY,CAAA;AAEjD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAE7D,KAAK,gBAAgB,GAAG,IAAI,CAC1B,mBAAmB,EACnB,aAAa,GAAG,SAAS,GAAG,iCAAiC,GAAG,gBAAgB,CACjF,GAAG;IACF,WAAW,EAAE,iBAAiB,CAAA;CAC/B,CAAA;AA0LD;;;GAGG;AACH,eAAO,MAAM,WAAW,GAAI,yFAMzB,gBAAgB,KAAG,QAAQ,GAAG,SAmIhC,CAAA"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
1
|
+
import { getResolvedRef as e, mergeSiblingReferences as t } from "@scalar/workspace-store/helpers/get-resolved-ref";
|
|
2
|
+
import { buildRequestBody as n, coerceLeafValueToSchemaType as r, getExample as i, getExampleFromBody as a, getExampleFromSchema as o, needsMultipartEncoding as s, resolveLeafSchema as c, serializeFormPropertyWithEncoding as l, serializeMultipartArray as u, serializeMultipartBody as d } from "@scalar/workspace-store/request-example";
|
|
3
|
+
import { isXmlMediaType as f } from "@scalar/helpers/http/is-xml-media-type";
|
|
4
|
+
import { getExampleValue as p, getExplicitExampleText as m } from "@scalar/workspace-store/helpers/get-example-value";
|
|
5
|
+
import { serializeStreamExample as h } from "@scalar/workspace-store/helpers/serialize-stream-example";
|
|
6
|
+
import { snapshotSchema as g } from "@scalar/workspace-store/helpers/snapshot-schema";
|
|
7
7
|
import { unpackProxyObject as _ } from "@scalar/workspace-store/helpers/unpack-proxy";
|
|
8
8
|
//#region src/code-example/helpers/operation-to-har/process-body.ts
|
|
9
9
|
var v = (e, t, n) => ({
|
|
@@ -11,13 +11,13 @@ var v = (e, t, n) => ({
|
|
|
11
11
|
value: `@${t}`,
|
|
12
12
|
fileName: t,
|
|
13
13
|
...n ? { contentType: n } : {}
|
|
14
|
-
}), y = (e) => !!e && "type" in e && e.type === "string" && "format" in e && e.format === "binary", b = (e, t) => typeof e == "string" && e.startsWith("@") && y(t) ? e.slice(1) : void 0, x = (e, t, n,
|
|
14
|
+
}), y = (e) => !!e && "type" in e && e.type === "string" && "format" in e && e.format === "binary", b = (e, t) => typeof e == "string" && e.startsWith("@") && y(t) ? e.slice(1) : void 0, x = (e, t, n, i = !1, a) => {
|
|
15
15
|
let o = [], s = Array.isArray(e) ? e.filter((e) => !e.isDisabled).map((e) => [String(e.name), e.value]) : Object.entries(e);
|
|
16
|
-
for (let [
|
|
16
|
+
for (let [d, f] of s) {
|
|
17
17
|
if (f == null) continue;
|
|
18
|
-
let s = n ? void 0 : t?.[
|
|
19
|
-
if (
|
|
20
|
-
let t = Array.isArray(e) ?
|
|
18
|
+
let s = n ? void 0 : t?.[d];
|
|
19
|
+
if (i && !n) {
|
|
20
|
+
let t = Array.isArray(e) ? r(f, c(a, [d])) : f, n = u(d, Array.isArray(t) ? t : f, s);
|
|
21
21
|
if (n) {
|
|
22
22
|
for (let e of n) {
|
|
23
23
|
if (e.value instanceof File) {
|
|
@@ -33,54 +33,54 @@ var v = (e, t, n) => ({
|
|
|
33
33
|
continue;
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
let p = s && (s.style !== void 0 || s.explode !== void 0 || s.allowReserved !== void 0), m = p || !
|
|
36
|
+
let p = s && (s.style !== void 0 || s.explode !== void 0 || s.allowReserved !== void 0), m = p || !i ? void 0 : s?.contentType, h = i && !n ? b(f, c(a, [d])) : void 0, g = n ? null : l(d, f, s);
|
|
37
37
|
if (g) for (let e of g) o.push({
|
|
38
38
|
name: e.key,
|
|
39
39
|
value: e.value
|
|
40
40
|
});
|
|
41
41
|
else if (f instanceof File) {
|
|
42
42
|
let e = _(f);
|
|
43
|
-
o.push(v(
|
|
44
|
-
} else if (h !== void 0) o.push(v(
|
|
43
|
+
o.push(v(d, e.name, m ?? (i ? e.type : void 0)));
|
|
44
|
+
} else if (h !== void 0) o.push(v(d, h, m));
|
|
45
45
|
else if (m && typeof f == "object") o.push({
|
|
46
|
-
name:
|
|
46
|
+
name: d,
|
|
47
47
|
value: JSON.stringify(_(f)),
|
|
48
48
|
contentType: m
|
|
49
49
|
});
|
|
50
|
-
else if (
|
|
51
|
-
name:
|
|
50
|
+
else if (i && !n && !p && typeof f == "object" && !Array.isArray(f)) o.push({
|
|
51
|
+
name: d,
|
|
52
52
|
value: JSON.stringify(_(f)),
|
|
53
53
|
contentType: "application/json"
|
|
54
54
|
});
|
|
55
55
|
else if (Array.isArray(f)) for (let e of f) if (e instanceof File) {
|
|
56
56
|
let t = _(e);
|
|
57
|
-
o.push(v(
|
|
57
|
+
o.push(v(d, t.name, i ? t.type : void 0));
|
|
58
58
|
} else o.push({
|
|
59
|
-
name:
|
|
59
|
+
name: d,
|
|
60
60
|
value: String(e)
|
|
61
61
|
});
|
|
62
62
|
else if (typeof f == "object") {
|
|
63
|
-
let e = x(f, void 0,
|
|
63
|
+
let e = x(f, void 0, d);
|
|
64
64
|
for (let t of e) o.push({
|
|
65
|
-
name: `${
|
|
65
|
+
name: `${d}.${t.name}`,
|
|
66
66
|
value: t.value
|
|
67
67
|
});
|
|
68
68
|
} else o.push({
|
|
69
|
-
name:
|
|
69
|
+
name: d,
|
|
70
70
|
value: String(f),
|
|
71
71
|
...m ? { contentType: m } : {}
|
|
72
72
|
});
|
|
73
73
|
}
|
|
74
74
|
return o;
|
|
75
|
-
}, S = ({ requestBody:
|
|
76
|
-
let y =
|
|
77
|
-
if (w &&
|
|
78
|
-
let e =
|
|
79
|
-
...
|
|
75
|
+
}, S = ({ requestBody: r, contentType: c, example: l, openapiVersion: u, requestBodyCompositionSelection: v }) => {
|
|
76
|
+
let y = c || Object.keys(r.content)[0] || "", b = y === "other" ? "" : y, S = (e) => `@${_(e).name || "filename"}`, C = r.content[y]?.encoding, w = r.content[y];
|
|
77
|
+
if (w && s(y, w)) {
|
|
78
|
+
let e = l ?? Object.keys(w.examples ?? {})[0] ?? "default", t = n({
|
|
79
|
+
...r,
|
|
80
80
|
"x-scalar-selected-content-type": { [e]: y }
|
|
81
81
|
}, e, v);
|
|
82
82
|
if (t?.mode === "multipart") {
|
|
83
|
-
let e =
|
|
83
|
+
let e = d(t.value, t.contentType);
|
|
84
84
|
return {
|
|
85
85
|
mimeType: e.contentType,
|
|
86
86
|
text: e.chunks.map((e) => e instanceof File ? S(e) : e instanceof Blob ? "BINARY" : String(e)).join("")
|
|
@@ -88,45 +88,45 @@ var v = (e, t, n) => ({
|
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
let T = y === "multipart/form-data" || y === "application/x-www-form-urlencoded";
|
|
91
|
-
if (
|
|
92
|
-
let e =
|
|
91
|
+
if (f(y)) {
|
|
92
|
+
let e = a(r, y, l ?? "", v, u);
|
|
93
93
|
return e ? {
|
|
94
94
|
mimeType: b,
|
|
95
95
|
text: e.value
|
|
96
96
|
} : void 0;
|
|
97
97
|
}
|
|
98
|
-
let E =
|
|
98
|
+
let E = p(i(r, l, c)), D = m(E, y);
|
|
99
99
|
if (D !== void 0) return {
|
|
100
100
|
mimeType: b,
|
|
101
101
|
text: D
|
|
102
102
|
};
|
|
103
103
|
let O = E?.value;
|
|
104
104
|
if (O !== void 0) {
|
|
105
|
-
let
|
|
106
|
-
return T && typeof
|
|
105
|
+
let n = typeof O == "object" && O ? _(O) : O;
|
|
106
|
+
return T && typeof n == "object" && n ? {
|
|
107
107
|
mimeType: b,
|
|
108
|
-
params: x(
|
|
109
|
-
} :
|
|
108
|
+
params: x(n, C, void 0, y === "multipart/form-data", e(r.content[y]?.schema, t))
|
|
109
|
+
} : n instanceof File ? {
|
|
110
110
|
mimeType: b,
|
|
111
|
-
text: S(
|
|
111
|
+
text: S(n)
|
|
112
112
|
} : {
|
|
113
113
|
mimeType: b,
|
|
114
|
-
text: typeof
|
|
114
|
+
text: typeof n == "string" ? n : h(n, y, !1) ?? JSON.stringify(n)
|
|
115
115
|
};
|
|
116
116
|
}
|
|
117
|
-
let k =
|
|
117
|
+
let k = r.content[y], A = e(k?.schema ?? k?.itemSchema);
|
|
118
118
|
if (A !== void 0) {
|
|
119
|
-
let
|
|
119
|
+
let e = o(g(A), {
|
|
120
120
|
compositionSelection: v,
|
|
121
121
|
mode: "write",
|
|
122
122
|
binaryAsFile: y === "multipart/form-data"
|
|
123
123
|
}, { schemaPath: ["requestBody"] });
|
|
124
|
-
if (
|
|
124
|
+
if (e !== void 0) return T && typeof e == "object" && e ? {
|
|
125
125
|
mimeType: b,
|
|
126
|
-
params: x(
|
|
126
|
+
params: x(e, C, void 0, y === "multipart/form-data", A)
|
|
127
127
|
} : {
|
|
128
128
|
mimeType: b,
|
|
129
|
-
text:
|
|
129
|
+
text: h(e, y, k?.schema === void 0) ?? (typeof e == "string" ? e : JSON.stringify(e))
|
|
130
130
|
};
|
|
131
131
|
}
|
|
132
132
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"process-body.js","names":[],"sources":["../../../../src/code-example/helpers/operation-to-har/process-body.ts"],"sourcesContent":["import { isXmlMediaType } from '@scalar/helpers/http/is-xml-media-type'\nimport { getExampleValue, getExplicitExampleText } from '@scalar/workspace-store/helpers/get-example-value'\nimport { getResolvedRef, mergeSiblingReferences } from '@scalar/workspace-store/helpers/get-resolved-ref'\nimport { getResolvedRefDeep } from '@scalar/workspace-store/helpers/get-resolved-ref-deep'\nimport { serializeStreamExample } from '@scalar/workspace-store/helpers/serialize-stream-example'\nimport { unpackProxyObject } from '@scalar/workspace-store/helpers/unpack-proxy'\nimport {\n buildRequestBody,\n coerceLeafValueToSchemaType,\n getExample,\n getExampleFromBody,\n getExampleFromSchema,\n needsMultipartEncoding,\n resolveLeafSchema,\n serializeFormPropertyWithEncoding,\n serializeMultipartArray,\n serializeMultipartBody,\n} from '@scalar/workspace-store/request-example'\nimport type {\n MediaTypeObject,\n RequestBodyObject,\n SchemaObject,\n} from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document'\nimport type { Param, PostData } from 'har-format'\n\nimport type { OperationToHarProps } from './operation-to-har'\n\ntype ProcessBodyProps = Pick<\n OperationToHarProps,\n 'contentType' | 'example' | 'requestBodyCompositionSelection' | 'openapiVersion'\n> & {\n requestBody: RequestBodyObject\n}\n\ntype MultipartEncodingMap = MediaTypeObject['encoding']\n\n/**\n * Builds a HAR param for an uploaded file. `fileName` is what snippet generators read to emit real\n * file handling (for example `files=` in Python or `new Blob` in fetch). `value` keeps the\n * `@filename` placeholder for consumers that only read the text value.\n */\nconst buildFileParam = (name: string, fileName: string, contentType?: string): Param => ({\n name,\n value: `@${fileName}`,\n fileName,\n ...(contentType ? { contentType } : {}),\n})\n\n/** True when the schema describes a binary file (`type: string, format: binary`). */\nconst isBinarySchema = (schema: SchemaObject | undefined): boolean =>\n !!schema && 'type' in schema && schema.type === 'string' && 'format' in schema && schema.format === 'binary'\n\n/**\n * Example generation turns a binary property into the `@filename` placeholder string.\n * Use the schema to tell that apart from a normal text field that happens to start with `@`.\n */\nconst getBinaryPlaceholderFileName = (value: unknown, schema: SchemaObject | undefined): string | undefined =>\n typeof value === 'string' && value.startsWith('@') && isBinarySchema(schema) ? value.slice(1) : undefined\n\n/**\n * Converts a form-data body into HAR `Param[]` entries for `multipart/form-data`\n * and `application/x-www-form-urlencoded` requests.\n *\n * Per OpenAPI 3.1.x Encoding Object, each property's serialization is governed\n * by an optional Encoding entry. When `style` / `explode` / `allowReserved` is\n * set, the value is serialized RFC6570-style and `contentType` is ignored.\n * Multipart arrays apply the encoding to each item and repeat the property name.\n * Object items default to JSON, and uploaded files retain their filename references.\n *\n * @param obj - The form-data payload, either an object keyed by property name\n * or a HAR-style `{ name, value, isDisabled }[]` array.\n * @param encoding - The `encoding` map from the Media Type Object, if any.\n * Used only at the top level (`parentKey` undefined).\n * @param parentKey - When set, we are flattening a nested object inside another\n * property; encoding is ignored and keys are joined with `.` (legacy default).\n * @param isMultipart - True for `multipart/form-data`. Gates the spec defaults\n * for object properties and array items. Urlencoded bodies retain their existing\n * serialization and flattening behavior.\n */\nconst objectToFormParams = (\n obj: object | { name: string; value: unknown; isDisabled: boolean }[],\n encoding?: MultipartEncodingMap,\n parentKey?: string,\n isMultipart = false,\n schema?: SchemaObject,\n): Param[] => {\n const params: Param[] = []\n\n /** Ensure we do not include disabled items */\n const entries: [string, unknown][] = Array.isArray(obj)\n ? obj.filter((item) => !item.isDisabled).map((item) => [String(item.name), item.value])\n : Object.entries(obj)\n\n for (const [key, value] of entries) {\n if (value === undefined || value === null) {\n continue\n }\n\n const partEncoding = parentKey ? undefined : encoding?.[key]\n\n if (isMultipart && !parentKey) {\n const restored = Array.isArray(obj) ? coerceLeafValueToSchemaType(value, resolveLeafSchema(schema, [key])) : value\n const arrayParts = serializeMultipartArray(key, Array.isArray(restored) ? restored : value, partEncoding)\n if (arrayParts) {\n for (const part of arrayParts) {\n if (part.value instanceof File) {\n params.push(buildFileParam(part.key, part.value.name, part.contentType ?? part.value.type))\n continue\n }\n params.push({\n name: part.key,\n value: part.value,\n ...(part.contentType ? { contentType: part.contentType } : {}),\n })\n }\n continue\n }\n }\n /**\n * Per OpenAPI 3.1.1: when style, explode, or allowReserved is explicitly set on the\n * encoding entry, contentType (implicit or explicit) is ignored and the value is\n * serialized as if it were a query-style parameter.\n */\n const hasFormStyle =\n partEncoding &&\n (partEncoding.style !== undefined ||\n partEncoding.explode !== undefined ||\n partEncoding.allowReserved !== undefined)\n /**\n * Per OAS 3.1.x Encoding Object: `contentType` SHALL be ignored if the request body\n * media type is not a multipart. For `application/x-www-form-urlencoded` we still\n * honor `style`/`explode`/`allowReserved` (handled above), but a `contentType`-only\n * entry has no effect — values fall through to the dotted-key flattening default.\n */\n const explicitContentType = hasFormStyle || !isMultipart ? undefined : partEncoding?.contentType\n\n /**\n * When the encoding sets style/explode/allowReserved, serialize the value RFC6570-style\n * (bracket/exploded notation) and ignore contentType. See `serializeFormPropertyWithEncoding`\n * for the per-style rules; it returns null for primitives, Files, and arrays of Files, which\n * then fall through to the dedicated branches below. HAR represents multipart and urlencoded\n * the same way via `PostData.params`, so the resulting parts work for both.\n */\n const binaryPlaceholderFileName =\n isMultipart && !parentKey ? getBinaryPlaceholderFileName(value, resolveLeafSchema(schema, [key])) : undefined\n const styleParams = parentKey ? null : serializeFormPropertyWithEncoding(key, value, partEncoding)\n if (styleParams) {\n for (const param of styleParams) {\n params.push({ name: param.key, value: param.value })\n }\n } else if (value instanceof File) {\n /**\n * File values render as `@filename` references, the conventional cURL syntax for an\n * attached file. Picked up by snippet renderers downstream (e.g. `--form 'x=@file.png'`).\n */\n const file = unpackProxyObject(value)\n params.push(buildFileParam(key, file.name, explicitContentType ?? (isMultipart ? file.type : undefined)))\n } else if (binaryPlaceholderFileName !== undefined) {\n /** A binary property filled in by example generation, so it is a file and not a text field. */\n params.push(buildFileParam(key, binaryPlaceholderFileName, explicitContentType))\n } else if (explicitContentType && typeof value === 'object') {\n /**\n * Per OAS 3.1.x Encoding Object: an explicit `encoding[key].contentType` on a\n * complex value overrides the default and emits a single part containing the value\n * JSON-stringified into that media type. Only reachable when style/explode/allowReserved\n * are unset (otherwise contentType is ignored — see the style branch above).\n */\n params.push({\n name: key,\n value: JSON.stringify(unpackProxyObject(value)),\n contentType: explicitContentType,\n })\n } else if (isMultipart && !parentKey && !hasFormStyle && typeof value === 'object' && !Array.isArray(value)) {\n /**\n * Per OpenAPI 3.x: a top-level multipart property whose value is an object (and not a File)\n * defaults to a single part encoded as application/json, rather than being flattened\n * into multiple parts with dotted keys.\n */\n params.push({\n name: key,\n value: JSON.stringify(unpackProxyObject(value)),\n contentType: 'application/json',\n })\n } else if (Array.isArray(value)) {\n for (const item of value) {\n if (item instanceof File) {\n const file = unpackProxyObject(item)\n params.push(buildFileParam(key, file.name, isMultipart ? file.type : undefined))\n } else {\n params.push({ name: key, value: String(item) })\n }\n }\n } else if (typeof value === 'object') {\n /**\n * Legacy fallback: flatten nested objects into dotted-key parts. Reached when the\n * multipart JSON-default branches above don't apply — i.e. either inside a recursive\n * call (`parentKey` set) or on `application/x-www-form-urlencoded` bodies without an\n * explicit encoding entry. Strict OAS 3.1.x would use `style: form, explode: true` as\n * the urlencoded default (inner keys become top-level params); we keep dotted keys for\n * backwards compatibility with consumers that already parse this shape.\n */\n const nestedParams = objectToFormParams(value, undefined, key)\n\n for (const param of nestedParams) {\n params.push({ name: `${key}.${param.name}`, value: param.value })\n }\n } else {\n params.push({\n name: key,\n value: String(value),\n ...(explicitContentType ? { contentType: explicitContentType } : {}),\n })\n }\n }\n\n return params\n}\n\n/**\n * Processes the request body and returns the processed data\n * Returns undefined if no example is found\n */\nexport const processBody = ({\n requestBody,\n contentType,\n example,\n openapiVersion,\n requestBodyCompositionSelection,\n}: ProcessBodyProps): PostData | undefined => {\n const _contentType = contentType || Object.keys(requestBody.content)[0] || ''\n /** Empty when \"Other\" is selected so snippets do not inject `Content-Type: other`. */\n const harMimeType = _contentType === 'other' ? '' : _contentType\n const formatBinaryFile = (file: File) => {\n const unwrappedFile = unpackProxyObject(file)\n return `@${unwrappedFile.name || 'filename'}`\n }\n const encoding = requestBody.content[_contentType]?.encoding\n\n const media = requestBody.content[_contentType]\n if (media && needsMultipartEncoding(_contentType, media)) {\n const exampleName = example ?? Object.keys(media.examples ?? {})[0] ?? 'default'\n const body = buildRequestBody(\n { ...requestBody, 'x-scalar-selected-content-type': { [exampleName]: _contentType } },\n exampleName,\n requestBodyCompositionSelection,\n )\n if (body?.mode === 'multipart') {\n const encoded = serializeMultipartBody(body.value, body.contentType)\n return {\n mimeType: encoded.contentType,\n // HAR text cannot embed file bytes synchronously. Keep visible file placeholders.\n text: encoded.chunks\n .map((chunk) =>\n chunk instanceof File ? formatBinaryFile(chunk) : chunk instanceof Blob ? 'BINARY' : String(chunk),\n )\n .join(''),\n }\n }\n }\n\n // Check if this is a form data content type\n const isFormData = _contentType === 'multipart/form-data' || _contentType === 'application/x-www-form-urlencoded'\n\n // Check if this is an XML content type\n if (isXmlMediaType(_contentType)) {\n const xmlExample = getExampleFromBody(\n requestBody,\n _contentType,\n example ?? '',\n requestBodyCompositionSelection,\n openapiVersion,\n )\n return xmlExample ? { mimeType: harMimeType, text: xmlExample.value as string } : undefined\n }\n\n // Get the example value\n const selected = getExampleValue(getExample(requestBody, example, contentType))\n const explicitText = getExplicitExampleText(selected, _contentType)\n if (explicitText !== undefined) {\n return { mimeType: harMimeType, text: explicitText }\n }\n const _example = selected?.value\n\n // Return the provided top level example\n if (typeof _example !== 'undefined') {\n const exampleValue = _example !== null && typeof _example === 'object' ? unpackProxyObject(_example) : _example\n\n if (isFormData && typeof exampleValue === 'object' && exampleValue !== null) {\n return {\n mimeType: harMimeType,\n params: objectToFormParams(\n exampleValue,\n encoding,\n undefined,\n _contentType === 'multipart/form-data',\n getResolvedRef(requestBody.content[_contentType]?.schema, mergeSiblingReferences),\n ),\n }\n }\n\n if (exampleValue instanceof File) {\n return {\n mimeType: harMimeType,\n text: formatBinaryFile(exampleValue),\n }\n }\n\n return {\n mimeType: harMimeType,\n text:\n typeof exampleValue === 'string'\n ? exampleValue\n : (serializeStreamExample(exampleValue, _contentType, false) ?? JSON.stringify(exampleValue)),\n }\n }\n\n // Try to extract examples from the schema\n const mediaType = requestBody.content[_contentType]\n const contentSchema = getResolvedRef(mediaType?.schema ?? mediaType?.itemSchema)\n if (typeof contentSchema !== 'undefined') {\n const resolvedContentSchema = getResolvedRefDeep(contentSchema) as SchemaObject\n const extractedExample = getExampleFromSchema(\n resolvedContentSchema,\n {\n compositionSelection: requestBodyCompositionSelection,\n mode: 'write',\n binaryAsFile: _contentType === 'multipart/form-data',\n },\n {\n schemaPath: ['requestBody'],\n },\n )\n\n if (extractedExample !== undefined) {\n if (isFormData && typeof extractedExample === 'object' && extractedExample !== null) {\n return {\n mimeType: harMimeType,\n params: objectToFormParams(\n extractedExample,\n encoding,\n undefined,\n _contentType === 'multipart/form-data',\n resolvedContentSchema,\n ),\n }\n }\n\n return {\n mimeType: harMimeType,\n text:\n serializeStreamExample(extractedExample, _contentType, mediaType?.schema === undefined) ??\n (typeof extractedExample === 'string' ? extractedExample : JSON.stringify(extractedExample)),\n }\n }\n }\n\n return undefined\n}\n"],"mappings":";;;;;;;;AA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GAAa,GAAS,CAAW,CAAC,GACxE,IAAe,EAAuB,GAAU,CAAY;CAClE,IAAI,MAAiB,KAAA,GACnB,OAAO;EAAE,UAAU;EAAa,MAAM;CAAa;CAErD,IAAM,IAAW,GAAU;CAG3B,IAAW,MAAa,QAAa;EACnC,IAAM,IAAoC,OAAO,KAAa,YAAzC,IAAoD,EAAkB,CAAQ,IAAI;EAsBvG,OApBI,KAAc,OAAO,KAAiB,YAAY,IAC7C;GACL,UAAU;GACV,QAAQ,EACN,GACA,GACA,KAAA,GACA,MAAiB,uBACjB,EAAe,EAAY,QAAQ,EAAa,EAAE,QAAQ,CAAsB,CAClF;EACF,IAGE,aAAwB,OACnB;GACL,UAAU;GACV,MAAM,EAAiB,CAAY;EACrC,IAGK;GACL,UAAU;GACV,MACE,OAAO,KAAiB,WACpB,IACC,EAAuB,GAAc,GAAc,EAAK,KAAK,KAAK,UAAU,CAAY;EACjG;CACF;CAGA,IAAM,IAAY,EAAY,QAAQ,IAChC,IAAgB,EAAe,GAAW,UAAU,GAAW,UAAU;CAC/E,IAAW,MAAkB,QAAa;EACxC,IAAM,IAAwB,EAAmB,CAAa,GACxD,IAAmB,EACvB,GACA;GACE,sBAAsB;GACtB,MAAM;GACN,cAAc,MAAiB;EACjC,GACA,EACE,YAAY,CAAC,aAAa,EAC5B,CACF;EAEA,IAAI,MAAqB,KAAA,GAcvB,OAbI,KAAc,OAAO,KAAqB,YAAY,IACjD;GACL,UAAU;GACV,QAAQ,EACN,GACA,GACA,KAAA,GACA,MAAiB,uBACjB,CACF;EACF,IAGK;GACL,UAAU;GACV,MACE,EAAuB,GAAkB,GAAc,GAAW,WAAW,KAAA,CAAS,MACrF,OAAO,KAAqB,WAAW,IAAmB,KAAK,UAAU,CAAgB;EAC9F;CAEJ;AAGF"}
|
|
1
|
+
{"version":3,"file":"process-body.js","names":[],"sources":["../../../../src/code-example/helpers/operation-to-har/process-body.ts"],"sourcesContent":["import { isXmlMediaType } from '@scalar/helpers/http/is-xml-media-type'\nimport { getExampleValue, getExplicitExampleText } from '@scalar/workspace-store/helpers/get-example-value'\nimport { getResolvedRef, mergeSiblingReferences } from '@scalar/workspace-store/helpers/get-resolved-ref'\nimport { serializeStreamExample } from '@scalar/workspace-store/helpers/serialize-stream-example'\nimport { snapshotSchema } from '@scalar/workspace-store/helpers/snapshot-schema'\nimport { unpackProxyObject } from '@scalar/workspace-store/helpers/unpack-proxy'\nimport {\n buildRequestBody,\n coerceLeafValueToSchemaType,\n getExample,\n getExampleFromBody,\n getExampleFromSchema,\n needsMultipartEncoding,\n resolveLeafSchema,\n serializeFormPropertyWithEncoding,\n serializeMultipartArray,\n serializeMultipartBody,\n} from '@scalar/workspace-store/request-example'\nimport type {\n MediaTypeObject,\n RequestBodyObject,\n SchemaObject,\n} from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document'\nimport type { Param, PostData } from 'har-format'\n\nimport type { OperationToHarProps } from './operation-to-har'\n\ntype ProcessBodyProps = Pick<\n OperationToHarProps,\n 'contentType' | 'example' | 'requestBodyCompositionSelection' | 'openapiVersion'\n> & {\n requestBody: RequestBodyObject\n}\n\ntype MultipartEncodingMap = MediaTypeObject['encoding']\n\n/**\n * Builds a HAR param for an uploaded file. `fileName` is what snippet generators read to emit real\n * file handling (for example `files=` in Python or `new Blob` in fetch). `value` keeps the\n * `@filename` placeholder for consumers that only read the text value.\n */\nconst buildFileParam = (name: string, fileName: string, contentType?: string): Param => ({\n name,\n value: `@${fileName}`,\n fileName,\n ...(contentType ? { contentType } : {}),\n})\n\n/** True when the schema describes a binary file (`type: string, format: binary`). */\nconst isBinarySchema = (schema: SchemaObject | undefined): boolean =>\n !!schema && 'type' in schema && schema.type === 'string' && 'format' in schema && schema.format === 'binary'\n\n/**\n * Example generation turns a binary property into the `@filename` placeholder string.\n * Use the schema to tell that apart from a normal text field that happens to start with `@`.\n */\nconst getBinaryPlaceholderFileName = (value: unknown, schema: SchemaObject | undefined): string | undefined =>\n typeof value === 'string' && value.startsWith('@') && isBinarySchema(schema) ? value.slice(1) : undefined\n\n/**\n * Converts a form-data body into HAR `Param[]` entries for `multipart/form-data`\n * and `application/x-www-form-urlencoded` requests.\n *\n * Per OpenAPI 3.1.x Encoding Object, each property's serialization is governed\n * by an optional Encoding entry. When `style` / `explode` / `allowReserved` is\n * set, the value is serialized RFC6570-style and `contentType` is ignored.\n * Multipart arrays apply the encoding to each item and repeat the property name.\n * Object items default to JSON, and uploaded files retain their filename references.\n *\n * @param obj - The form-data payload, either an object keyed by property name\n * or a HAR-style `{ name, value, isDisabled }[]` array.\n * @param encoding - The `encoding` map from the Media Type Object, if any.\n * Used only at the top level (`parentKey` undefined).\n * @param parentKey - When set, we are flattening a nested object inside another\n * property; encoding is ignored and keys are joined with `.` (legacy default).\n * @param isMultipart - True for `multipart/form-data`. Gates the spec defaults\n * for object properties and array items. Urlencoded bodies retain their existing\n * serialization and flattening behavior.\n */\nconst objectToFormParams = (\n obj: object | { name: string; value: unknown; isDisabled: boolean }[],\n encoding?: MultipartEncodingMap,\n parentKey?: string,\n isMultipart = false,\n schema?: SchemaObject,\n): Param[] => {\n const params: Param[] = []\n\n /** Ensure we do not include disabled items */\n const entries: [string, unknown][] = Array.isArray(obj)\n ? obj.filter((item) => !item.isDisabled).map((item) => [String(item.name), item.value])\n : Object.entries(obj)\n\n for (const [key, value] of entries) {\n if (value === undefined || value === null) {\n continue\n }\n\n const partEncoding = parentKey ? undefined : encoding?.[key]\n\n if (isMultipart && !parentKey) {\n const restored = Array.isArray(obj) ? coerceLeafValueToSchemaType(value, resolveLeafSchema(schema, [key])) : value\n const arrayParts = serializeMultipartArray(key, Array.isArray(restored) ? restored : value, partEncoding)\n if (arrayParts) {\n for (const part of arrayParts) {\n if (part.value instanceof File) {\n params.push(buildFileParam(part.key, part.value.name, part.contentType ?? part.value.type))\n continue\n }\n params.push({\n name: part.key,\n value: part.value,\n ...(part.contentType ? { contentType: part.contentType } : {}),\n })\n }\n continue\n }\n }\n /**\n * Per OpenAPI 3.1.1: when style, explode, or allowReserved is explicitly set on the\n * encoding entry, contentType (implicit or explicit) is ignored and the value is\n * serialized as if it were a query-style parameter.\n */\n const hasFormStyle =\n partEncoding &&\n (partEncoding.style !== undefined ||\n partEncoding.explode !== undefined ||\n partEncoding.allowReserved !== undefined)\n /**\n * Per OAS 3.1.x Encoding Object: `contentType` SHALL be ignored if the request body\n * media type is not a multipart. For `application/x-www-form-urlencoded` we still\n * honor `style`/`explode`/`allowReserved` (handled above), but a `contentType`-only\n * entry has no effect — values fall through to the dotted-key flattening default.\n */\n const explicitContentType = hasFormStyle || !isMultipart ? undefined : partEncoding?.contentType\n\n /**\n * When the encoding sets style/explode/allowReserved, serialize the value RFC6570-style\n * (bracket/exploded notation) and ignore contentType. See `serializeFormPropertyWithEncoding`\n * for the per-style rules; it returns null for primitives, Files, and arrays of Files, which\n * then fall through to the dedicated branches below. HAR represents multipart and urlencoded\n * the same way via `PostData.params`, so the resulting parts work for both.\n */\n const binaryPlaceholderFileName =\n isMultipart && !parentKey ? getBinaryPlaceholderFileName(value, resolveLeafSchema(schema, [key])) : undefined\n const styleParams = parentKey ? null : serializeFormPropertyWithEncoding(key, value, partEncoding)\n if (styleParams) {\n for (const param of styleParams) {\n params.push({ name: param.key, value: param.value })\n }\n } else if (value instanceof File) {\n /**\n * File values render as `@filename` references, the conventional cURL syntax for an\n * attached file. Picked up by snippet renderers downstream (e.g. `--form 'x=@file.png'`).\n */\n const file = unpackProxyObject(value)\n params.push(buildFileParam(key, file.name, explicitContentType ?? (isMultipart ? file.type : undefined)))\n } else if (binaryPlaceholderFileName !== undefined) {\n /** A binary property filled in by example generation, so it is a file and not a text field. */\n params.push(buildFileParam(key, binaryPlaceholderFileName, explicitContentType))\n } else if (explicitContentType && typeof value === 'object') {\n /**\n * Per OAS 3.1.x Encoding Object: an explicit `encoding[key].contentType` on a\n * complex value overrides the default and emits a single part containing the value\n * JSON-stringified into that media type. Only reachable when style/explode/allowReserved\n * are unset (otherwise contentType is ignored — see the style branch above).\n */\n params.push({\n name: key,\n value: JSON.stringify(unpackProxyObject(value)),\n contentType: explicitContentType,\n })\n } else if (isMultipart && !parentKey && !hasFormStyle && typeof value === 'object' && !Array.isArray(value)) {\n /**\n * Per OpenAPI 3.x: a top-level multipart property whose value is an object (and not a File)\n * defaults to a single part encoded as application/json, rather than being flattened\n * into multiple parts with dotted keys.\n */\n params.push({\n name: key,\n value: JSON.stringify(unpackProxyObject(value)),\n contentType: 'application/json',\n })\n } else if (Array.isArray(value)) {\n for (const item of value) {\n if (item instanceof File) {\n const file = unpackProxyObject(item)\n params.push(buildFileParam(key, file.name, isMultipart ? file.type : undefined))\n } else {\n params.push({ name: key, value: String(item) })\n }\n }\n } else if (typeof value === 'object') {\n /**\n * Legacy fallback: flatten nested objects into dotted-key parts. Reached when the\n * multipart JSON-default branches above don't apply — i.e. either inside a recursive\n * call (`parentKey` set) or on `application/x-www-form-urlencoded` bodies without an\n * explicit encoding entry. Strict OAS 3.1.x would use `style: form, explode: true` as\n * the urlencoded default (inner keys become top-level params); we keep dotted keys for\n * backwards compatibility with consumers that already parse this shape.\n */\n const nestedParams = objectToFormParams(value, undefined, key)\n\n for (const param of nestedParams) {\n params.push({ name: `${key}.${param.name}`, value: param.value })\n }\n } else {\n params.push({\n name: key,\n value: String(value),\n ...(explicitContentType ? { contentType: explicitContentType } : {}),\n })\n }\n }\n\n return params\n}\n\n/**\n * Processes the request body and returns the processed data\n * Returns undefined if no example is found\n */\nexport const processBody = ({\n requestBody,\n contentType,\n example,\n openapiVersion,\n requestBodyCompositionSelection,\n}: ProcessBodyProps): PostData | undefined => {\n const _contentType = contentType || Object.keys(requestBody.content)[0] || ''\n /** Empty when \"Other\" is selected so snippets do not inject `Content-Type: other`. */\n const harMimeType = _contentType === 'other' ? '' : _contentType\n const formatBinaryFile = (file: File) => {\n const unwrappedFile = unpackProxyObject(file)\n return `@${unwrappedFile.name || 'filename'}`\n }\n const encoding = requestBody.content[_contentType]?.encoding\n\n const media = requestBody.content[_contentType]\n if (media && needsMultipartEncoding(_contentType, media)) {\n const exampleName = example ?? Object.keys(media.examples ?? {})[0] ?? 'default'\n const body = buildRequestBody(\n { ...requestBody, 'x-scalar-selected-content-type': { [exampleName]: _contentType } },\n exampleName,\n requestBodyCompositionSelection,\n )\n if (body?.mode === 'multipart') {\n const encoded = serializeMultipartBody(body.value, body.contentType)\n return {\n mimeType: encoded.contentType,\n // HAR text cannot embed file bytes synchronously. Keep visible file placeholders.\n text: encoded.chunks\n .map((chunk) => {\n if (chunk instanceof File) {\n return formatBinaryFile(chunk)\n }\n return chunk instanceof Blob ? 'BINARY' : String(chunk)\n })\n .join(''),\n }\n }\n }\n\n // Check if this is a form data content type\n const isFormData = _contentType === 'multipart/form-data' || _contentType === 'application/x-www-form-urlencoded'\n\n // Check if this is an XML content type\n if (isXmlMediaType(_contentType)) {\n const xmlExample = getExampleFromBody(\n requestBody,\n _contentType,\n example ?? '',\n requestBodyCompositionSelection,\n openapiVersion,\n )\n return xmlExample ? { mimeType: harMimeType, text: xmlExample.value as string } : undefined\n }\n\n // Get the example value\n const selected = getExampleValue(getExample(requestBody, example, contentType))\n const explicitText = getExplicitExampleText(selected, _contentType)\n if (explicitText !== undefined) {\n return { mimeType: harMimeType, text: explicitText }\n }\n const _example = selected?.value\n\n // Return the provided top level example\n if (typeof _example !== 'undefined') {\n const exampleValue = _example !== null && typeof _example === 'object' ? unpackProxyObject(_example) : _example\n\n if (isFormData && typeof exampleValue === 'object' && exampleValue !== null) {\n return {\n mimeType: harMimeType,\n params: objectToFormParams(\n exampleValue,\n encoding,\n undefined,\n _contentType === 'multipart/form-data',\n getResolvedRef(requestBody.content[_contentType]?.schema, mergeSiblingReferences),\n ),\n }\n }\n\n if (exampleValue instanceof File) {\n return {\n mimeType: harMimeType,\n text: formatBinaryFile(exampleValue),\n }\n }\n\n return {\n mimeType: harMimeType,\n text:\n typeof exampleValue === 'string'\n ? exampleValue\n : (serializeStreamExample(exampleValue, _contentType, false) ?? JSON.stringify(exampleValue)),\n }\n }\n\n // Try to extract examples from the schema\n const mediaType = requestBody.content[_contentType]\n const contentSchema = getResolvedRef(mediaType?.schema ?? mediaType?.itemSchema)\n if (typeof contentSchema !== 'undefined') {\n const extractedExample = getExampleFromSchema(\n snapshotSchema(contentSchema),\n {\n compositionSelection: requestBodyCompositionSelection,\n mode: 'write',\n binaryAsFile: _contentType === 'multipart/form-data',\n },\n {\n schemaPath: ['requestBody'],\n },\n )\n\n if (extractedExample !== undefined) {\n if (isFormData && typeof extractedExample === 'object' && extractedExample !== null) {\n return {\n mimeType: harMimeType,\n params: objectToFormParams(\n extractedExample,\n encoding,\n undefined,\n _contentType === 'multipart/form-data',\n contentSchema,\n ),\n }\n }\n\n return {\n mimeType: harMimeType,\n text:\n serializeStreamExample(extractedExample, _contentType, mediaType?.schema === undefined) ??\n (typeof extractedExample === 'string' ? extractedExample : JSON.stringify(extractedExample)),\n }\n }\n }\n\n return undefined\n}\n"],"mappings":";;;;;;;;AAyCA,IAAM,KAAkB,GAAc,GAAkB,OAAiC;CACvF;CACA,OAAO,IAAI;CACX;CACA,GAAI,IAAc,EAAE,eAAY,IAAI,CAAC;AACvC,IAGM,KAAkB,MACtB,CAAC,CAAC,KAAU,UAAU,KAAU,EAAO,SAAS,YAAY,YAAY,KAAU,EAAO,WAAW,UAMhG,KAAgC,GAAgB,MACpD,OAAO,KAAU,YAAY,EAAM,WAAW,GAAG,KAAK,EAAe,CAAM,IAAI,EAAM,MAAM,CAAC,IAAI,KAAA,GAsB5F,KACJ,GACA,GACA,GACA,IAAc,IACd,MACY;CACZ,IAAM,IAAkB,CAAC,GAGnB,IAA+B,MAAM,QAAQ,CAAG,IAClD,EAAI,QAAQ,MAAS,CAAC,EAAK,UAAU,CAAC,CAAC,KAAK,MAAS,CAAC,OAAO,EAAK,IAAI,GAAG,EAAK,KAAK,CAAC,IACpF,OAAO,QAAQ,CAAG;CAEtB,KAAK,IAAM,CAAC,GAAK,MAAU,GAAS;EAClC,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B,EAAe,GAAW,UAAU,GAAW,UAAU;CAC/E,IAAW,MAAkB,QAAa;EACxC,IAAM,IAAmB,EACvB,EAAe,CAAa,GAC5B;GACE,sBAAsB;GACtB,MAAM;GACN,cAAc,MAAiB;EACjC,GACA,EACE,YAAY,CAAC,aAAa,EAC5B,CACF;EAEA,IAAI,MAAqB,KAAA,GAcvB,OAbI,KAAc,OAAO,KAAqB,YAAY,IACjD;GACL,UAAU;GACV,QAAQ,EACN,GACA,GACA,KAAA,GACA,MAAiB,uBACjB,CACF;EACF,IAGK;GACL,UAAU;GACV,MACE,EAAuB,GAAkB,GAAc,GAAW,WAAW,KAAA,CAAS,MACrF,OAAO,KAAqB,WAAW,IAAmB,KAAK,UAAU,CAAgB;EAC9F;CAEJ;AAGF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"process-parameters.d.ts","sourceRoot":"","sources":["../../../../src/code-example/helpers/operation-to-har/process-parameters.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"process-parameters.d.ts","sourceRoot":"","sources":["../../../../src/code-example/helpers/operation-to-har/process-parameters.ts"],"names":[],"mappings":"AA0BA,OAAO,KAAK,EAAE,eAAe,EAAmB,MAAM,8DAA8D,CAAA;AACpH,OAAO,KAAK,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,YAAY,CAAA;AAEvD,wFAAwF;AACxF,qBAAa,wBAAyB,SAAQ,KAAK;CAAG;AAEtD,KAAK,mBAAmB,GAAG;IACzB,6DAA6D;IAC7D,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B,GAAG,EAAE,MAAM,CAAA;IACX,OAAO,EAAE,UAAU,CAAC,SAAS,CAAC,CAAA;IAC9B,WAAW,EAAE,UAAU,CAAC,aAAa,CAAC,CAAA;IACtC,OAAO,EAAE,UAAU,CAAC,SAAS,CAAC,CAAA;IAC9B,+EAA+E;IAC/E,qBAAqB,EAAE,OAAO,CAAA;CAC/B,CAAA;AA6FD;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAAI,uEAM/B;IACD,UAAU,EAAE,UAAU,CAAA;IACtB,UAAU,EAAE,eAAe,CAAC,YAAY,CAAC,CAAA;IACzC,qCAAqC;IACrC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC5B,gDAAgD;IAChD,eAAe,EAAE,OAAO,CAAA;IACxB,2CAA2C;IAC3C,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB,KAAG,mBAwPH,CAAA"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { getResolvedRef as e } from "@scalar/workspace-store/helpers/get-resolved-ref";
|
|
2
|
-
import { deSerializeParameter as t,
|
|
3
|
-
import { getCookieSerializationError as
|
|
4
|
-
import { isObjectLike as
|
|
5
|
-
import { assertReservedPathUrl as
|
|
6
|
-
import { getParameterExample as
|
|
7
|
-
import { getQuerystringParameter as
|
|
2
|
+
import { deSerializeParameter as t, filterDisabledProperties as n, getExampleFromSchema as r, isParamDisabled as i, serializeContentValue as a, serializeCookieStyle as o, serializeDeepObjectStyle as s, serializeFormStyle as c, serializeFormStyleForCookies as l, serializePipeDelimitedStyle as u, serializeSimpleStyle as d, serializeSpaceDelimitedStyle as f } from "@scalar/workspace-store/request-example";
|
|
3
|
+
import { getCookieSerializationError as p } from "@scalar/helpers/http/get-cookie-serialization-error";
|
|
4
|
+
import { isObjectLike as m } from "@scalar/helpers/object/is-object";
|
|
5
|
+
import { assertReservedPathUrl as h, serializeReservedPathParameter as g } from "@scalar/workspace-store/helpers/encode-path-parameter";
|
|
6
|
+
import { getParameterExample as _ } from "@scalar/workspace-store/helpers/get-parameter-example";
|
|
7
|
+
import { getQuerystringParameter as v, serializeQuerystringParameter as y } from "@scalar/workspace-store/helpers/querystring-parameter";
|
|
8
8
|
//#region src/code-example/helpers/operation-to-har/process-parameters.ts
|
|
9
|
-
var
|
|
9
|
+
var b = class extends Error {}, x = (t) => (t ?? []).map((t) => e(t)).filter((e) => e !== void 0), S = (e) => "allowReserved" in e && e.allowReserved !== void 0 ? e.allowReserved : "schema" in e && e.schema && typeof e.schema == "object" && "allowReserved" in e.schema ? e.schema.allowReserved === !0 : !1, C = (e) => {
|
|
10
10
|
if (e.in === "header") return {
|
|
11
11
|
style: "simple",
|
|
12
12
|
explode: "explode" in e && e.explode !== void 0 && e.explode
|
|
@@ -29,32 +29,33 @@ var y = class extends Error {}, b = (t) => (t ?? []).map((t) => e(t)).filter((e)
|
|
|
29
29
|
style: n,
|
|
30
30
|
explode: "explode" in e && e.explode !== void 0 ? e.explode : n === "form"
|
|
31
31
|
};
|
|
32
|
-
},
|
|
33
|
-
let
|
|
34
|
-
if (
|
|
35
|
-
if (
|
|
36
|
-
if (
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
32
|
+
}, w = (a, o, s) => {
|
|
33
|
+
let c = _(a, o), l = c.example, u = a.in === "query" && !c.serialized && !c.mediaSerialized ? l?.["x-scalar-disabled-properties"] : void 0;
|
|
34
|
+
if (u) return n(t(c.value, a), u, i(a, l, s));
|
|
35
|
+
if (i(a, l, s)) return;
|
|
36
|
+
if (c.value !== void 0) return t(c.value, a);
|
|
37
|
+
if (!("schema" in a) || !a.schema) return;
|
|
38
|
+
let d = a.in === "path" ? { emptyString: `{${a.name}}` } : {}, f = e(a.schema);
|
|
39
|
+
return f ? r(f, d) : void 0;
|
|
40
|
+
}, T = ({ harRequest: e, parameters: t, example: n, defaultDisabled: r, openapiVersion: m }) => {
|
|
41
|
+
let T = [...e.headers], D = [...e.queryString], O = [...e.cookies], k = [], A = e.url, j = !1, M = [], N = [], P = (e, t, n) => {
|
|
42
|
+
S(n) ? M.push(`${encodeURIComponent(e)}=${t}`) : D.push({
|
|
42
43
|
name: e,
|
|
43
44
|
value: t
|
|
44
45
|
});
|
|
45
|
-
}, F =
|
|
46
|
+
}, F = x(t);
|
|
46
47
|
for (let e of F) {
|
|
47
48
|
if (!e.in || !e.name) continue;
|
|
48
49
|
if (e.in === "querystring") {
|
|
49
|
-
let t =
|
|
50
|
+
let t = v(e, n, { defaultDisabled: r });
|
|
50
51
|
if (t) {
|
|
51
|
-
let e = A.indexOf("#"), n = e === -1 ? "" : A.slice(e), r = (e === -1 ? A : A.slice(0, e)).split("?")[0], i =
|
|
52
|
+
let e = A.indexOf("#"), n = e === -1 ? "" : A.slice(e), r = (e === -1 ? A : A.slice(0, e)).split("?")[0], i = y(t);
|
|
52
53
|
A = `${r}${i ? `?${i}` : ""}${n}`;
|
|
53
54
|
}
|
|
54
55
|
continue;
|
|
55
56
|
}
|
|
56
|
-
let t =
|
|
57
|
-
if (t.serialized && !
|
|
57
|
+
let t = _(e, n);
|
|
58
|
+
if (t.serialized && !i(e, t.example, r)) {
|
|
58
59
|
let n = String(t.value);
|
|
59
60
|
switch (e.in) {
|
|
60
61
|
case "path":
|
|
@@ -64,7 +65,7 @@ var y = class extends Error {}, b = (t) => (t ?? []).map((t) => e(t)).filter((e)
|
|
|
64
65
|
M.push(n);
|
|
65
66
|
break;
|
|
66
67
|
case "header":
|
|
67
|
-
|
|
68
|
+
T.push({
|
|
68
69
|
name: e.name,
|
|
69
70
|
value: n
|
|
70
71
|
});
|
|
@@ -75,14 +76,14 @@ var y = class extends Error {}, b = (t) => (t ?? []).map((t) => e(t)).filter((e)
|
|
|
75
76
|
}
|
|
76
77
|
continue;
|
|
77
78
|
}
|
|
78
|
-
if (t.mediaSerialized && !
|
|
79
|
+
if (t.mediaSerialized && !i(e, t.example, r)) {
|
|
79
80
|
let n = String(t.value);
|
|
80
81
|
switch (e.in) {
|
|
81
82
|
case "query":
|
|
82
83
|
P(e.name, n, e);
|
|
83
84
|
break;
|
|
84
85
|
case "header":
|
|
85
|
-
|
|
86
|
+
T.push({
|
|
86
87
|
name: e.name,
|
|
87
88
|
value: n
|
|
88
89
|
});
|
|
@@ -99,73 +100,73 @@ var y = class extends Error {}, b = (t) => (t ?? []).map((t) => e(t)).filter((e)
|
|
|
99
100
|
}
|
|
100
101
|
continue;
|
|
101
102
|
}
|
|
102
|
-
let
|
|
103
|
-
if (
|
|
104
|
-
let { style:
|
|
103
|
+
let h = w(e, n, r);
|
|
104
|
+
if (h === void 0) continue;
|
|
105
|
+
let { style: x, explode: S } = C(e);
|
|
105
106
|
switch (e.in) {
|
|
106
107
|
case "path": {
|
|
107
|
-
let t =
|
|
108
|
+
let t = m?.startsWith("3.2.") && "schema" in e && e.allowReserved === !0;
|
|
108
109
|
j ||= !!t;
|
|
109
|
-
let n = t ?
|
|
110
|
-
value:
|
|
111
|
-
style:
|
|
112
|
-
explode:
|
|
110
|
+
let n = t ? g(e.name, {
|
|
111
|
+
value: h,
|
|
112
|
+
style: x,
|
|
113
|
+
explode: S
|
|
113
114
|
}) : void 0;
|
|
114
|
-
A = n === void 0 ?
|
|
115
|
+
A = n === void 0 ? E(A, e, h, x, S) : A.replaceAll(`{${e.name}}`, () => n);
|
|
115
116
|
break;
|
|
116
117
|
}
|
|
117
118
|
case "query":
|
|
118
119
|
if ("content" in e && e.content) {
|
|
119
|
-
let t =
|
|
120
|
+
let t = a(h, Object.keys(e.content)[0] ?? "application/json");
|
|
120
121
|
P(e.name, t, e);
|
|
121
122
|
break;
|
|
122
123
|
}
|
|
123
|
-
switch (
|
|
124
|
+
switch (x) {
|
|
124
125
|
case "form": {
|
|
125
|
-
let t =
|
|
126
|
+
let t = c(h, S);
|
|
126
127
|
if (Array.isArray(t)) for (let n of t) P(n.key || e.name, String(n.value), e);
|
|
127
128
|
else P(e.name, String(t), e);
|
|
128
129
|
break;
|
|
129
130
|
}
|
|
130
131
|
case "spaceDelimited": {
|
|
131
|
-
let t =
|
|
132
|
+
let t = f(h);
|
|
132
133
|
P(e.name, t, e);
|
|
133
134
|
break;
|
|
134
135
|
}
|
|
135
136
|
case "pipeDelimited": {
|
|
136
|
-
let t =
|
|
137
|
+
let t = u(h);
|
|
137
138
|
P(e.name, t, e);
|
|
138
139
|
break;
|
|
139
140
|
}
|
|
140
141
|
case "deepObject":
|
|
141
|
-
if (Array.isArray(
|
|
142
|
-
let t =
|
|
142
|
+
if (Array.isArray(h)) {
|
|
143
|
+
let t = c(h, !0);
|
|
143
144
|
if (Array.isArray(t)) for (let n of t) P(n.key || e.name, String(n.value), e);
|
|
144
145
|
else P(e.name, String(t), e);
|
|
145
146
|
} else {
|
|
146
|
-
let t =
|
|
147
|
+
let t = s(e.name, h);
|
|
147
148
|
for (let n of t) P(n.key, n.value, e);
|
|
148
149
|
}
|
|
149
150
|
break;
|
|
150
|
-
default: P(e.name, String(
|
|
151
|
+
default: P(e.name, String(h), e);
|
|
151
152
|
}
|
|
152
153
|
break;
|
|
153
154
|
case "header": {
|
|
154
|
-
let t =
|
|
155
|
-
|
|
155
|
+
let t = d(h, S);
|
|
156
|
+
T.push({
|
|
156
157
|
name: e.name,
|
|
157
158
|
value: String(t)
|
|
158
159
|
});
|
|
159
160
|
break;
|
|
160
161
|
}
|
|
161
162
|
case "cookie": {
|
|
162
|
-
let [t, n] = (
|
|
163
|
-
if (r) throw new
|
|
164
|
-
if (
|
|
165
|
-
k.push(...
|
|
163
|
+
let [t, n] = (m ?? "").split("."), r = t === "3" && n === "2" && !("content" in e) ? p(e, h) : void 0;
|
|
164
|
+
if (r) throw new b(r);
|
|
165
|
+
if (x === "cookie") {
|
|
166
|
+
k.push(...o(e.name, h, S));
|
|
166
167
|
break;
|
|
167
168
|
}
|
|
168
|
-
let i =
|
|
169
|
+
let i = l(h, S);
|
|
169
170
|
if (Array.isArray(i)) for (let t of i) {
|
|
170
171
|
let n = t.key || e.name, r = t.value === null ? "null" : String(t.value);
|
|
171
172
|
O.push({
|
|
@@ -189,11 +190,11 @@ var y = class extends Error {}, b = (t) => (t ?? []).map((t) => e(t)).filter((e)
|
|
|
189
190
|
...O.map((e) => `${encodeURIComponent(e.name)}=${encodeURIComponent(e.value)}`),
|
|
190
191
|
...k.map((e) => `${e.name}=${e.value}`),
|
|
191
192
|
...N
|
|
192
|
-
].join("; "), t =
|
|
193
|
-
t ?
|
|
193
|
+
].join("; "), t = T.find((e) => e.name.toLowerCase() === "cookie");
|
|
194
|
+
t ? T.splice(T.indexOf(t), 1, {
|
|
194
195
|
...t,
|
|
195
196
|
value: t.value ? `${t.value}; ${e}` : e
|
|
196
|
-
}) :
|
|
197
|
+
}) : T.push({
|
|
197
198
|
name: "Cookie",
|
|
198
199
|
value: e
|
|
199
200
|
});
|
|
@@ -202,15 +203,15 @@ var y = class extends Error {}, b = (t) => (t ?? []).map((t) => e(t)).filter((e)
|
|
|
202
203
|
let e = A.indexOf("#"), t = e < 0 ? "" : A.slice(e), n = e < 0 ? A : A.slice(0, e);
|
|
203
204
|
A = `${n}${n.includes("?") ? "&" : "?"}${M.join("&")}${t}`;
|
|
204
205
|
}
|
|
205
|
-
return j &&
|
|
206
|
+
return j && h(A), {
|
|
206
207
|
url: A,
|
|
207
|
-
headers:
|
|
208
|
+
headers: T,
|
|
208
209
|
queryString: D,
|
|
209
210
|
cookies: k.length || N.length ? [] : O,
|
|
210
211
|
hasCookieStyleEntries: k.length > 0 || N.length > 0,
|
|
211
212
|
...M.length ? { hasSerializedQuery: !0 } : {}
|
|
212
213
|
};
|
|
213
|
-
},
|
|
214
|
+
}, E = (e, t, n, r, i) => {
|
|
214
215
|
switch (r) {
|
|
215
216
|
case "matrix":
|
|
216
217
|
if (i) {
|
|
@@ -218,14 +219,14 @@ var y = class extends Error {}, b = (t) => (t ?? []).map((t) => e(t)).filter((e)
|
|
|
218
219
|
let r = n.map((e) => `${t.name}=${e}`).join(";");
|
|
219
220
|
return e.replace(`{;${t.name}}`, `;${r}`);
|
|
220
221
|
}
|
|
221
|
-
if (
|
|
222
|
+
if (m(n)) {
|
|
222
223
|
let r = Object.entries(n).map(([e, t]) => `${e}=${t}`).join(";");
|
|
223
224
|
return e.replace(`{;${t.name}}`, `;${r}`);
|
|
224
225
|
}
|
|
225
226
|
return e.replace(`{;${t.name}}`, `;${t.name}=${n}`);
|
|
226
227
|
}
|
|
227
228
|
if (Array.isArray(n)) return e.replace(`{;${t.name}}`, `;${t.name}=${n.join(",")}`);
|
|
228
|
-
if (
|
|
229
|
+
if (m(n)) {
|
|
229
230
|
let r = Object.entries(n).map(([e, t]) => `${e},${t}`).join(",");
|
|
230
231
|
return e.replace(`{;${t.name}}`, `;${t.name}=${r}`);
|
|
231
232
|
}
|
|
@@ -233,26 +234,26 @@ var y = class extends Error {}, b = (t) => (t ?? []).map((t) => e(t)).filter((e)
|
|
|
233
234
|
case "label":
|
|
234
235
|
if (i) {
|
|
235
236
|
if (Array.isArray(n)) return e.replace(`{.${t.name}}`, `.${n.join(".")}`);
|
|
236
|
-
if (
|
|
237
|
+
if (m(n)) {
|
|
237
238
|
let r = Object.entries(n).map(([e, t]) => `${e}=${t}`).join(".");
|
|
238
239
|
return e.replace(`{.${t.name}}`, `.${r}`);
|
|
239
240
|
}
|
|
240
241
|
return e.replace(`{.${t.name}}`, `.${n}`);
|
|
241
242
|
}
|
|
242
243
|
if (Array.isArray(n)) return e.replace(`{.${t.name}}`, `.${n.join(",")}`);
|
|
243
|
-
if (
|
|
244
|
+
if (m(n)) {
|
|
244
245
|
let r = Object.entries(n).map(([e, t]) => `${e},${t}`).join(",");
|
|
245
246
|
return e.replace(`{.${t.name}}`, `.${r}`);
|
|
246
247
|
}
|
|
247
248
|
return e.replace(`{.${t.name}}`, `.${n}`);
|
|
248
249
|
case "simple": {
|
|
249
|
-
let r =
|
|
250
|
+
let r = d(n, i);
|
|
250
251
|
return e.replace(`{${t.name}}`, String(r));
|
|
251
252
|
}
|
|
252
253
|
default: return e.replace(`{${t.name}}`, String(n));
|
|
253
254
|
}
|
|
254
255
|
};
|
|
255
256
|
//#endregion
|
|
256
|
-
export {
|
|
257
|
+
export { b as CookieSerializationError, T as processParameters };
|
|
257
258
|
|
|
258
259
|
//# sourceMappingURL=process-parameters.js.map
|