@scalar/oas-utils 0.4.17 → 0.4.20

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.
Files changed (45) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/dist/entities/spec/request-examples.d.ts +55 -55
  3. package/dist/entities/spec/request-examples.d.ts.map +1 -1
  4. package/dist/entities/spec/request-examples.js.map +2 -2
  5. package/dist/helpers/index.d.ts +1 -0
  6. package/dist/helpers/index.d.ts.map +1 -1
  7. package/dist/helpers/index.js +2 -0
  8. package/dist/helpers/index.js.map +2 -2
  9. package/dist/helpers/operation-to-har/operation-to-har.d.ts +1 -2
  10. package/dist/helpers/operation-to-har/operation-to-har.d.ts.map +1 -1
  11. package/dist/helpers/operation-to-har/operation-to-har.js +16 -8
  12. package/dist/helpers/operation-to-har/operation-to-har.js.map +2 -2
  13. package/dist/helpers/operation-to-har/process-body.d.ts +5 -2
  14. package/dist/helpers/operation-to-har/process-body.d.ts.map +1 -1
  15. package/dist/helpers/operation-to-har/process-body.js +3 -4
  16. package/dist/helpers/operation-to-har/process-body.js.map +2 -2
  17. package/dist/helpers/operation-to-har/process-parameters.d.ts +2 -4
  18. package/dist/helpers/operation-to-har/process-parameters.d.ts.map +1 -1
  19. package/dist/helpers/operation-to-har/process-parameters.js +24 -8
  20. package/dist/helpers/operation-to-har/process-parameters.js.map +2 -2
  21. package/dist/helpers/operation-to-har/process-security-schemes.js +1 -1
  22. package/dist/helpers/operation-to-har/process-security-schemes.js.map +2 -2
  23. package/dist/helpers/servers.d.ts +24 -0
  24. package/dist/helpers/servers.d.ts.map +1 -0
  25. package/dist/helpers/servers.js +97 -0
  26. package/dist/helpers/servers.js.map +7 -0
  27. package/dist/spec-getters/get-example-from-schema.d.ts +3 -2
  28. package/dist/spec-getters/get-example-from-schema.d.ts.map +1 -1
  29. package/dist/spec-getters/get-example-from-schema.js +52 -39
  30. package/dist/spec-getters/get-example-from-schema.js.map +2 -2
  31. package/dist/spec-getters/get-parameters-from-operation.d.ts.map +1 -1
  32. package/dist/spec-getters/get-parameters-from-operation.js +4 -1
  33. package/dist/spec-getters/get-parameters-from-operation.js.map +2 -2
  34. package/dist/spec-getters/get-request-body-from-operation.d.ts.map +1 -1
  35. package/dist/spec-getters/get-request-body-from-operation.js +5 -4
  36. package/dist/spec-getters/get-request-body-from-operation.js.map +2 -2
  37. package/dist/transforms/import-spec.d.ts +0 -4
  38. package/dist/transforms/import-spec.d.ts.map +1 -1
  39. package/dist/transforms/import-spec.js +2 -69
  40. package/dist/transforms/import-spec.js.map +2 -2
  41. package/dist/transforms/index.d.ts +1 -1
  42. package/dist/transforms/index.d.ts.map +1 -1
  43. package/dist/transforms/index.js +0 -2
  44. package/dist/transforms/index.js.map +2 -2
  45. package/package.json +9 -8
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/entities/spec/request-examples.ts"],
4
- "sourcesContent": ["import { schemaModel } from '@/helpers/schema-model'\nimport { getServerVariableExamples } from '@/spec-getters/get-server-variable-examples'\nimport { keysOf } from '@scalar/object-utils/arrays'\nimport { type ENTITY_BRANDS, nanoidSchema } from '@scalar/types/utils'\nimport { z } from 'zod'\n\nimport { getRequestBodyFromOperation } from '@/spec-getters/get-request-body-from-operation'\nimport { isDefined } from '@scalar/helpers/array/is-defined'\nimport { objectKeys } from '@scalar/helpers/object/object-keys'\nimport type { ParameterContent, RequestParameter } from './parameters'\nimport type { Request } from './requests'\nimport type { Server } from './server'\n\n// ---------------------------------------------------------------------------\n// Example Parameters\n\n/**\n * TODO: Deprecate this.\n *\n * The request schema should be stored in the request and any\n * parameters should be validated against that\n */\nexport const requestExampleParametersSchema = z\n .object({\n key: z.string().default(''),\n value: z.coerce.string().default(''),\n enabled: z.boolean().default(true),\n file: z.any().optional(),\n description: z.string().optional(),\n required: z.boolean().optional(),\n enum: z.array(z.string()).optional(),\n examples: z.array(z.any()).optional(),\n type: z\n .union([\n // 'string'\n z.string(),\n // ['string', 'null']\n z.array(z.string()),\n ])\n .optional(),\n format: z.string().optional(),\n minimum: z.number().optional(),\n maximum: z.number().optional(),\n default: z.any().optional(),\n nullable: z.boolean().optional(),\n })\n // set nullable: to true if type is ['string', 'null']\n .transform((_data) => {\n const data = { ..._data }\n\n // type: ['string', 'null'] -> nullable: true\n if (Array.isArray(data.type) && data.type.includes('null')) {\n data.nullable = true\n }\n\n // Hey, if it's just one value and 'null', we can make it a string and ditch the 'null'.\n if (Array.isArray(data.type) && data.type.length === 2 && data.type.includes('null')) {\n data.type = data.type.find((item) => item !== 'null')\n }\n\n return data\n })\n\n/** Convert the array of parameters to an object keyed by the parameter name */\nexport const parameterArrayToObject = (params: RequestExampleParameter[]) =>\n params.reduce<Record<string, string>>((map, param) => {\n map[param.key] = param.value\n return map\n }, {})\n\n/** Request examples - formerly known as instances - are \"children\" of requests */\nexport type RequestExampleParameter = z.infer<typeof requestExampleParametersSchema>\n\nexport const xScalarFileValueSchema = z\n .object({\n url: z.string(),\n base64: z.string().optional(),\n })\n .nullable()\n\n/**\n * When files are required for an example we provide the options\n * to provide a public URL or a base64 encoded string\n */\nexport type XScalarFileValue = z.infer<typeof xScalarFileValueSchema>\n\n/**\n * Schema for the OAS serialization of request example parameters\n *\n * File values can be optionally fetched on import OR inserted as a base64 encoded string\n */\nexport const xScalarFormDataValue = z.union([\n z.object({\n type: z.literal('string'),\n value: z.string(),\n }),\n z.object({\n type: z.literal('file'),\n file: xScalarFileValueSchema,\n }),\n])\n\nexport type XScalarFormDataValue = z.infer<typeof xScalarFormDataValue>\n\n// ---------------------------------------------------------------------------\n// Example Body\n\n/**\n * Possible encodings for example request bodies when using text formats\n *\n * TODO: This list may not be comprehensive enough\n */\nexport const exampleRequestBodyEncoding = ['json', 'text', 'html', 'javascript', 'xml', 'yaml', 'edn'] as const\n\nexport type BodyEncoding = (typeof exampleRequestBodyEncoding)[number]\n\nexport const exampleBodyMime = [\n 'application/json',\n 'text/plain',\n 'text/html',\n 'application/javascript',\n 'application/xml',\n 'application/yaml',\n 'application/edn',\n 'application/octet-stream',\n 'application/x-www-form-urlencoded',\n 'multipart/form-data',\n /** Used for direct files */\n 'binary',\n] as const\n\nexport type BodyMime = (typeof exampleBodyMime)[number]\n\nconst contentMapping: Record<BodyEncoding, BodyMime> = {\n json: 'application/json',\n text: 'text/plain',\n html: 'text/html',\n javascript: 'application/javascript',\n xml: 'application/xml',\n yaml: 'application/yaml',\n edn: 'application/edn',\n} as const\n\n/**\n * TODO: Migrate away from this layout to the format used in the extension\n *\n * If a user changes the encoding of the body we expect the content to change as well\n */\nexport const exampleRequestBodySchema = z.object({\n raw: z\n .object({\n encoding: z.enum(exampleRequestBodyEncoding),\n value: z.string().default(''),\n mimeType: z.string().optional(),\n })\n .optional(),\n formData: z\n .object({\n encoding: z.union([z.literal('form-data'), z.literal('urlencoded')]).default('form-data'),\n value: requestExampleParametersSchema.array().default([]),\n })\n .optional(),\n binary: z.instanceof(Blob).optional(),\n activeBody: z.union([z.literal('raw'), z.literal('formData'), z.literal('binary')]).default('raw'),\n})\n\nexport type ExampleRequestBody = z.infer<typeof exampleRequestBodySchema>\n\n/** Schema for the OAS serialization of request example bodies */\nexport const xScalarExampleBodySchema = z.object({\n encoding: z.enum(exampleBodyMime),\n /**\n * Body content as an object with a separately specified encoding or a simple pre-encoded string value\n *\n * Ideally we would convert any objects into the proper encoding on import\n */\n content: z.union([z.record(z.string(), z.any()), z.string()]),\n /** When the encoding is `binary` this will be used to link to the file */\n file: xScalarFileValueSchema.optional(),\n})\n\nexport type XScalarExampleBody = z.infer<typeof xScalarExampleBodySchema>\n\n// ---------------------------------------------------------------------------\n// Example Schema\n\nexport const requestExampleSchema = z.object({\n uid: nanoidSchema.brand<ENTITY_BRANDS['EXAMPLE']>(),\n type: z.literal('requestExample').optional().default('requestExample'),\n requestUid: z.string().brand<ENTITY_BRANDS['OPERATION']>().optional(),\n name: z.string().optional().default('Name'),\n body: exampleRequestBodySchema.optional().default({}),\n parameters: z\n .object({\n path: requestExampleParametersSchema.array().default([]),\n query: requestExampleParametersSchema.array().default([]),\n headers: requestExampleParametersSchema.array().default([{ key: 'Accept', value: '*/*', enabled: true }]),\n cookies: requestExampleParametersSchema.array().default([]),\n })\n .optional()\n .default({}),\n /** TODO: Should this be deprecated? */\n serverVariables: z.record(z.string(), z.array(z.string())).optional(),\n})\n\nexport type RequestExample = z.infer<typeof requestExampleSchema>\n\n/** For OAS serialization we just store the simple key/value pairs */\nconst xScalarExampleParameterSchema = z.record(z.string(), z.string()).optional()\n\n/** Schema for the OAS serialization of request examples */\nexport const xScalarExampleSchema = z.object({\n /** TODO: Should this be required? */\n name: z.string().optional(),\n body: xScalarExampleBodySchema.optional(),\n parameters: z.object({\n path: xScalarExampleParameterSchema,\n query: xScalarExampleParameterSchema,\n headers: xScalarExampleParameterSchema,\n cookies: xScalarExampleParameterSchema,\n }),\n})\n\nexport type XScalarExample = z.infer<typeof xScalarExampleSchema>\n\n/**\n * Convert a request example to the xScalar serialized format\n *\n * TODO: The base format should be migrated to align MUCH closer to the serialized format\n */\nexport function convertExampleToXScalar(example: RequestExample) {\n const active = example.body?.activeBody\n\n const xScalarBody: XScalarExampleBody = {\n encoding: 'text/plain',\n content: '',\n }\n\n if (example.body?.activeBody === 'binary') {\n xScalarBody.encoding = 'binary'\n // TODO: Need to allow users to set these properties\n xScalarBody.file = null\n }\n\n if (active === 'formData' && example.body?.[active]) {\n const body = example.body[active]\n xScalarBody.encoding = body.encoding === 'form-data' ? 'multipart/form-data' : 'application/x-www-form-urlencoded'\n\n // TODO: Need to allow users to set these properties\n xScalarBody.content = body.value.reduce<Record<string, XScalarFormDataValue>>((map, param) => {\n /** TODO: We need to ensure only file or value is set */\n map[param.key] = param.file\n ? {\n type: 'file',\n file: null,\n }\n : {\n type: 'string',\n value: param.value,\n }\n return map\n }, {})\n }\n\n if (example.body?.activeBody === 'raw') {\n xScalarBody.encoding = contentMapping[example.body.raw?.encoding ?? 'text'] ?? 'text/plain'\n\n xScalarBody.content = example.body.raw?.value ?? ''\n }\n\n const parameters: XScalarExample['parameters'] = {}\n\n keysOf(example.parameters ?? {}).forEach((key) => {\n if (example.parameters?.[key].length) {\n parameters[key] = parameterArrayToObject(example.parameters[key])\n }\n })\n\n return xScalarExampleSchema.parse({\n /** Only add the body if we have content or the body should be a file */\n body: xScalarBody.content || xScalarBody.encoding === 'binary' ? xScalarBody : undefined,\n parameters,\n })\n}\n\n// ---------------------------------------------------------------------------\n// Example Helpers\n\n/** Create new instance parameter from a request parameter */\nexport function createParamInstance(param: RequestParameter) {\n const schema = param.schema as any\n\n const firstExample = (() => {\n if (param.examples && !Array.isArray(param.examples) && objectKeys(param.examples).length > 0) {\n const exampleValues = Object.entries(param.examples).map(([_, example]) => {\n // returns the external value if it exists\n if (example.externalValue) {\n return example.externalValue\n }\n\n // returns the value if it exists and is defined\n // e.g. { examples: { foo: { value: 'bar' } } } would return ['bar']\n return example.value\n })\n\n // returns the first example as selected value along other examples\n return { value: exampleValues[0], examples: exampleValues }\n }\n\n // param example e.g. { example: 'foo' }\n if (isDefined(param.example)) {\n return { value: param.example }\n }\n\n // param examples e.g. { examples: ['foo', 'bar'] }\n if (Array.isArray(param.examples) && param.examples.length > 0) {\n return { value: param.examples[0] }\n }\n\n // schema example e.g. { example: 'foo' } while being discouraged\n // see https://spec.openapis.org/oas/v3.1.1.html#fixed-fields-20\n if (isDefined(schema?.example)) {\n return { value: schema.example }\n }\n\n // schema examples e.g. { examples: ['foo', 'bar'] }\n if (Array.isArray(schema?.examples) && schema.examples.length > 0) {\n // For boolean type, default to false when using schema examples\n if (schema?.type === 'boolean') {\n return { value: schema.default ?? false }\n }\n return { value: schema.examples[0] }\n }\n\n // content examples e.g. { content: { 'application/json': { examples: { foo: { value: 'bar' } } } } }\n if (param.content) {\n const firstContentType = objectKeys(param.content)[0]\n if (firstContentType) {\n const content = (param.content as ParameterContent)[firstContentType]\n if (content?.examples) {\n const firstExampleKey = Object.keys(content.examples)[0]\n if (firstExampleKey) {\n const example = content.examples[firstExampleKey]\n if (isDefined(example?.value)) {\n return { value: example.value }\n }\n }\n }\n // content example e.g. { example: 'foo' }\n if (isDefined(content?.example)) {\n return { value: content.example }\n }\n }\n }\n\n return null\n })() as null | { value: any; examples?: string[] }\n\n /**\n * TODO:\n * - Need better value defaulting here\n * - Need to handle non-string parameters much better\n * - Need to handle unions/array values for schema\n */\n const value = String(firstExample?.value ?? schema?.default ?? '')\n\n // Handle non-string enums and enums within items for array types\n const parseEnum = (() => {\n if (schema?.enum && schema?.type !== 'string') {\n return schema.enum?.map(String)\n }\n\n if (schema?.items?.enum && schema?.type === 'array') {\n return schema.items.enum.map(String)\n }\n\n return schema?.enum\n })()\n\n // Handle parameter examples\n const examples =\n firstExample?.examples ||\n (schema?.examples && schema?.type !== 'string' ? schema.examples?.map(String) : schema?.examples)\n\n // safe parse the example\n const example = schemaModel(\n {\n ...schema,\n key: param.name,\n value,\n description: param.description,\n required: param.required,\n /** Initialized all required properties to enabled */\n enabled: !!param.required,\n enum: parseEnum,\n examples,\n },\n requestExampleParametersSchema,\n false,\n )\n\n if (!example) {\n console.warn(`Example at ${param.name} is invalid.`)\n return requestExampleParametersSchema.parse({})\n }\n\n return example\n}\n\n/**\n * Create new request example from a request\n * Iterates the name of the example if provided\n */\nexport function createExampleFromRequest(request: Request, name: string, server?: Server): RequestExample {\n // ---------------------------------------------------------------------------\n // Populate all parameters with an example value\n const parameters: Record<'path' | 'cookie' | 'header' | 'query' | 'headers', RequestExampleParameter[]> = {\n path: [],\n query: [],\n cookie: [],\n // deprecated TODO: add zod transform to remove\n header: [],\n headers: [{ key: 'Accept', value: '*/*', enabled: true }],\n }\n\n // Populated the separated params\n request.parameters?.forEach((p) => parameters[p.in].push(createParamInstance(p)))\n\n // TODO: add zod transform to remove header and only support headers\n if (parameters.header.length > 0) {\n parameters.headers = parameters.header\n parameters.header = []\n }\n\n // Get content type header\n const contentTypeHeader = parameters.headers.find((h) => h.key.toLowerCase() === 'content-type')\n\n // ---------------------------------------------------------------------------\n // Handle request body defaulting for various content type encodings\n const body: ExampleRequestBody = {\n activeBody: 'raw',\n }\n\n // If we have a request body or a content type header\n // TODO: we don't even handle path parameters here\n if (request.requestBody || contentTypeHeader?.value) {\n const requestBody = getRequestBodyFromOperation(request)\n\n const contentType = request.requestBody ? requestBody?.mimeType : contentTypeHeader?.value\n\n // Handle JSON and JSON-like mimetypes\n if (contentType?.includes('/json') || contentType?.endsWith('+json')) {\n body.activeBody = 'raw'\n body.raw = {\n encoding: 'json',\n mimeType: contentType,\n value: requestBody?.text ?? JSON.stringify({}),\n }\n }\n\n if (contentType === 'application/xml') {\n body.activeBody = 'raw'\n body.raw = {\n encoding: 'xml',\n value: requestBody?.text ?? '',\n }\n }\n\n /**\n * TODO: Are we loading example files from somewhere based on the spec?\n * How are we handling the body values\n */\n if (contentType === 'application/octet-stream') {\n body.activeBody = 'binary'\n body.binary = undefined\n }\n\n if (contentType === 'application/x-www-form-urlencoded' || contentType === 'multipart/form-data') {\n body.activeBody = 'formData'\n body.formData = {\n encoding: contentType === 'application/x-www-form-urlencoded' ? 'urlencoded' : 'form-data',\n value: (requestBody?.params || []).map((param) => {\n if (param.value instanceof File) {\n return {\n key: param.name,\n value: 'BINARY',\n file: param.value,\n enabled: true,\n }\n }\n return {\n key: param.name,\n value: param.value || '',\n enabled: true,\n }\n }),\n }\n }\n\n // Add the content-type header if it doesn't exist and if it's not multipart request\n if (requestBody?.mimeType && !contentTypeHeader && !requestBody.mimeType.startsWith('multipart/')) {\n parameters.headers.push({\n key: 'Content-Type',\n value: requestBody.mimeType,\n enabled: true,\n })\n }\n }\n\n const serverVariables = server ? getServerVariableExamples(server) : {}\n\n // safe parse the example\n const example = schemaModel(\n {\n requestUid: request.uid,\n parameters,\n name,\n body,\n serverVariables,\n },\n requestExampleSchema,\n false,\n )\n\n if (!example) {\n console.warn(`Example at ${request.uid} is invalid.`)\n return requestExampleSchema.parse({})\n }\n return example\n}\n"],
5
- "m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;AAAA,QACV,OAAO,aAAa,QAAQ;AAAA,MAC9B;AAAA,IACF;AAMA,QAAI,gBAAgB,4BAA4B;AAC9C,WAAK,aAAa;AAClB,WAAK,SAAS;AAAA,IAChB;AAEA,QAAI,gBAAgB,uCAAuC,gBAAgB,uBAAuB;AAChG,WAAK,aAAa;AAClB,WAAK,WAAW;AAAA,QACd,UAAU,gBAAgB,sCAAsC,eAAe;AAAA,QAC/E,QAAQ,aAAa,UAAU,CAAC,GAAG,IAAI,CAAC,UAAU;AAChD,cAAI,MAAM,iBAAiB,MAAM;AAC/B,mBAAO;AAAA,cACL,KAAK,MAAM;AAAA,cACX,OAAO;AAAA,cACP,MAAM,MAAM;AAAA,cACZ,SAAS;AAAA,YACX;AAAA,UACF;AACA,iBAAO;AAAA,YACL,KAAK,MAAM;AAAA,YACX,OAAO,MAAM,SAAS;AAAA,YACtB,SAAS;AAAA,UACX;AAAA,QACF,CAAC;AAAA,MACH;AAAA,IACF;AAGA,QAAI,aAAa,YAAY,CAAC,qBAAqB,CAAC,YAAY,SAAS,WAAW,YAAY,GAAG;AACjG,iBAAW,QAAQ,KAAK;AAAA,QACtB,KAAK;AAAA,QACL,OAAO,YAAY;AAAA,QACnB,SAAS;AAAA,MACX,CAAC;AAAA,IACH;AAAA,EACF;AAEA,QAAM,kBAAkB,SAAS,0BAA0B,MAAM,IAAI,CAAC;AAGtE,QAAM,UAAU;AAAA,IACd;AAAA,MACE,YAAY,QAAQ;AAAA,MACpB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,MAAI,CAAC,SAAS;AACZ,YAAQ,KAAK,cAAc,QAAQ,GAAG,cAAc;AACpD,WAAO,qBAAqB,MAAM,CAAC,CAAC;AAAA,EACtC;AACA,SAAO;AACT;",
4
+ "sourcesContent": ["import { schemaModel } from '@/helpers/schema-model'\nimport { getServerVariableExamples } from '@/spec-getters/get-server-variable-examples'\nimport { keysOf } from '@scalar/object-utils/arrays'\nimport { type ENTITY_BRANDS, nanoidSchema } from '@scalar/types/utils'\nimport { z } from 'zod'\n\nimport { getRequestBodyFromOperation } from '@/spec-getters/get-request-body-from-operation'\nimport { isDefined } from '@scalar/helpers/array/is-defined'\nimport { objectKeys } from '@scalar/helpers/object/object-keys'\nimport type { ParameterContent, RequestParameter } from './parameters'\nimport type { Request } from './requests'\nimport type { Server } from './server'\n\n// ---------------------------------------------------------------------------\n// Example Parameters\n\n/**\n * TODO: Deprecate this.\n *\n * The request schema should be stored in the request and any\n * parameters should be validated against that\n */\nexport const requestExampleParametersSchema = z\n .object({\n key: z.string().default(''),\n value: z.coerce.string().default(''),\n enabled: z.boolean().default(true),\n file: z.any().optional(),\n description: z.string().optional(),\n required: z.boolean().optional(),\n enum: z.array(z.string()).optional(),\n examples: z.array(z.any()).optional(),\n type: z\n .union([\n // 'string'\n z.string(),\n // ['string', 'null']\n z.array(z.string()),\n ])\n .optional(),\n format: z.string().optional(),\n minimum: z.number().optional(),\n maximum: z.number().optional(),\n default: z.any().optional(),\n nullable: z.boolean().optional(),\n })\n // set nullable: to true if type is ['string', 'null']\n .transform((_data) => {\n const data = { ..._data }\n\n // type: ['string', 'null'] -> nullable: true\n if (Array.isArray(data.type) && data.type.includes('null')) {\n data.nullable = true\n }\n\n // Hey, if it's just one value and 'null', we can make it a string and ditch the 'null'.\n if (Array.isArray(data.type) && data.type.length === 2 && data.type.includes('null')) {\n data.type = data.type.find((item) => item !== 'null')\n }\n\n return data\n })\n\n/** Convert the array of parameters to an object keyed by the parameter name */\nexport const parameterArrayToObject = (params: RequestExampleParameter[]) =>\n params.reduce<Record<string, string>>((map, param) => {\n map[param.key] = param.value\n return map\n }, {})\n\n/** Request examples - formerly known as instances - are \"children\" of requests */\nexport type RequestExampleParameter = z.infer<typeof requestExampleParametersSchema>\n\nexport const xScalarFileValueSchema = z\n .object({\n url: z.string(),\n base64: z.string().optional(),\n })\n .nullable()\n\n/**\n * When files are required for an example we provide the options\n * to provide a public URL or a base64 encoded string\n */\nexport type XScalarFileValue = z.infer<typeof xScalarFileValueSchema>\n\n/**\n * Schema for the OAS serialization of request example parameters\n *\n * File values can be optionally fetched on import OR inserted as a base64 encoded string\n */\nexport const xScalarFormDataValue = z.union([\n z.object({\n type: z.literal('string'),\n value: z.string(),\n }),\n z.object({\n type: z.literal('file'),\n file: xScalarFileValueSchema,\n }),\n])\n\nexport type XScalarFormDataValue = z.infer<typeof xScalarFormDataValue>\n\n// ---------------------------------------------------------------------------\n// Example Body\n\n/**\n * Possible encodings for example request bodies when using text formats\n *\n * TODO: This list may not be comprehensive enough\n */\nexport const exampleRequestBodyEncoding = ['json', 'text', 'html', 'javascript', 'xml', 'yaml', 'edn'] as const\n\nexport type BodyEncoding = (typeof exampleRequestBodyEncoding)[number]\n\nexport const exampleBodyMime = [\n 'application/json',\n 'text/plain',\n 'text/html',\n 'application/javascript',\n 'application/xml',\n 'application/yaml',\n 'application/edn',\n 'application/octet-stream',\n 'application/x-www-form-urlencoded',\n 'multipart/form-data',\n /** Used for direct files */\n 'binary',\n] as const\n\nexport type BodyMime = (typeof exampleBodyMime)[number]\n\nconst contentMapping: Record<BodyEncoding, BodyMime> = {\n json: 'application/json',\n text: 'text/plain',\n html: 'text/html',\n javascript: 'application/javascript',\n xml: 'application/xml',\n yaml: 'application/yaml',\n edn: 'application/edn',\n} as const\n\n/**\n * TODO: Migrate away from this layout to the format used in the extension\n *\n * If a user changes the encoding of the body we expect the content to change as well\n */\nexport const exampleRequestBodySchema = z.object({\n raw: z\n .object({\n encoding: z.enum(exampleRequestBodyEncoding),\n value: z.string().default(''),\n mimeType: z.string().optional(),\n })\n .optional(),\n formData: z\n .object({\n encoding: z.union([z.literal('form-data'), z.literal('urlencoded')]).default('form-data'),\n value: requestExampleParametersSchema.array().default([]),\n })\n .optional(),\n binary: z.instanceof(Blob).optional(),\n activeBody: z.union([z.literal('raw'), z.literal('formData'), z.literal('binary')]).default('raw'),\n})\n\nexport type ExampleRequestBody = z.infer<typeof exampleRequestBodySchema>\n\n/** Schema for the OAS serialization of request example bodies */\nexport const xScalarExampleBodySchema = z.object({\n encoding: z.enum(exampleBodyMime),\n /**\n * Body content as an object with a separately specified encoding or a simple pre-encoded string value\n *\n * Ideally we would convert any objects into the proper encoding on import\n */\n content: z.union([z.record(z.string(), z.any()), z.string()]),\n /** When the encoding is `binary` this will be used to link to the file */\n file: xScalarFileValueSchema.optional(),\n})\n\nexport type XScalarExampleBody = z.infer<typeof xScalarExampleBodySchema>\n\n// ---------------------------------------------------------------------------\n// Example Schema\n\nexport const requestExampleSchema = z.object({\n uid: nanoidSchema.brand<ENTITY_BRANDS['EXAMPLE']>(),\n type: z.literal('requestExample').optional().default('requestExample'),\n requestUid: z.string().brand<ENTITY_BRANDS['OPERATION']>().optional(),\n name: z.string().optional().default('Name'),\n body: exampleRequestBodySchema.optional().default({}),\n parameters: z\n .object({\n path: requestExampleParametersSchema.array().default([]),\n query: requestExampleParametersSchema.array().default([]),\n headers: requestExampleParametersSchema.array().default([{ key: 'Accept', value: '*/*', enabled: true }]),\n cookies: requestExampleParametersSchema.array().default([]),\n })\n .optional()\n .default({}),\n /** TODO: Should this be deprecated? */\n serverVariables: z.record(z.string(), z.array(z.string())).optional(),\n})\n\nexport type RequestExample = z.infer<typeof requestExampleSchema>\n\n/** For OAS serialization we just store the simple key/value pairs */\nconst xScalarExampleParameterSchema = z.record(z.string(), z.string()).optional()\n\n/** Schema for the OAS serialization of request examples */\nexport const xScalarExampleSchema = z.object({\n /** TODO: Should this be required? */\n name: z.string().optional(),\n body: xScalarExampleBodySchema.optional(),\n parameters: z.object({\n path: xScalarExampleParameterSchema,\n query: xScalarExampleParameterSchema,\n headers: xScalarExampleParameterSchema,\n cookies: xScalarExampleParameterSchema,\n }),\n})\n\nexport type XScalarExample = z.infer<typeof xScalarExampleSchema>\n\n/**\n * Convert a request example to the xScalar serialized format\n *\n * TODO: The base format should be migrated to align MUCH closer to the serialized format\n */\nexport function convertExampleToXScalar(example: RequestExample) {\n const active = example.body?.activeBody\n\n const xScalarBody: XScalarExampleBody = {\n encoding: 'text/plain',\n content: '',\n }\n\n if (example.body?.activeBody === 'binary') {\n xScalarBody.encoding = 'binary'\n // TODO: Need to allow users to set these properties\n xScalarBody.file = null\n }\n\n if (active === 'formData' && example.body?.[active]) {\n const body = example.body[active]\n xScalarBody.encoding = body.encoding === 'form-data' ? 'multipart/form-data' : 'application/x-www-form-urlencoded'\n\n // TODO: Need to allow users to set these properties\n xScalarBody.content = body.value.reduce<Record<string, XScalarFormDataValue>>((map, param) => {\n /** TODO: We need to ensure only file or value is set */\n map[param.key] = param.file\n ? {\n type: 'file',\n file: null,\n }\n : {\n type: 'string',\n value: param.value,\n }\n return map\n }, {})\n }\n\n if (example.body?.activeBody === 'raw') {\n xScalarBody.encoding = contentMapping[example.body.raw?.encoding ?? 'text'] ?? 'text/plain'\n\n xScalarBody.content = example.body.raw?.value ?? ''\n }\n\n const parameters: XScalarExample['parameters'] = {}\n\n keysOf(example.parameters ?? {}).forEach((key) => {\n if (example.parameters?.[key].length) {\n parameters[key] = parameterArrayToObject(example.parameters[key])\n }\n })\n\n return xScalarExampleSchema.parse({\n /** Only add the body if we have content or the body should be a file */\n body: xScalarBody.content || xScalarBody.encoding === 'binary' ? xScalarBody : undefined,\n parameters,\n })\n}\n\n// ---------------------------------------------------------------------------\n// Example Helpers\n\n/** Create new instance parameter from a request parameter */\nexport function createParamInstance(param: RequestParameter) {\n const schema = param.schema as any\n\n const firstExample = (() => {\n if (param.examples && !Array.isArray(param.examples) && objectKeys(param.examples).length > 0) {\n const exampleValues = Object.entries(param.examples).map(([_, example]) => {\n // returns the external value if it exists\n if (example.externalValue) {\n return example.externalValue\n }\n\n // returns the value if it exists and is defined\n // e.g. { examples: { foo: { value: 'bar' } } } would return ['bar']\n return example.value\n })\n\n // returns the first example as selected value along other examples\n return { value: exampleValues[0], examples: exampleValues }\n }\n\n // param example e.g. { example: 'foo' }\n if (isDefined(param.example)) {\n return { value: param.example }\n }\n\n // param examples e.g. { examples: ['foo', 'bar'] }\n if (Array.isArray(param.examples) && param.examples.length > 0) {\n return { value: param.examples[0] }\n }\n\n // schema example e.g. { example: 'foo' } while being discouraged\n // see https://spec.openapis.org/oas/v3.1.1.html#fixed-fields-20\n if (isDefined(schema?.example)) {\n return { value: schema.example }\n }\n\n // schema examples e.g. { examples: ['foo', 'bar'] }\n if (Array.isArray(schema?.examples) && schema.examples.length > 0) {\n // For boolean type, default to false when using schema examples\n if (schema?.type === 'boolean') {\n return { value: schema.default ?? false }\n }\n return { value: schema.examples[0] }\n }\n\n // content examples e.g. { content: { 'application/json': { examples: { foo: { value: 'bar' } } } } }\n if (param.content) {\n const firstContentType = objectKeys(param.content)[0]\n if (firstContentType) {\n const content = (param.content as ParameterContent)[firstContentType]\n if (content?.examples) {\n const firstExampleKey = Object.keys(content.examples)[0]\n if (firstExampleKey) {\n const example = content.examples[firstExampleKey]\n if (isDefined(example?.value)) {\n return { value: example.value }\n }\n }\n }\n // content example e.g. { example: 'foo' }\n if (isDefined(content?.example)) {\n return { value: content.example }\n }\n }\n }\n\n return null\n })() as null | { value: any; examples?: string[] }\n\n /**\n * TODO:\n * - Need better value defaulting here\n * - Need to handle non-string parameters much better\n * - Need to handle unions/array values for schema\n */\n const value = String(firstExample?.value ?? schema?.default ?? '')\n\n // Handle non-string enums and enums within items for array types\n const parseEnum = (() => {\n if (schema?.enum && schema?.type !== 'string') {\n return schema.enum?.map(String)\n }\n\n if (schema?.items?.enum && schema?.type === 'array') {\n return schema.items.enum.map(String)\n }\n\n return schema?.enum\n })()\n\n // Handle parameter examples\n const examples =\n firstExample?.examples ||\n (schema?.examples && schema?.type !== 'string' ? schema.examples?.map(String) : schema?.examples)\n\n // safe parse the example\n const example = schemaModel(\n {\n ...schema,\n key: param.name,\n value,\n description: param.description,\n required: param.required,\n /** Initialized all required properties to enabled */\n enabled: !!param.required,\n enum: parseEnum,\n examples,\n },\n requestExampleParametersSchema,\n false,\n )\n\n if (!example) {\n console.warn(`Example at ${param.name} is invalid.`)\n return requestExampleParametersSchema.parse({})\n }\n\n return example\n}\n\n/**\n * Create new request example from a request\n * Iterates the name of the example if provided\n */\nexport function createExampleFromRequest(request: Request, name: string, server?: Server): RequestExample {\n // ---------------------------------------------------------------------------\n // Populate all parameters with an example value\n const parameters: Record<'path' | 'cookie' | 'header' | 'query' | 'headers', RequestExampleParameter[]> = {\n path: [],\n query: [],\n cookie: [],\n // deprecated TODO: add zod transform to remove\n header: [],\n headers: [{ key: 'Accept', value: '*/*', enabled: true }],\n }\n\n // Populated the separated params\n request.parameters?.forEach((p) => parameters[p.in].push(createParamInstance(p)))\n\n // TODO: add zod transform to remove header and only support headers\n if (parameters.header.length > 0) {\n parameters.headers = parameters.header\n parameters.header = []\n }\n\n // Get content type header\n const contentTypeHeader = parameters.headers.find((h) => h.key.toLowerCase() === 'content-type')\n\n // ---------------------------------------------------------------------------\n // Handle request body defaulting for various content type encodings\n const body: ExampleRequestBody = {\n activeBody: 'raw',\n }\n\n // If we have a request body or a content type header\n // TODO: we don't even handle path parameters here\n if (request.requestBody || contentTypeHeader?.value) {\n const requestBody = getRequestBodyFromOperation(request)\n const contentType = request.requestBody ? requestBody?.mimeType : contentTypeHeader?.value\n\n // Handle JSON and JSON-like mimetypes\n if (contentType?.includes('/json') || contentType?.endsWith('+json')) {\n body.activeBody = 'raw'\n body.raw = {\n encoding: 'json',\n mimeType: contentType,\n value: requestBody?.text ?? JSON.stringify({}),\n }\n }\n\n if (contentType === 'application/xml') {\n body.activeBody = 'raw'\n body.raw = {\n encoding: 'xml',\n value: requestBody?.text ?? '',\n }\n }\n\n /**\n * TODO: Are we loading example files from somewhere based on the spec?\n * How are we handling the body values\n */\n if (contentType === 'application/octet-stream') {\n body.activeBody = 'binary'\n body.binary = undefined\n }\n\n if (contentType === 'application/x-www-form-urlencoded' || contentType === 'multipart/form-data') {\n body.activeBody = 'formData'\n body.formData = {\n encoding: contentType === 'application/x-www-form-urlencoded' ? 'urlencoded' : 'form-data',\n value: (requestBody?.params || []).map((param) => {\n if (param.value instanceof File) {\n return {\n key: param.name,\n value: 'BINARY',\n file: param.value,\n enabled: true,\n }\n }\n return {\n key: param.name,\n value: param.value || '',\n enabled: true,\n }\n }),\n }\n }\n\n // Add the content-type header if it doesn't exist and if it's not multipart request\n if (requestBody?.mimeType && !contentTypeHeader && !requestBody.mimeType.startsWith('multipart/')) {\n parameters.headers.push({\n key: 'Content-Type',\n value: requestBody.mimeType,\n enabled: true,\n })\n }\n }\n\n const serverVariables = server ? getServerVariableExamples(server) : {}\n\n // safe parse the example\n const example = schemaModel(\n {\n requestUid: request.uid,\n parameters,\n name,\n body,\n serverVariables,\n },\n requestExampleSchema,\n false,\n )\n\n if (!example) {\n console.warn(`Example at ${request.uid} is invalid.`)\n return requestExampleSchema.parse({})\n }\n return example\n}\n"],
5
+ "mappings": "AAAA,SAAS,mBAAmB;AAC5B,SAAS,iCAAiC;AAC1C,SAAS,cAAc;AACvB,SAA6B,oBAAoB;AACjD,SAAS,SAAS;AAElB,SAAS,mCAAmC;AAC5C,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AAcpB,MAAM,iCAAiC,EAC3C,OAAO;AAAA,EACN,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE;AAAA,EAC1B,OAAO,EAAE,OAAO,OAAO,EAAE,QAAQ,EAAE;AAAA,EACnC,SAAS,EAAE,QAAQ,EAAE,QAAQ,IAAI;AAAA,EACjC,MAAM,EAAE,IAAI,EAAE,SAAS;AAAA,EACvB,aAAa,EAAE,OAAO,EAAE,SAAS;AAAA,EACjC,UAAU,EAAE,QAAQ,EAAE,SAAS;AAAA,EAC/B,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,SAAS;AAAA,EACnC,UAAU,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,SAAS;AAAA,EACpC,MAAM,EACH,MAAM;AAAA;AAAA,IAEL,EAAE,OAAO;AAAA;AAAA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BAAW,QAAQ,KAAK;AAAA,QACtB,KAAK;AAAA,QACL,OAAO,YAAY;AAAA,QACnB,SAAS;AAAA,MACX,CAAC;AAAA,IACH;AAAA,EACF;AAEA,QAAM,kBAAkB,SAAS,0BAA0B,MAAM,IAAI,CAAC;AAGtE,QAAM,UAAU;AAAA,IACd;AAAA,MACE,YAAY,QAAQ;AAAA,MACpB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,MAAI,CAAC,SAAS;AACZ,YAAQ,KAAK,cAAc,QAAQ,GAAG,cAAc;AACpD,WAAO,qBAAqB,MAAM,CAAC,CAAC;AAAA,EACtC;AACA,SAAO;AACT;",
6
6
  "names": ["example"]
7
7
  }
@@ -8,6 +8,7 @@ export { shouldUseProxy, redirectToProxy } from './redirect-to-proxy.js';
8
8
  export { schemaModel } from './schema-model.js';
9
9
  export { shouldIgnoreEntity } from './should-ignore-entity.js';
10
10
  export { isOperationDeprecated, getOperationStability, getOperationStabilityColor } from './operation-stability.js';
11
+ export { getServersFromDocument } from './servers.js';
11
12
  /**
12
13
  * @deprecated These helpers are being phased out. Please import directly from @scalar/helpers instead.
13
14
  * For example: import { createHash } from '/@scalar/helpers/string/create-hash'
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAChD,OAAO,EAAE,KAAK,6BAA6B,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAA;AACxG,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AACzD,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAA;AACtE,OAAO,EAAE,sBAAsB,EAAE,YAAY,EAAE,IAAI,EAAE,eAAe,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC5G,OAAO,EAAE,eAAe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;AAClG,eAAe,GAChB,MAAM,wCAAwC,CAAA;AAC/C,OAAO;AACL,uFAAuF;AACvF,UAAU,GACX,MAAM,kCAAkC,CAAA;AACzC,OAAO;AACL,6FAA6F;AAC7F,YAAY,GACb,MAAM,sCAAsC,CAAA;AAC7C,OAAO;AACL,iGAAiG;AACjG,eAAe,GAChB,MAAM,uCAAuC,CAAA;AAC9C,OAAO;AACL,4FAA4F;AAC5F,iBAAiB;AACjB,oFAAoF;AACpF,SAAS,GACV,MAAM,gCAAgC,CAAA;AACvC,OAAO;AACL,yFAAyF;AACzF,UAAU,IAAI,aAAa,GAC5B,MAAM,oCAAoC,CAAA;AAC3C,OAAO;AACL,oGAAoG;AACpG,gBAAgB,GACjB,MAAM,yCAAyC,CAAA"}
@@ -8,6 +8,7 @@ import { shouldUseProxy, redirectToProxy } from "./redirect-to-proxy.js";
8
8
  import { schemaModel } from "./schema-model.js";
9
9
  import { shouldIgnoreEntity } from "./should-ignore-entity.js";
10
10
  import { isOperationDeprecated, getOperationStability, getOperationStabilityColor } from "./operation-stability.js";
11
+ import { getServersFromDocument } from "./servers.js";
11
12
  import {
12
13
  createHash
13
14
  } from "@scalar/helpers/string/create-hash";
@@ -92,6 +93,7 @@ export {
92
93
  objectKeys as getObjectKeys,
93
94
  getOperationStability,
94
95
  getOperationStabilityColor,
96
+ getServersFromDocument,
95
97
  httpStatusCodes,
96
98
  isDefined,
97
99
  isHttpMethod,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/helpers/index.ts"],
4
- "sourcesContent": ["export { fetchDocument } from './fetch-document'\nexport { type FetchWithProxyFallbackOptions, fetchWithProxyFallback } from './fetch-with-proxy-fallback'\nexport { normalizeMimeType } from './normalize-mime-type'\nexport { normalizeMimeTypeObject } from './normalize-mime-type-object'\nexport { formatJsonOrYamlString, isJsonString, json, parseJsonOrYaml, transformToJson, yaml } from './parse'\nexport { prettyPrintJson, replaceCircularDependencies } from './pretty-print-json'\nexport { shouldUseProxy, redirectToProxy } from './redirect-to-proxy'\nexport { schemaModel } from './schema-model'\nexport { shouldIgnoreEntity } from './should-ignore-entity'\nexport { isOperationDeprecated, getOperationStability, getOperationStabilityColor } from './operation-stability'\n\n/**\n * @deprecated These helpers are being phased out. Please import directly from @scalar/helpers instead.\n * For example: import { createHash } from '\\@scalar/helpers/string/create-hash'\n */\nexport {\n /** @deprecated Please use createHash from \\@scalar/helpers/string/create-hash instead */\n createHash,\n} from '@scalar/helpers/string/create-hash'\nexport {\n /** @deprecated Please use isDefined from \\@scalar/helpers/array/is-defined instead */\n isDefined,\n} from '@scalar/helpers/array/is-defined'\nexport {\n /** @deprecated Please use isHttpMethod from \\@scalar/helpers/http/is-http-method instead */\n isHttpMethod,\n} from '@scalar/helpers/http/is-http-method'\nexport {\n /** @deprecated Please use combineUrlAndPath from \\@scalar/helpers/url/merge-urls instead */\n combineUrlAndPath,\n} from '@scalar/helpers/url/merge-urls'\nexport {\n /** @deprecated Please use json2xml from \\@scalar/helpers/file/json2xml instead */\n json2xml,\n} from '@scalar/helpers/file/json2xml'\nexport {\n /** @deprecated Please use capitalize from \\@scalar/helpers/string/capitalize instead */\n capitalize,\n} from '@scalar/helpers/string/capitalize'\nexport {\n /** @deprecated Please use camelToTitleWords from \\@scalar/helpers/string/camel-to-title instead */\n camelToTitleWords,\n} from '@scalar/helpers/string/camel-to-title'\nexport {\n /** @deprecated Please use REGEX from \\@scalar/helpers/regex/regex-helpers instead */\n REGEX,\n} from '@scalar/helpers/regex/regex-helpers'\nexport {\n /** @deprecated Please use isLocalUrl from \\@scalar/helpers/url/is-local-url instead */\n isLocalUrl,\n} from '@scalar/helpers/url/is-local-url'\nexport {\n /** @deprecated Please use isRelativePath from \\@scalar/helpers/url/is-relative-path instead */\n isRelativePath,\n} from '@scalar/helpers/url/is-relative-path'\nexport {\n /** @deprecated Please use ensureProtocol from \\@scalar/helpers/url/ensure-protocol instead */\n ensureProtocol,\n} from '@scalar/helpers/url/ensure-protocol'\nexport {\n /** @deprecated Please use findVariables from \\@scalar/helpers/regex/find-variables instead */\n findVariables,\n} from '@scalar/helpers/regex/find-variables'\nexport {\n /** @deprecated Please use canMethodHaveBody from \\@scalar/helpers/http/can-method-have-body instead */\n canMethodHaveBody,\n} from '@scalar/helpers/http/can-method-have-body'\nexport {\n /** @deprecated Please use getHttpMethodInfo from \\@scalar/helpers/http/http-info instead */\n getHttpMethodInfo,\n} from '@scalar/helpers/http/http-info'\nexport {\n /** @deprecated Please use REQUEST_METHODS from \\@scalar/helpers/http/http-methods instead */\n REQUEST_METHODS,\n} from '@scalar/helpers/http/http-info'\nexport {\n /** @deprecated Please use HttpStatusCode from \\@scalar/helpers/http/http-status-codes instead */\n type HttpStatusCode,\n /** @deprecated Please use HttpStatusCodes from \\@scalar/helpers/http/http-status-codes instead */\n type HttpStatusCodes,\n /** @deprecated Please use httpStatusCodes from \\@scalar/helpers/http/http-status-codes instead */\n httpStatusCodes,\n} from '@scalar/helpers/http/http-status-codes'\nexport {\n /** @deprecated Please use isValidUrl from \\@scalar/helpers/url/is-valid-url instead */\n isValidUrl,\n} from '@scalar/helpers/url/is-valid-url'\nexport {\n /** @deprecated Please use iterateTitle from \\@scalar/helpers/string/iterate-title instead */\n iterateTitle,\n} from '@scalar/helpers/string/iterate-title'\nexport {\n /** @deprecated Please use makeUrlAbsolute from \\@scalar/helpers/url/make-url-absolute instead */\n makeUrlAbsolute,\n} from '@scalar/helpers/url/make-url-absolute'\nexport {\n /** @deprecated Please use mergeSearchParams from \\@scalar/helpers/url/merge-urls instead */\n mergeSearchParams,\n /** @deprecated Please use mergeUrls from \\@scalar/helpers/url/merge-urls instead */\n mergeUrls,\n} from '@scalar/helpers/url/merge-urls'\nexport {\n /** @deprecated Please use objectKeys from \\@scalar/helpers/object/object-keys instead */\n objectKeys as getObjectKeys,\n} from '@scalar/helpers/object/object-keys'\nexport {\n /** @deprecated Please use replaceVariables from \\@scalar/helpers/regex/replace-variables instead */\n replaceVariables,\n} from '@scalar/helpers/regex/replace-variables'\n"],
5
- "mappings": "AAAA,SAAS,qBAAqB;AAC9B,SAA6C,8BAA8B;AAC3E,SAAS,yBAAyB;AAClC,SAAS,+BAA+B;AACxC,SAAS,wBAAwB,cAAc,MAAM,iBAAiB,iBAAiB,YAAY;AACnG,SAAS,iBAAiB,mCAAmC;AAC7D,SAAS,gBAAgB,uBAAuB;AAChD,SAAS,mBAAmB;AAC5B,SAAS,0BAA0B;AACnC,SAAS,uBAAuB,uBAAuB,kCAAkC;AAMzF;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAME;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,EAEA;AAAA,OACK;AACP;AAAA,EAEgB;AAAA,OACT;AACP;AAAA,EAEE;AAAA,OACK;",
4
+ "sourcesContent": ["export { fetchDocument } from './fetch-document'\nexport { type FetchWithProxyFallbackOptions, fetchWithProxyFallback } from './fetch-with-proxy-fallback'\nexport { normalizeMimeType } from './normalize-mime-type'\nexport { normalizeMimeTypeObject } from './normalize-mime-type-object'\nexport { formatJsonOrYamlString, isJsonString, json, parseJsonOrYaml, transformToJson, yaml } from './parse'\nexport { prettyPrintJson, replaceCircularDependencies } from './pretty-print-json'\nexport { shouldUseProxy, redirectToProxy } from './redirect-to-proxy'\nexport { schemaModel } from './schema-model'\nexport { shouldIgnoreEntity } from './should-ignore-entity'\nexport { isOperationDeprecated, getOperationStability, getOperationStabilityColor } from './operation-stability'\nexport { getServersFromDocument } from './servers'\n\n/**\n * @deprecated These helpers are being phased out. Please import directly from @scalar/helpers instead.\n * For example: import { createHash } from '\\@scalar/helpers/string/create-hash'\n */\nexport {\n /** @deprecated Please use createHash from \\@scalar/helpers/string/create-hash instead */\n createHash,\n} from '@scalar/helpers/string/create-hash'\nexport {\n /** @deprecated Please use isDefined from \\@scalar/helpers/array/is-defined instead */\n isDefined,\n} from '@scalar/helpers/array/is-defined'\nexport {\n /** @deprecated Please use isHttpMethod from \\@scalar/helpers/http/is-http-method instead */\n isHttpMethod,\n} from '@scalar/helpers/http/is-http-method'\nexport {\n /** @deprecated Please use combineUrlAndPath from \\@scalar/helpers/url/merge-urls instead */\n combineUrlAndPath,\n} from '@scalar/helpers/url/merge-urls'\nexport {\n /** @deprecated Please use json2xml from \\@scalar/helpers/file/json2xml instead */\n json2xml,\n} from '@scalar/helpers/file/json2xml'\nexport {\n /** @deprecated Please use capitalize from \\@scalar/helpers/string/capitalize instead */\n capitalize,\n} from '@scalar/helpers/string/capitalize'\nexport {\n /** @deprecated Please use camelToTitleWords from \\@scalar/helpers/string/camel-to-title instead */\n camelToTitleWords,\n} from '@scalar/helpers/string/camel-to-title'\nexport {\n /** @deprecated Please use REGEX from \\@scalar/helpers/regex/regex-helpers instead */\n REGEX,\n} from '@scalar/helpers/regex/regex-helpers'\nexport {\n /** @deprecated Please use isLocalUrl from \\@scalar/helpers/url/is-local-url instead */\n isLocalUrl,\n} from '@scalar/helpers/url/is-local-url'\nexport {\n /** @deprecated Please use isRelativePath from \\@scalar/helpers/url/is-relative-path instead */\n isRelativePath,\n} from '@scalar/helpers/url/is-relative-path'\nexport {\n /** @deprecated Please use ensureProtocol from \\@scalar/helpers/url/ensure-protocol instead */\n ensureProtocol,\n} from '@scalar/helpers/url/ensure-protocol'\nexport {\n /** @deprecated Please use findVariables from \\@scalar/helpers/regex/find-variables instead */\n findVariables,\n} from '@scalar/helpers/regex/find-variables'\nexport {\n /** @deprecated Please use canMethodHaveBody from \\@scalar/helpers/http/can-method-have-body instead */\n canMethodHaveBody,\n} from '@scalar/helpers/http/can-method-have-body'\nexport {\n /** @deprecated Please use getHttpMethodInfo from \\@scalar/helpers/http/http-info instead */\n getHttpMethodInfo,\n} from '@scalar/helpers/http/http-info'\nexport {\n /** @deprecated Please use REQUEST_METHODS from \\@scalar/helpers/http/http-methods instead */\n REQUEST_METHODS,\n} from '@scalar/helpers/http/http-info'\nexport {\n /** @deprecated Please use HttpStatusCode from \\@scalar/helpers/http/http-status-codes instead */\n type HttpStatusCode,\n /** @deprecated Please use HttpStatusCodes from \\@scalar/helpers/http/http-status-codes instead */\n type HttpStatusCodes,\n /** @deprecated Please use httpStatusCodes from \\@scalar/helpers/http/http-status-codes instead */\n httpStatusCodes,\n} from '@scalar/helpers/http/http-status-codes'\nexport {\n /** @deprecated Please use isValidUrl from \\@scalar/helpers/url/is-valid-url instead */\n isValidUrl,\n} from '@scalar/helpers/url/is-valid-url'\nexport {\n /** @deprecated Please use iterateTitle from \\@scalar/helpers/string/iterate-title instead */\n iterateTitle,\n} from '@scalar/helpers/string/iterate-title'\nexport {\n /** @deprecated Please use makeUrlAbsolute from \\@scalar/helpers/url/make-url-absolute instead */\n makeUrlAbsolute,\n} from '@scalar/helpers/url/make-url-absolute'\nexport {\n /** @deprecated Please use mergeSearchParams from \\@scalar/helpers/url/merge-urls instead */\n mergeSearchParams,\n /** @deprecated Please use mergeUrls from \\@scalar/helpers/url/merge-urls instead */\n mergeUrls,\n} from '@scalar/helpers/url/merge-urls'\nexport {\n /** @deprecated Please use objectKeys from \\@scalar/helpers/object/object-keys instead */\n objectKeys as getObjectKeys,\n} from '@scalar/helpers/object/object-keys'\nexport {\n /** @deprecated Please use replaceVariables from \\@scalar/helpers/regex/replace-variables instead */\n replaceVariables,\n} from '@scalar/helpers/regex/replace-variables'\n"],
5
+ "mappings": "AAAA,SAAS,qBAAqB;AAC9B,SAA6C,8BAA8B;AAC3E,SAAS,yBAAyB;AAClC,SAAS,+BAA+B;AACxC,SAAS,wBAAwB,cAAc,MAAM,iBAAiB,iBAAiB,YAAY;AACnG,SAAS,iBAAiB,mCAAmC;AAC7D,SAAS,gBAAgB,uBAAuB;AAChD,SAAS,mBAAmB;AAC5B,SAAS,0BAA0B;AACnC,SAAS,uBAAuB,uBAAuB,kCAAkC;AACzF,SAAS,8BAA8B;AAMvC;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAME;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,OACK;AACP;AAAA,EAEE;AAAA,EAEA;AAAA,OACK;AACP;AAAA,EAEgB;AAAA,OACT;AACP;AAAA,EAEE;AAAA,OACK;",
6
6
  "names": []
7
7
  }
@@ -1,12 +1,11 @@
1
1
  import type { HttpMethod } from '@scalar/helpers/http/http-methods';
2
2
  import type { Request as HarRequest } from 'har-format';
3
3
  import type { OperationObject } from '@scalar/workspace-store/schemas/v3.1/strict/path-operations';
4
- import { type Dereference } from '@scalar/workspace-store/schemas/v3.1/type-guard';
5
4
  import type { ServerObject } from '@scalar/workspace-store/schemas/v3.1/strict/server';
6
5
  import type { SecuritySchemeObject } from '@scalar/workspace-store/schemas/v3.1/strict/security-scheme';
7
6
  export type OperationToHarProps = {
8
7
  /** OpenAPI Operation object */
9
- operation: Dereference<OperationObject>;
8
+ operation: OperationObject;
10
9
  /** HTTP method of the operation */
11
10
  method: HttpMethod;
12
11
  /** Path of the operation */
@@ -1 +1 @@
1
- {"version":3,"file":"operation-to-har.d.ts","sourceRoot":"","sources":["../../../src/helpers/operation-to-har/operation-to-har.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAA;AACnE,OAAO,KAAK,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,YAAY,CAAA;AAMvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6DAA6D,CAAA;AAClG,OAAO,EAAe,KAAK,WAAW,EAAE,MAAM,iDAAiD,CAAA;AAC/F,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oDAAoD,CAAA;AACtF,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,6DAA6D,CAAA;AAEvG,MAAM,MAAM,mBAAmB,GAAG;IAChC,+BAA+B;IAC/B,SAAS,EAAE,WAAW,CAAC,eAAe,CAAC,CAAA;IACvC,mCAAmC;IACnC,MAAM,EAAE,UAAU,CAAA;IAClB,4BAA4B;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,4BAA4B;IAC5B,MAAM,CAAC,EAAE,YAAY,GAAG,SAAS,CAAA;IACjC,2EAA2E;IAC3E,eAAe,CAAC,EAAE,oBAAoB,EAAE,CAAA;CACzC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,cAAc,gFAQxB,mBAAmB,KAAG,UAwDxB,CAAA"}
1
+ {"version":3,"file":"operation-to-har.d.ts","sourceRoot":"","sources":["../../../src/helpers/operation-to-har/operation-to-har.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAA;AACnE,OAAO,KAAK,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,YAAY,CAAA;AAMvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6DAA6D,CAAA;AAClG,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oDAAoD,CAAA;AACtF,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,6DAA6D,CAAA;AAGvG,MAAM,MAAM,mBAAmB,GAAG;IAChC,+BAA+B;IAC/B,SAAS,EAAE,eAAe,CAAA;IAC1B,mCAAmC;IACnC,MAAM,EAAE,UAAU,CAAA;IAClB,4BAA4B;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,4BAA4B;IAC5B,MAAM,CAAC,EAAE,YAAY,GAAG,SAAS,CAAA;IACjC,2EAA2E;IAC3E,eAAe,CAAC,EAAE,oBAAoB,EAAE,CAAA;CACzC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,cAAc,gFAQxB,mBAAmB,KAAG,UAoExB,CAAA"}
@@ -2,7 +2,7 @@ import { processServerUrl } from "./process-server-url.js";
2
2
  import { processParameters } from "./process-parameters.js";
3
3
  import { processBody } from "./process-body.js";
4
4
  import { processSecuritySchemes } from "./process-security-schemes.js";
5
- import { isReference } from "@scalar/workspace-store/schemas/v3.1/type-guard";
5
+ import { getResolvedRef } from "@scalar/workspace-store/helpers/get-resolved-ref";
6
6
  const operationToHar = ({
7
7
  operation,
8
8
  contentType,
@@ -33,15 +33,23 @@ const operationToHar = ({
33
33
  harRequest.queryString = queryString;
34
34
  harRequest.cookies = cookies;
35
35
  }
36
- if (!isReference(operation.requestBody) && operation.requestBody?.content) {
37
- const postData = processBody({ operation, contentType, example });
36
+ const body = getResolvedRef(operation.requestBody);
37
+ if (body?.content) {
38
+ const postData = processBody({ content: body.content, contentType, example });
38
39
  harRequest.postData = postData;
39
40
  harRequest.bodySize = postData.text?.length ?? -1;
40
- if (postData.mimeType && !harRequest.headers.some((header) => header.name.toLowerCase() === "content-type")) {
41
- harRequest.headers.push({
42
- name: "Content-Type",
43
- value: postData.mimeType
44
- });
41
+ if (postData.mimeType) {
42
+ const existingContentTypeHeader = harRequest.headers.find(
43
+ (header) => header.name.toLowerCase() === "content-type"
44
+ );
45
+ if (existingContentTypeHeader && !existingContentTypeHeader.value) {
46
+ existingContentTypeHeader.value = postData.mimeType;
47
+ } else {
48
+ harRequest.headers.push({
49
+ name: "Content-Type",
50
+ value: postData.mimeType
51
+ });
52
+ }
45
53
  }
46
54
  }
47
55
  if (securitySchemes) {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/helpers/operation-to-har/operation-to-har.ts"],
4
- "sourcesContent": ["import type { HttpMethod } from '@scalar/helpers/http/http-methods'\nimport type { Request as HarRequest } from 'har-format'\n\nimport { processServerUrl } from './process-server-url'\nimport { processParameters } from './process-parameters'\nimport { processBody } from './process-body'\nimport { processSecuritySchemes } from './process-security-schemes'\nimport type { OperationObject } from '@scalar/workspace-store/schemas/v3.1/strict/path-operations'\nimport { isReference, type Dereference } from '@scalar/workspace-store/schemas/v3.1/type-guard'\nimport type { ServerObject } from '@scalar/workspace-store/schemas/v3.1/strict/server'\nimport type { SecuritySchemeObject } from '@scalar/workspace-store/schemas/v3.1/strict/security-scheme'\n\nexport type OperationToHarProps = {\n /** OpenAPI Operation object */\n operation: Dereference<OperationObject>\n /** HTTP method of the operation */\n method: HttpMethod\n /** Path of the operation */\n path: string\n /**\n * requestBody.content[contentType].example to use for the request, it should be pre-selected and discriminated\n */\n example?: unknown\n /**\n * Content type of the request\n *\n * @defaults to the first content type in the operation.requestBody.content\n */\n contentType?: string\n /** OpenAPI Server object */\n server?: ServerObject | undefined\n /** OpenAPI SecurityScheme objects which are applicable to the operation */\n securitySchemes?: SecuritySchemeObject[]\n}\n\n/**\n * Converts an OpenAPI Operation to a HarRequest format for generating HTTP request snippets.\n *\n * This function transforms OpenAPI 3.1 operation objects into HAR (HTTP Archive) format requests,\n * which can be used to generate code snippets for various programming languages and HTTP clients.\n *\n * The conversion handles:\n * - Server URL processing and path parameter substitution\n * - Query parameter formatting based on OpenAPI parameter styles\n * - Request body processing with content type handling\n * - Security scheme integration (API keys, etc.)\n *\n * The resulting HarRequest object follows the HAR specification and includes:\n * - HTTP method and URL\n * - Headers and query parameters\n * - Request body (if present)\n * - Cookie information\n * - Size calculations for headers and body\n *\n * @see https://w3c.github.io/web-performance/specs/HAR/Overview.html\n * @see https://spec.openapis.org/oas/v3.1.0#operation-object\n */\nexport const operationToHar = ({\n operation,\n contentType,\n method,\n path,\n server,\n securitySchemes,\n example,\n}: OperationToHarProps): HarRequest => {\n // Initialize the HAR request with basic properties\n const harRequest: HarRequest = {\n method,\n url: path,\n headers: [],\n queryString: [],\n postData: undefined,\n httpVersion: 'HTTP/1.1',\n cookies: [],\n headersSize: -1,\n bodySize: -1,\n }\n\n // Server URL\n if (server?.url) {\n harRequest.url = processServerUrl(server, path)\n }\n\n // Handle parameters\n if (operation.parameters) {\n const { url, headers, queryString, cookies } = processParameters(harRequest, operation.parameters, example)\n harRequest.url = url\n harRequest.headers = headers\n harRequest.queryString = queryString\n harRequest.cookies = cookies\n }\n\n // Handle request body\n if (!isReference(operation.requestBody) && operation.requestBody?.content) {\n const postData = processBody({ operation, contentType, example })\n harRequest.postData = postData\n harRequest.bodySize = postData.text?.length ?? -1\n\n // Add Content-Type header if not already present\n if (postData.mimeType && !harRequest.headers.some((header) => header.name.toLowerCase() === 'content-type')) {\n harRequest.headers.push({\n name: 'Content-Type',\n value: postData.mimeType,\n })\n }\n }\n\n // Handle security schemes\n if (securitySchemes) {\n const { headers, queryString, cookies } = processSecuritySchemes(securitySchemes)\n harRequest.headers.push(...headers)\n harRequest.queryString.push(...queryString)\n harRequest.cookies.push(...cookies)\n }\n\n // Calculate headers size\n const headerText = harRequest.headers.map((h) => `${h.name}: ${h.value}`).join('\\r\\n')\n harRequest.headersSize = headerText.length\n\n return harRequest\n}\n"],
5
- "mappings": "AAGA,SAAS,wBAAwB;AACjC,SAAS,yBAAyB;AAClC,SAAS,mBAAmB;AAC5B,SAAS,8BAA8B;AAEvC,SAAS,mBAAqC;AAiDvC,MAAM,iBAAiB,CAAC;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAAuC;AAErC,QAAM,aAAyB;AAAA,IAC7B;AAAA,IACA,KAAK;AAAA,IACL,SAAS,CAAC;AAAA,IACV,aAAa,CAAC;AAAA,IACd,UAAU;AAAA,IACV,aAAa;AAAA,IACb,SAAS,CAAC;AAAA,IACV,aAAa;AAAA,IACb,UAAU;AAAA,EACZ;AAGA,MAAI,QAAQ,KAAK;AACf,eAAW,MAAM,iBAAiB,QAAQ,IAAI;AAAA,EAChD;AAGA,MAAI,UAAU,YAAY;AACxB,UAAM,EAAE,KAAK,SAAS,aAAa,QAAQ,IAAI,kBAAkB,YAAY,UAAU,YAAY,OAAO;AAC1G,eAAW,MAAM;AACjB,eAAW,UAAU;AACrB,eAAW,cAAc;AACzB,eAAW,UAAU;AAAA,EACvB;AAGA,MAAI,CAAC,YAAY,UAAU,WAAW,KAAK,UAAU,aAAa,SAAS;AACzE,UAAM,WAAW,YAAY,EAAE,WAAW,aAAa,QAAQ,CAAC;AAChE,eAAW,WAAW;AACtB,eAAW,WAAW,SAAS,MAAM,UAAU;AAG/C,QAAI,SAAS,YAAY,CAAC,WAAW,QAAQ,KAAK,CAAC,WAAW,OAAO,KAAK,YAAY,MAAM,cAAc,GAAG;AAC3G,iBAAW,QAAQ,KAAK;AAAA,QACtB,MAAM;AAAA,QACN,OAAO,SAAS;AAAA,MAClB,CAAC;AAAA,IACH;AAAA,EACF;AAGA,MAAI,iBAAiB;AACnB,UAAM,EAAE,SAAS,aAAa,QAAQ,IAAI,uBAAuB,eAAe;AAChF,eAAW,QAAQ,KAAK,GAAG,OAAO;AAClC,eAAW,YAAY,KAAK,GAAG,WAAW;AAC1C,eAAW,QAAQ,KAAK,GAAG,OAAO;AAAA,EACpC;AAGA,QAAM,aAAa,WAAW,QAAQ,IAAI,CAAC,MAAM,GAAG,EAAE,IAAI,KAAK,EAAE,KAAK,EAAE,EAAE,KAAK,MAAM;AACrF,aAAW,cAAc,WAAW;AAEpC,SAAO;AACT;",
4
+ "sourcesContent": ["import type { HttpMethod } from '@scalar/helpers/http/http-methods'\nimport type { Request as HarRequest } from 'har-format'\n\nimport { processServerUrl } from './process-server-url'\nimport { processParameters } from './process-parameters'\nimport { processBody } from './process-body'\nimport { processSecuritySchemes } from './process-security-schemes'\nimport type { OperationObject } from '@scalar/workspace-store/schemas/v3.1/strict/path-operations'\nimport type { ServerObject } from '@scalar/workspace-store/schemas/v3.1/strict/server'\nimport type { SecuritySchemeObject } from '@scalar/workspace-store/schemas/v3.1/strict/security-scheme'\nimport { getResolvedRef } from '@scalar/workspace-store/helpers/get-resolved-ref'\n\nexport type OperationToHarProps = {\n /** OpenAPI Operation object */\n operation: OperationObject\n /** HTTP method of the operation */\n method: HttpMethod\n /** Path of the operation */\n path: string\n /**\n * requestBody.content[contentType].example to use for the request, it should be pre-selected and discriminated\n */\n example?: unknown\n /**\n * Content type of the request\n *\n * @defaults to the first content type in the operation.requestBody.content\n */\n contentType?: string\n /** OpenAPI Server object */\n server?: ServerObject | undefined\n /** OpenAPI SecurityScheme objects which are applicable to the operation */\n securitySchemes?: SecuritySchemeObject[]\n}\n\n/**\n * Converts an OpenAPI Operation to a HarRequest format for generating HTTP request snippets.\n *\n * This function transforms OpenAPI 3.1 operation objects into HAR (HTTP Archive) format requests,\n * which can be used to generate code snippets for various programming languages and HTTP clients.\n *\n * The conversion handles:\n * - Server URL processing and path parameter substitution\n * - Query parameter formatting based on OpenAPI parameter styles\n * - Request body processing with content type handling\n * - Security scheme integration (API keys, etc.)\n *\n * The resulting HarRequest object follows the HAR specification and includes:\n * - HTTP method and URL\n * - Headers and query parameters\n * - Request body (if present)\n * - Cookie information\n * - Size calculations for headers and body\n *\n * @see https://w3c.github.io/web-performance/specs/HAR/Overview.html\n * @see https://spec.openapis.org/oas/v3.1.0#operation-object\n */\nexport const operationToHar = ({\n operation,\n contentType,\n method,\n path,\n server,\n securitySchemes,\n example,\n}: OperationToHarProps): HarRequest => {\n // Initialize the HAR request with basic properties\n const harRequest: HarRequest = {\n method,\n url: path,\n headers: [],\n queryString: [],\n postData: undefined,\n httpVersion: 'HTTP/1.1',\n cookies: [],\n headersSize: -1,\n bodySize: -1,\n }\n\n // Server URL\n if (server?.url) {\n harRequest.url = processServerUrl(server, path)\n }\n\n // Handle parameters\n if (operation.parameters) {\n const { url, headers, queryString, cookies } = processParameters(harRequest, operation.parameters, example)\n harRequest.url = url\n harRequest.headers = headers\n harRequest.queryString = queryString\n harRequest.cookies = cookies\n }\n\n const body = getResolvedRef(operation.requestBody)\n\n // Handle request body\n if (body?.content) {\n const postData = processBody({ content: body.content, contentType, example })\n harRequest.postData = postData\n harRequest.bodySize = postData.text?.length ?? -1\n\n // Add or update Content-Type header\n if (postData.mimeType) {\n const existingContentTypeHeader = harRequest.headers.find(\n (header) => header.name.toLowerCase() === 'content-type',\n )\n // Update existing header if it has an empty value\n if (existingContentTypeHeader && !existingContentTypeHeader.value) {\n existingContentTypeHeader.value = postData.mimeType\n }\n // Add new header if none exists\n else {\n harRequest.headers.push({\n name: 'Content-Type',\n value: postData.mimeType,\n })\n }\n }\n }\n\n // Handle security schemes\n if (securitySchemes) {\n const { headers, queryString, cookies } = processSecuritySchemes(securitySchemes)\n harRequest.headers.push(...headers)\n harRequest.queryString.push(...queryString)\n harRequest.cookies.push(...cookies)\n }\n\n // Calculate headers size\n const headerText = harRequest.headers.map((h) => `${h.name}: ${h.value}`).join('\\r\\n')\n harRequest.headersSize = headerText.length\n\n return harRequest\n}\n"],
5
+ "mappings": "AAGA,SAAS,wBAAwB;AACjC,SAAS,yBAAyB;AAClC,SAAS,mBAAmB;AAC5B,SAAS,8BAA8B;AAIvC,SAAS,sBAAsB;AA+CxB,MAAM,iBAAiB,CAAC;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAAuC;AAErC,QAAM,aAAyB;AAAA,IAC7B;AAAA,IACA,KAAK;AAAA,IACL,SAAS,CAAC;AAAA,IACV,aAAa,CAAC;AAAA,IACd,UAAU;AAAA,IACV,aAAa;AAAA,IACb,SAAS,CAAC;AAAA,IACV,aAAa;AAAA,IACb,UAAU;AAAA,EACZ;AAGA,MAAI,QAAQ,KAAK;AACf,eAAW,MAAM,iBAAiB,QAAQ,IAAI;AAAA,EAChD;AAGA,MAAI,UAAU,YAAY;AACxB,UAAM,EAAE,KAAK,SAAS,aAAa,QAAQ,IAAI,kBAAkB,YAAY,UAAU,YAAY,OAAO;AAC1G,eAAW,MAAM;AACjB,eAAW,UAAU;AACrB,eAAW,cAAc;AACzB,eAAW,UAAU;AAAA,EACvB;AAEA,QAAM,OAAO,eAAe,UAAU,WAAW;AAGjD,MAAI,MAAM,SAAS;AACjB,UAAM,WAAW,YAAY,EAAE,SAAS,KAAK,SAAS,aAAa,QAAQ,CAAC;AAC5E,eAAW,WAAW;AACtB,eAAW,WAAW,SAAS,MAAM,UAAU;AAG/C,QAAI,SAAS,UAAU;AACrB,YAAM,4BAA4B,WAAW,QAAQ;AAAA,QACnD,CAAC,WAAW,OAAO,KAAK,YAAY,MAAM;AAAA,MAC5C;AAEA,UAAI,6BAA6B,CAAC,0BAA0B,OAAO;AACjE,kCAA0B,QAAQ,SAAS;AAAA,MAC7C,OAEK;AACH,mBAAW,QAAQ,KAAK;AAAA,UACtB,MAAM;AAAA,UACN,OAAO,SAAS;AAAA,QAClB,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AAGA,MAAI,iBAAiB;AACnB,UAAM,EAAE,SAAS,aAAa,QAAQ,IAAI,uBAAuB,eAAe;AAChF,eAAW,QAAQ,KAAK,GAAG,OAAO;AAClC,eAAW,YAAY,KAAK,GAAG,WAAW;AAC1C,eAAW,QAAQ,KAAK,GAAG,OAAO;AAAA,EACpC;AAGA,QAAM,aAAa,WAAW,QAAQ,IAAI,CAAC,MAAM,GAAG,EAAE,IAAI,KAAK,EAAE,KAAK,EAAE,EAAE,KAAK,MAAM;AACrF,aAAW,cAAc,WAAW;AAEpC,SAAO;AACT;",
6
6
  "names": []
7
7
  }
@@ -1,9 +1,12 @@
1
1
  import type { OperationToHarProps } from './operation-to-har.js';
2
+ import type { RequestBodyObject } from '@scalar/workspace-store/schemas/v3.1/strict/request-body';
2
3
  import type { PostData } from 'har-format';
3
- type ProcessBodyProps = Pick<OperationToHarProps, 'contentType' | 'operation' | 'example'>;
4
+ type ProcessBodyProps = Pick<OperationToHarProps, 'contentType' | 'example'> & {
5
+ content: RequestBodyObject['content'];
6
+ };
4
7
  /**
5
8
  * Processes the request body and returns the processed data
6
9
  */
7
- export declare const processBody: ({ operation, contentType, example }: ProcessBodyProps) => PostData;
10
+ export declare const processBody: ({ content, contentType, example }: ProcessBodyProps) => PostData;
8
11
  export {};
9
12
  //# sourceMappingURL=process-body.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"process-body.d.ts","sourceRoot":"","sources":["../../../src/helpers/operation-to-har/process-body.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAG7D,OAAO,KAAK,EAAS,QAAQ,EAAE,MAAM,YAAY,CAAA;AAEjD,KAAK,gBAAgB,GAAG,IAAI,CAAC,mBAAmB,EAAE,aAAa,GAAG,WAAW,GAAG,SAAS,CAAC,CAAA;AAoC1F;;GAEG;AACH,eAAO,MAAM,WAAW,wCAAyC,gBAAgB,KAAG,QA6CnF,CAAA"}
1
+ {"version":3,"file":"process-body.d.ts","sourceRoot":"","sources":["../../../src/helpers/operation-to-har/process-body.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAG7D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0DAA0D,CAAA;AACjG,OAAO,KAAK,EAAS,QAAQ,EAAE,MAAM,YAAY,CAAA;AAEjD,KAAK,gBAAgB,GAAG,IAAI,CAAC,mBAAmB,EAAE,aAAa,GAAG,SAAS,CAAC,GAAG;IAC7E,OAAO,EAAE,iBAAiB,CAAC,SAAS,CAAC,CAAA;CACtC,CAAA;AAoCD;;GAEG;AACH,eAAO,MAAM,WAAW,sCAAuC,gBAAgB,KAAG,QA2CjF,CAAA"}
@@ -1,5 +1,5 @@
1
1
  import { getExampleFromSchema } from "../../spec-getters/get-example-from-schema.js";
2
- import { isReference } from "@scalar/workspace-store/schemas/v3.1/type-guard";
2
+ import { getResolvedRef } from "@scalar/workspace-store/helpers/get-resolved-ref";
3
3
  const objectToFormParams = (obj) => {
4
4
  const params = [];
5
5
  for (const [key, value] of Object.entries(obj)) {
@@ -21,8 +21,7 @@ const objectToFormParams = (obj) => {
21
21
  }
22
22
  return params;
23
23
  };
24
- const processBody = ({ operation, contentType, example }) => {
25
- const content = !operation.requestBody || isReference(operation.requestBody) ? {} : operation.requestBody.content;
24
+ const processBody = ({ content, contentType, example }) => {
26
25
  const _contentType = (contentType || Object.keys(content)[0]) ?? "";
27
26
  const isFormData = _contentType === "multipart/form-data" || _contentType === "application/x-www-form-urlencoded";
28
27
  if (example) {
@@ -37,7 +36,7 @@ const processBody = ({ operation, contentType, example }) => {
37
36
  text: JSON.stringify(example)
38
37
  };
39
38
  }
40
- const contentSchema = content[_contentType]?.schema;
39
+ const contentSchema = getResolvedRef(content[_contentType]?.schema);
41
40
  if (contentSchema) {
42
41
  const extractedExample = getExampleFromSchema(contentSchema);
43
42
  if (extractedExample !== void 0) {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/helpers/operation-to-har/process-body.ts"],
4
- "sourcesContent": ["import type { OperationToHarProps } from './operation-to-har'\nimport { getExampleFromSchema } from '@/spec-getters/get-example-from-schema'\nimport { isReference } from '@scalar/workspace-store/schemas/v3.1/type-guard'\nimport type { Param, PostData } from 'har-format'\n\ntype ProcessBodyProps = Pick<OperationToHarProps, 'contentType' | 'operation' | 'example'>\n\n/**\n * Converts an object to an array of form parameters\n * @param obj - The object to convert\n * @returns Array of form parameters with name and value properties\n */\nconst objectToFormParams = (obj: Record<string, unknown>): Param[] => {\n const params: Param[] = []\n\n for (const [key, value] of Object.entries(obj)) {\n if (value === undefined || value === null) {\n continue\n }\n\n // Handle arrays by adding each item with the same key\n if (Array.isArray(value)) {\n for (const item of value) {\n params.push({ name: key, value: String(item) })\n }\n }\n // Handle nested objects by flattening them\n else if (typeof value === 'object') {\n const nestedParams = objectToFormParams(value as Record<string, unknown>)\n\n for (const param of nestedParams) {\n params.push({ name: `${key}.${param.name}`, value: param.value })\n }\n } else {\n params.push({ name: key, value: String(value) })\n }\n }\n\n return params\n}\n\n/**\n * Processes the request body and returns the processed data\n */\nexport const processBody = ({ operation, contentType, example }: ProcessBodyProps): PostData => {\n const content = !operation.requestBody || isReference(operation.requestBody) ? {} : operation.requestBody.content\n\n const _contentType = (contentType || Object.keys(content)[0]) ?? ''\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 // Return the provided top level example\n if (example) {\n if (isFormData && typeof example === 'object' && example !== null) {\n return {\n mimeType: _contentType,\n params: objectToFormParams(example as Record<string, unknown>),\n }\n }\n return {\n mimeType: _contentType,\n text: JSON.stringify(example),\n }\n }\n\n // Try to extract examples from the schema\n const contentSchema = content[_contentType]?.schema\n if (contentSchema) {\n const extractedExample = getExampleFromSchema(contentSchema)\n\n if (extractedExample !== undefined) {\n if (isFormData && typeof extractedExample === 'object' && extractedExample !== null) {\n return {\n mimeType: _contentType,\n params: objectToFormParams(extractedExample as Record<string, unknown>),\n }\n }\n return {\n mimeType: _contentType,\n text: JSON.stringify(extractedExample),\n }\n }\n }\n\n return {\n mimeType: _contentType,\n text: 'null',\n }\n}\n"],
5
- "mappings": "AACA,SAAS,4BAA4B;AACrC,SAAS,mBAAmB;AAU5B,MAAM,qBAAqB,CAAC,QAA0C;AACpE,QAAM,SAAkB,CAAC;AAEzB,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,GAAG,GAAG;AAC9C,QAAI,UAAU,UAAa,UAAU,MAAM;AACzC;AAAA,IACF;AAGA,QAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,iBAAW,QAAQ,OAAO;AACxB,eAAO,KAAK,EAAE,MAAM,KAAK,OAAO,OAAO,IAAI,EAAE,CAAC;AAAA,MAChD;AAAA,IACF,WAES,OAAO,UAAU,UAAU;AAClC,YAAM,eAAe,mBAAmB,KAAgC;AAExE,iBAAW,SAAS,cAAc;AAChC,eAAO,KAAK,EAAE,MAAM,GAAG,GAAG,IAAI,MAAM,IAAI,IAAI,OAAO,MAAM,MAAM,CAAC;AAAA,MAClE;AAAA,IACF,OAAO;AACL,aAAO,KAAK,EAAE,MAAM,KAAK,OAAO,OAAO,KAAK,EAAE,CAAC;AAAA,IACjD;AAAA,EACF;AAEA,SAAO;AACT;AAKO,MAAM,cAAc,CAAC,EAAE,WAAW,aAAa,QAAQ,MAAkC;AAC9F,QAAM,UAAU,CAAC,UAAU,eAAe,YAAY,UAAU,WAAW,IAAI,CAAC,IAAI,UAAU,YAAY;AAE1G,QAAM,gBAAgB,eAAe,OAAO,KAAK,OAAO,EAAE,CAAC,MAAM;AAGjE,QAAM,aAAa,iBAAiB,yBAAyB,iBAAiB;AAG9E,MAAI,SAAS;AACX,QAAI,cAAc,OAAO,YAAY,YAAY,YAAY,MAAM;AACjE,aAAO;AAAA,QACL,UAAU;AAAA,QACV,QAAQ,mBAAmB,OAAkC;AAAA,MAC/D;AAAA,IACF;AACA,WAAO;AAAA,MACL,UAAU;AAAA,MACV,MAAM,KAAK,UAAU,OAAO;AAAA,IAC9B;AAAA,EACF;AAGA,QAAM,gBAAgB,QAAQ,YAAY,GAAG;AAC7C,MAAI,eAAe;AACjB,UAAM,mBAAmB,qBAAqB,aAAa;AAE3D,QAAI,qBAAqB,QAAW;AAClC,UAAI,cAAc,OAAO,qBAAqB,YAAY,qBAAqB,MAAM;AACnF,eAAO;AAAA,UACL,UAAU;AAAA,UACV,QAAQ,mBAAmB,gBAA2C;AAAA,QACxE;AAAA,MACF;AACA,aAAO;AAAA,QACL,UAAU;AAAA,QACV,MAAM,KAAK,UAAU,gBAAgB;AAAA,MACvC;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL,UAAU;AAAA,IACV,MAAM;AAAA,EACR;AACF;",
4
+ "sourcesContent": ["import type { OperationToHarProps } from './operation-to-har'\nimport { getExampleFromSchema } from '@/spec-getters/get-example-from-schema'\nimport { getResolvedRef } from '@scalar/workspace-store/helpers/get-resolved-ref'\nimport type { RequestBodyObject } from '@scalar/workspace-store/schemas/v3.1/strict/request-body'\nimport type { Param, PostData } from 'har-format'\n\ntype ProcessBodyProps = Pick<OperationToHarProps, 'contentType' | 'example'> & {\n content: RequestBodyObject['content']\n}\n\n/**\n * Converts an object to an array of form parameters\n * @param obj - The object to convert\n * @returns Array of form parameters with name and value properties\n */\nconst objectToFormParams = (obj: Record<string, unknown>): Param[] => {\n const params: Param[] = []\n\n for (const [key, value] of Object.entries(obj)) {\n if (value === undefined || value === null) {\n continue\n }\n\n // Handle arrays by adding each item with the same key\n if (Array.isArray(value)) {\n for (const item of value) {\n params.push({ name: key, value: String(item) })\n }\n }\n // Handle nested objects by flattening them\n else if (typeof value === 'object') {\n const nestedParams = objectToFormParams(value as Record<string, unknown>)\n\n for (const param of nestedParams) {\n params.push({ name: `${key}.${param.name}`, value: param.value })\n }\n } else {\n params.push({ name: key, value: String(value) })\n }\n }\n\n return params\n}\n\n/**\n * Processes the request body and returns the processed data\n */\nexport const processBody = ({ content, contentType, example }: ProcessBodyProps): PostData => {\n const _contentType = (contentType || Object.keys(content)[0]) ?? ''\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 // Return the provided top level example\n if (example) {\n if (isFormData && typeof example === 'object' && example !== null) {\n return {\n mimeType: _contentType,\n params: objectToFormParams(example as Record<string, unknown>),\n }\n }\n return {\n mimeType: _contentType,\n text: JSON.stringify(example),\n }\n }\n\n // Try to extract examples from the schema\n const contentSchema = getResolvedRef(content[_contentType]?.schema)\n if (contentSchema) {\n const extractedExample = getExampleFromSchema(contentSchema)\n\n if (extractedExample !== undefined) {\n if (isFormData && typeof extractedExample === 'object' && extractedExample !== null) {\n return {\n mimeType: _contentType,\n params: objectToFormParams(extractedExample as Record<string, unknown>),\n }\n }\n return {\n mimeType: _contentType,\n text: JSON.stringify(extractedExample),\n }\n }\n }\n\n return {\n mimeType: _contentType,\n text: 'null',\n }\n}\n"],
5
+ "mappings": "AACA,SAAS,4BAA4B;AACrC,SAAS,sBAAsB;AAa/B,MAAM,qBAAqB,CAAC,QAA0C;AACpE,QAAM,SAAkB,CAAC;AAEzB,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,GAAG,GAAG;AAC9C,QAAI,UAAU,UAAa,UAAU,MAAM;AACzC;AAAA,IACF;AAGA,QAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,iBAAW,QAAQ,OAAO;AACxB,eAAO,KAAK,EAAE,MAAM,KAAK,OAAO,OAAO,IAAI,EAAE,CAAC;AAAA,MAChD;AAAA,IACF,WAES,OAAO,UAAU,UAAU;AAClC,YAAM,eAAe,mBAAmB,KAAgC;AAExE,iBAAW,SAAS,cAAc;AAChC,eAAO,KAAK,EAAE,MAAM,GAAG,GAAG,IAAI,MAAM,IAAI,IAAI,OAAO,MAAM,MAAM,CAAC;AAAA,MAClE;AAAA,IACF,OAAO;AACL,aAAO,KAAK,EAAE,MAAM,KAAK,OAAO,OAAO,KAAK,EAAE,CAAC;AAAA,IACjD;AAAA,EACF;AAEA,SAAO;AACT;AAKO,MAAM,cAAc,CAAC,EAAE,SAAS,aAAa,QAAQ,MAAkC;AAC5F,QAAM,gBAAgB,eAAe,OAAO,KAAK,OAAO,EAAE,CAAC,MAAM;AAGjE,QAAM,aAAa,iBAAiB,yBAAyB,iBAAiB;AAG9E,MAAI,SAAS;AACX,QAAI,cAAc,OAAO,YAAY,YAAY,YAAY,MAAM;AACjE,aAAO;AAAA,QACL,UAAU;AAAA,QACV,QAAQ,mBAAmB,OAAkC;AAAA,MAC/D;AAAA,IACF;AACA,WAAO;AAAA,MACL,UAAU;AAAA,MACV,MAAM,KAAK,UAAU,OAAO;AAAA,IAC9B;AAAA,EACF;AAGA,QAAM,gBAAgB,eAAe,QAAQ,YAAY,GAAG,MAAM;AAClE,MAAI,eAAe;AACjB,UAAM,mBAAmB,qBAAqB,aAAa;AAE3D,QAAI,qBAAqB,QAAW;AAClC,UAAI,cAAc,OAAO,qBAAqB,YAAY,qBAAqB,MAAM;AACnF,eAAO;AAAA,UACL,UAAU;AAAA,UACV,QAAQ,mBAAmB,gBAA2C;AAAA,QACxE;AAAA,MACF;AACA,aAAO;AAAA,QACL,UAAU;AAAA,QACV,MAAM,KAAK,UAAU,gBAAgB;AAAA,MACvC;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL,UAAU;AAAA,IACV,MAAM;AAAA,EACR;AACF;",
6
6
  "names": []
7
7
  }
@@ -1,7 +1,5 @@
1
1
  import type { ParameterObject } from '@scalar/workspace-store/schemas/v3.1/strict/parameter';
2
2
  import type { OperationObject } from '@scalar/workspace-store/schemas/v3.1/strict/path-operations';
3
- import type { ReferenceObject } from '@scalar/workspace-store/schemas/v3.1/strict/reference';
4
- import { type Dereference } from '@scalar/workspace-store/schemas/v3.1/type-guard';
5
3
  import type { Request as HarRequest } from 'har-format';
6
4
  type ProcessedParameters = {
7
5
  url: string;
@@ -10,13 +8,13 @@ type ProcessedParameters = {
10
8
  cookies: HarRequest['cookies'];
11
9
  };
12
10
  /** Ensures we don't have any references in the parameters */
13
- export declare const deReferenceParams: (params: Dereference<OperationObject>["parameters"]) => ParameterObject[];
11
+ export declare const deReferenceParams: (params: OperationObject["parameters"]) => ParameterObject[];
14
12
  /**
15
13
  * Process OpenAPI parameters and return the updated properties.
16
14
  * Handles path, query, and header parameters with various styles and explode options.
17
15
  *
18
16
  * @see https://spec.openapis.org/oas/latest.html#style-values
19
17
  */
20
- export declare const processParameters: (harRequest: HarRequest, parameters: (ParameterObject | ReferenceObject)[], example?: unknown) => ProcessedParameters;
18
+ export declare const processParameters: (harRequest: HarRequest, parameters: OperationObject["parameters"], example?: unknown) => ProcessedParameters;
21
19
  export {};
22
20
  //# sourceMappingURL=process-parameters.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"process-parameters.d.ts","sourceRoot":"","sources":["../../../src/helpers/operation-to-har/process-parameters.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uDAAuD,CAAA;AAC5F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6DAA6D,CAAA;AAClG,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uDAAuD,CAAA;AAC5F,OAAO,EAAe,KAAK,WAAW,EAAE,MAAM,iDAAiD,CAAA;AAC/F,OAAO,KAAK,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,YAAY,CAAA;AAEvD,KAAK,mBAAmB,GAAG;IACzB,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;CAC/B,CAAA;AAED,6DAA6D;AAC7D,eAAO,MAAM,iBAAiB,WAAY,WAAW,CAAC,eAAe,CAAC,CAAC,YAAY,CAAC,KAAG,eAAe,EAKrG,CAAA;AAmCD;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,eAChB,UAAU,cACV,CAAC,eAAe,GAAG,eAAe,CAAC,EAAE,YACvC,OAAO,KAChB,mBAuNF,CAAA"}
1
+ {"version":3,"file":"process-parameters.d.ts","sourceRoot":"","sources":["../../../src/helpers/operation-to-har/process-parameters.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uDAAuD,CAAA;AAC5F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6DAA6D,CAAA;AAClG,OAAO,KAAK,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,YAAY,CAAA;AAEvD,KAAK,mBAAmB,GAAG;IACzB,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;CAC/B,CAAA;AAED,6DAA6D;AAC7D,eAAO,MAAM,iBAAiB,WAAY,eAAe,CAAC,YAAY,CAAC,KAAG,eAAe,EACnC,CAAA;AAoEtD;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,eAChB,UAAU,cACV,eAAe,CAAC,YAAY,CAAC,YAC/B,OAAO,KAChB,mBAsNF,CAAA"}
@@ -1,10 +1,6 @@
1
- import { isReference } from "@scalar/workspace-store/schemas/v3.1/type-guard";
2
- const deReferenceParams = (params) => {
3
- if (isReference(params)) {
4
- return [];
5
- }
6
- return (params ?? []).filter((param) => !isReference(param));
7
- };
1
+ import { getExampleFromSchema } from "../../spec-getters/get-example-from-schema.js";
2
+ import { getResolvedRef } from "@scalar/workspace-store/helpers/get-resolved-ref";
3
+ const deReferenceParams = (params) => (params ?? []).map((param) => getResolvedRef(param));
8
4
  const getParameterStyleAndExplode = (param) => {
9
5
  if (param.in === "header") {
10
6
  const explode2 = "explode" in param && param.explode !== void 0 ? param.explode : false;
@@ -24,6 +20,26 @@ const getParameterStyleAndExplode = (param) => {
24
20
  const explode = "explode" in param && param.explode !== void 0 ? param.explode : style === "form";
25
21
  return { style, explode };
26
22
  };
23
+ const getParameterValue = (param, example) => {
24
+ if (example && typeof example === "object" && param.name) {
25
+ const exampleValue = example[param.name];
26
+ if (exampleValue !== void 0) {
27
+ return exampleValue;
28
+ }
29
+ }
30
+ if ("example" in param && param.example) {
31
+ return param.example;
32
+ }
33
+ if ("examples" in param && param.examples) {
34
+ const examples = param.examples;
35
+ return examples[param.name] || Object.values(examples)[0]?.value;
36
+ }
37
+ if ("schema" in param && param.schema) {
38
+ const options = param.in === "path" ? { emptyString: `{${param.name}}` } : {};
39
+ return getExampleFromSchema(getResolvedRef(param.schema), options);
40
+ }
41
+ return void 0;
42
+ };
27
43
  const processParameters = (harRequest, parameters, example) => {
28
44
  const newHeaders = [...harRequest.headers];
29
45
  const newQueryString = [...harRequest.queryString];
@@ -33,7 +49,7 @@ const processParameters = (harRequest, parameters, example) => {
33
49
  if (!param.in || !param.name) {
34
50
  continue;
35
51
  }
36
- const paramValue = example && typeof example === "object" ? example[param.name] : void 0;
52
+ const paramValue = getParameterValue(param, example);
37
53
  if (paramValue === void 0) {
38
54
  continue;
39
55
  }