@scalar/oas-utils 0.4.4 → 0.4.5

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 (41) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/entities/spec/operation.d.ts +10 -10
  3. package/dist/entities/spec/parameters.d.ts +2 -2
  4. package/dist/entities/spec/request-examples.d.ts +8 -8
  5. package/dist/entities/spec/request-examples.d.ts.map +1 -1
  6. package/dist/entities/spec/request-examples.js +1 -1
  7. package/dist/entities/spec/request-examples.js.map +2 -2
  8. package/dist/entities/spec/requests.d.ts +20 -20
  9. package/dist/helpers/operation-to-har/index.d.ts +2 -0
  10. package/dist/helpers/operation-to-har/index.d.ts.map +1 -0
  11. package/dist/helpers/operation-to-har/index.js +5 -0
  12. package/dist/helpers/operation-to-har/index.js.map +7 -0
  13. package/dist/helpers/operation-to-har/operation-to-har.d.ts +49 -0
  14. package/dist/helpers/operation-to-har/operation-to-har.d.ts.map +1 -0
  15. package/dist/helpers/operation-to-har/operation-to-har.js +52 -0
  16. package/dist/helpers/operation-to-har/operation-to-har.js.map +7 -0
  17. package/dist/helpers/operation-to-har/process-body.d.ts +9 -0
  18. package/dist/helpers/operation-to-har/process-body.d.ts.map +1 -0
  19. package/dist/helpers/operation-to-har/process-body.js +12 -0
  20. package/dist/helpers/operation-to-har/process-body.js.map +7 -0
  21. package/dist/helpers/operation-to-har/process-parameters.d.ts +16 -0
  22. package/dist/helpers/operation-to-har/process-parameters.d.ts.map +1 -0
  23. package/dist/helpers/operation-to-har/process-parameters.js +161 -0
  24. package/dist/helpers/operation-to-har/process-parameters.js.map +7 -0
  25. package/dist/helpers/operation-to-har/process-security-schemes.d.ts +13 -0
  26. package/dist/helpers/operation-to-har/process-security-schemes.d.ts.map +1 -0
  27. package/dist/helpers/operation-to-har/process-security-schemes.js +68 -0
  28. package/dist/helpers/operation-to-har/process-security-schemes.js.map +7 -0
  29. package/dist/helpers/operation-to-har/process-server-url.d.ts +6 -0
  30. package/dist/helpers/operation-to-har/process-server-url.d.ts.map +1 -0
  31. package/dist/helpers/operation-to-har/process-server-url.js +27 -0
  32. package/dist/helpers/operation-to-har/process-server-url.js.map +7 -0
  33. package/dist/spec-getters/get-parameters-from-operation.d.ts +3 -2
  34. package/dist/spec-getters/get-parameters-from-operation.d.ts.map +1 -1
  35. package/dist/spec-getters/get-parameters-from-operation.js +3 -3
  36. package/dist/spec-getters/get-parameters-from-operation.js.map +2 -2
  37. package/dist/spec-getters/get-request-body-from-operation.d.ts +1 -1
  38. package/dist/spec-getters/get-request-body-from-operation.d.ts.map +1 -1
  39. package/dist/spec-getters/get-request-body-from-operation.js +12 -2
  40. package/dist/spec-getters/get-request-body-from-operation.js.map +2 -2
  41. package/package.json +15 -9
@@ -1 +1 @@
1
- {"version":3,"file":"get-request-body-from-operation.d.ts","sourceRoot":"","sources":["../../src/spec-getters/get-request-body-from-operation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AA8C7E;;GAEG;AACH,wBAAgB,2BAA2B,CACzC,SAAS,EAAE,IAAI,CAAC,oBAAoB,EAAE,UAAU,CAAC,EACjD,kBAAkB,CAAC,EAAE,MAAM,GAAG,MAAM,EACpC,8BAA8B,CAAC,EAAE,OAAO,GACvC;IACD,QAAQ,EAAE,WAAW,CAAA;IACrB,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACzB,MAAM,CAAC,EAAE;QACP,IAAI,EAAE,MAAM,CAAA;QACZ,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;KACtB,EAAE,CAAA;CACJ,GAAG,IAAI,CA+JP"}
1
+ {"version":3,"file":"get-request-body-from-operation.d.ts","sourceRoot":"","sources":["../../src/spec-getters/get-request-body-from-operation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AA8C7E;;GAEG;AACH,wBAAgB,2BAA2B,CACzC,SAAS,EAAE,IAAI,CAAC,oBAAoB,EAAE,gBAAgB,GAAG,aAAa,CAAC,EACvE,kBAAkB,CAAC,EAAE,MAAM,GAAG,MAAM,EACpC,8BAA8B,CAAC,EAAE,OAAO,GACvC;IACD,QAAQ,EAAE,WAAW,CAAA;IACrB,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACzB,MAAM,CAAC,EAAE;QACP,IAAI,EAAE,MAAM,CAAA;QACZ,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;KACtB,EAAE,CAAA;CACJ,GAAG,IAAI,CAyKP"}
@@ -36,14 +36,24 @@ function getRequestBodyFromOperation(operation, selectedExampleKey, omitEmptyAnd
36
36
  text: prettyPrintJson(selectedExample?.value)
37
37
  };
38
38
  }
39
- const bodyParameters = getParametersFromOperation(operation, "body", false);
39
+ const bodyParameters = getParametersFromOperation(
40
+ operation.information?.parameters ?? [],
41
+ operation.pathParameters ?? [],
42
+ "body",
43
+ false
44
+ );
40
45
  if (bodyParameters.length > 0) {
41
46
  return {
42
47
  mimeType: "application/json",
43
48
  text: prettyPrintJson(bodyParameters[0]?.value ?? "")
44
49
  };
45
50
  }
46
- const formDataParameters = getParametersFromOperation(operation, "formData", false);
51
+ const formDataParameters = getParametersFromOperation(
52
+ operation.information?.parameters ?? [],
53
+ operation.pathParameters ?? [],
54
+ "formData",
55
+ false
56
+ );
47
57
  if (formDataParameters.length > 0) {
48
58
  return {
49
59
  mimeType: "application/x-www-form-urlencoded",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/spec-getters/get-request-body-from-operation.ts"],
4
- "sourcesContent": ["import { json2xml } from '@scalar/helpers/file/json2xml'\nimport type { ContentType, TransformedOperation } from '@scalar/types/legacy'\n\nimport { normalizeMimeTypeObject } from '@/helpers/normalize-mime-type-object'\nimport { prettyPrintJson } from '@/helpers/pretty-print-json'\nimport { getExampleFromSchema } from './get-example-from-schema'\nimport { getParametersFromOperation } from './get-parameters-from-operation'\n\ntype AnyObject = Record<string, any>\n\n/**\n * Transform the object into a nested array of objects\n * that represent the key-value pairs of the object.\n */\nfunction getParamsFromObject(\n obj: AnyObject,\n nested = false,\n field?: string,\n): {\n name: string\n value: any\n}[] {\n return Object.entries(obj).flatMap(([key, value]) => {\n const name = field ?? key\n\n if (Array.isArray(value) && !nested) {\n return getParamsFromObject(value, true, key)\n }\n\n if (typeof value === 'object' && !(value instanceof File) && value !== null) {\n // Nested object inside formData field: no way to represent it, so just serialize to JSON string\n value = JSON.stringify(value)\n }\n\n return [{ name, value }]\n })\n}\n// Define preferred standard mime types (order indicates preference)\nconst standardMimeTypes: ContentType[] = [\n 'application/json',\n 'application/octet-stream',\n 'application/x-www-form-urlencoded',\n 'application/xml',\n 'multipart/form-data',\n 'text/plain',\n]\n\n/**\n * Get the request body from the operation.\n */\nexport function getRequestBodyFromOperation(\n operation: Omit<TransformedOperation, 'httpVerb'>,\n selectedExampleKey?: string | number,\n omitEmptyAndOptionalProperties?: boolean,\n): {\n mimeType: ContentType\n text?: string | undefined\n params?: {\n name: string\n value?: string | File\n }[]\n} | null {\n const originalContent = operation.information?.requestBody?.content\n const content = normalizeMimeTypeObject(originalContent)\n\n // First try to find a standard mime type\n const mimeType =\n standardMimeTypes.find((currentMimeType) => !!content?.[currentMimeType]) ??\n ((Object.keys(content ?? {})[0] || 'application/json') as ContentType)\n\n // Handle JSON-like content types (e.g., application/vnd.github+json)\n const isJsonLike = mimeType.includes('json') || mimeType.endsWith('+json')\n\n /** Examples */\n const examples = content?.[mimeType]?.examples ?? content?.['application/json']?.examples\n\n // Let\u2019s use the first example\n const selectedExample = examples?.[selectedExampleKey ?? Object.keys(examples ?? {})[0] ?? '']\n\n if (selectedExample) {\n return {\n mimeType,\n text: prettyPrintJson(selectedExample?.value),\n }\n }\n\n /**\n * Body Parameters (Swagger 2.0)\n *\n * \u201DThe payload that's appended to the HTTP request. Since there can only be one payload, there can only\n * be one body parameter. The name of the body parameter has no effect on the parameter itself and is used\n * for documentation purposes only. Since Form parameters are also in the payload, body and form\n * parameters cannot exist together for the same operation.\u201D\n */\n const bodyParameters = getParametersFromOperation(operation, 'body', false)\n\n if (bodyParameters.length > 0) {\n return {\n mimeType: 'application/json',\n text: prettyPrintJson(bodyParameters[0]?.value ?? ''),\n }\n }\n\n /**\n * FormData Parameters (Swagger 2.0)\n *\n * \u201DForm - Used to describe the payload of an HTTP request when either application/x-www-form-urlencoded,\n * multipart/form-data or both are used as the content type of the request (in Swagger's definition, the\n * consumes property of an operation). This is the only parameter type that can be used to send files,\n * thus supporting the file type. Since form parameters are sent in the payload, they cannot be declared\n * together with a body parameter for the same operation. Form parameters have a different format based on\n * the content-type used (for further details, consult http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4):\n * - application/x-www-form-urlencoded - Similar to the format of Query parameters but as a payload.\n * For example, foo=1&bar=swagger - both foo and bar are form parameters. This is normally used for simple\n * parameters that are being transferred.\n * - multipart/form-data - each parameter takes a section in the payload with an internal header.\n * For example, for the header Content-Disposition: form-data; name=\"submit-name\" the name of the parameter is\n * submit-name. This type of form parameters is more commonly used for file transfers.\u201D\n */\n\n const formDataParameters = getParametersFromOperation(operation, 'formData', false)\n\n if (formDataParameters.length > 0) {\n return {\n mimeType: 'application/x-www-form-urlencoded',\n params: formDataParameters.map((parameter) => ({\n name: parameter.name,\n /**\n * TODO: This value MUST be a string\n * Figure out why this is not always a string\n *\n * JSON.stringify is a TEMPORARY fix\n */\n value: typeof parameter.value === 'string' ? parameter.value : JSON.stringify(parameter.value),\n })),\n }\n }\n\n // If no mime type is supported, exit early\n if (!mimeType) {\n return null\n }\n\n // Get the request body object for the mime type\n const requestBodyObject = content?.[mimeType]\n\n // Get example from operation\n const example = requestBodyObject?.example ? requestBodyObject?.example : undefined\n\n // Update the JSON handling section\n if (isJsonLike) {\n const exampleFromSchema = requestBodyObject?.schema\n ? getExampleFromSchema(requestBodyObject?.schema, {\n mode: 'write',\n omitEmptyAndOptionalProperties: omitEmptyAndOptionalProperties ?? false,\n })\n : null\n\n const body = example ?? exampleFromSchema\n\n return {\n mimeType,\n text: body ? (typeof body === 'string' ? body : JSON.stringify(body, null, 2)) : undefined,\n }\n }\n\n // XML\n if (mimeType === 'application/xml') {\n const exampleFromSchema = requestBodyObject?.schema\n ? getExampleFromSchema(requestBodyObject?.schema, {\n xml: true,\n mode: 'write',\n })\n : null\n\n return {\n mimeType,\n text: example ?? json2xml(exampleFromSchema, ' '),\n }\n }\n\n // Binary data\n if (mimeType === 'application/octet-stream') {\n return {\n mimeType,\n text: 'BINARY',\n }\n }\n\n // Plain text\n if (mimeType === 'text/plain') {\n const exampleFromSchema = requestBodyObject?.schema\n ? getExampleFromSchema(requestBodyObject?.schema, {\n xml: true,\n mode: 'write',\n })\n : null\n\n return {\n mimeType,\n text: example ?? exampleFromSchema ?? '',\n }\n }\n\n // URL encoded data\n if (mimeType === 'multipart/form-data' || mimeType === 'application/x-www-form-urlencoded') {\n const exampleFromSchema = requestBodyObject?.schema\n ? getExampleFromSchema(requestBodyObject?.schema, {\n xml: true,\n mode: 'write',\n })\n : null\n\n return {\n mimeType,\n params: getParamsFromObject(example ?? exampleFromSchema ?? {}),\n }\n }\n\n return null\n}\n"],
5
- "mappings": "AAAA,SAAS,gBAAgB;AAGzB,SAAS,+BAA+B;AACxC,SAAS,uBAAuB;AAChC,SAAS,4BAA4B;AACrC,SAAS,kCAAkC;AAQ3C,SAAS,oBACP,KACA,SAAS,OACT,OAIE;AACF,SAAO,OAAO,QAAQ,GAAG,EAAE,QAAQ,CAAC,CAAC,KAAK,KAAK,MAAM;AACnD,UAAM,OAAO,SAAS;AAEtB,QAAI,MAAM,QAAQ,KAAK,KAAK,CAAC,QAAQ;AACnC,aAAO,oBAAoB,OAAO,MAAM,GAAG;AAAA,IAC7C;AAEA,QAAI,OAAO,UAAU,YAAY,EAAE,iBAAiB,SAAS,UAAU,MAAM;AAE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AAoB,WAAW,qBAAqB,CAAC,CAAC;AAAA,IAChE;AAAA,EACF;AAEA,SAAO;AACT;",
4
+ "sourcesContent": ["import { json2xml } from '@scalar/helpers/file/json2xml'\nimport type { ContentType, TransformedOperation } from '@scalar/types/legacy'\n\nimport { normalizeMimeTypeObject } from '@/helpers/normalize-mime-type-object'\nimport { prettyPrintJson } from '@/helpers/pretty-print-json'\nimport { getExampleFromSchema } from './get-example-from-schema'\nimport { getParametersFromOperation } from './get-parameters-from-operation'\n\ntype AnyObject = Record<string, any>\n\n/**\n * Transform the object into a nested array of objects\n * that represent the key-value pairs of the object.\n */\nfunction getParamsFromObject(\n obj: AnyObject,\n nested = false,\n field?: string,\n): {\n name: string\n value: any\n}[] {\n return Object.entries(obj).flatMap(([key, value]) => {\n const name = field ?? key\n\n if (Array.isArray(value) && !nested) {\n return getParamsFromObject(value, true, key)\n }\n\n if (typeof value === 'object' && !(value instanceof File) && value !== null) {\n // Nested object inside formData field: no way to represent it, so just serialize to JSON string\n value = JSON.stringify(value)\n }\n\n return [{ name, value }]\n })\n}\n// Define preferred standard mime types (order indicates preference)\nconst standardMimeTypes: ContentType[] = [\n 'application/json',\n 'application/octet-stream',\n 'application/x-www-form-urlencoded',\n 'application/xml',\n 'multipart/form-data',\n 'text/plain',\n]\n\n/**\n * Get the request body from the operation.\n */\nexport function getRequestBodyFromOperation(\n operation: Pick<TransformedOperation, 'pathParameters' | 'information'>,\n selectedExampleKey?: string | number,\n omitEmptyAndOptionalProperties?: boolean,\n): {\n mimeType: ContentType\n text?: string | undefined\n params?: {\n name: string\n value?: string | File\n }[]\n} | null {\n const originalContent = operation.information?.requestBody?.content\n const content = normalizeMimeTypeObject(originalContent)\n\n // First try to find a standard mime type\n const mimeType =\n standardMimeTypes.find((currentMimeType) => !!content?.[currentMimeType]) ??\n ((Object.keys(content ?? {})[0] || 'application/json') as ContentType)\n\n // Handle JSON-like content types (e.g., application/vnd.github+json)\n const isJsonLike = mimeType.includes('json') || mimeType.endsWith('+json')\n\n /** Examples */\n const examples = content?.[mimeType]?.examples ?? content?.['application/json']?.examples\n\n // Let\u2019s use the first example\n const selectedExample = examples?.[selectedExampleKey ?? Object.keys(examples ?? {})[0] ?? '']\n\n if (selectedExample) {\n return {\n mimeType,\n text: prettyPrintJson(selectedExample?.value),\n }\n }\n\n /**\n * Body Parameters (Swagger 2.0)\n *\n * \u201DThe payload that's appended to the HTTP request. Since there can only be one payload, there can only\n * be one body parameter. The name of the body parameter has no effect on the parameter itself and is used\n * for documentation purposes only. Since Form parameters are also in the payload, body and form\n * parameters cannot exist together for the same operation.\u201D\n */\n const bodyParameters = getParametersFromOperation(\n operation.information?.parameters ?? [],\n operation.pathParameters ?? [],\n 'body',\n false,\n )\n\n if (bodyParameters.length > 0) {\n return {\n mimeType: 'application/json',\n text: prettyPrintJson(bodyParameters[0]?.value ?? ''),\n }\n }\n\n /**\n * FormData Parameters (Swagger 2.0)\n *\n * \u201DForm - Used to describe the payload of an HTTP request when either application/x-www-form-urlencoded,\n * multipart/form-data or both are used as the content type of the request (in Swagger's definition, the\n * consumes property of an operation). This is the only parameter type that can be used to send files,\n * thus supporting the file type. Since form parameters are sent in the payload, they cannot be declared\n * together with a body parameter for the same operation. Form parameters have a different format based on\n * the content-type used (for further details, consult http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4):\n * - application/x-www-form-urlencoded - Similar to the format of Query parameters but as a payload.\n * For example, foo=1&bar=swagger - both foo and bar are form parameters. This is normally used for simple\n * parameters that are being transferred.\n * - multipart/form-data - each parameter takes a section in the payload with an internal header.\n * For example, for the header Content-Disposition: form-data; name=\"submit-name\" the name of the parameter is\n * submit-name. This type of form parameters is more commonly used for file transfers.\u201D\n */\n\n const formDataParameters = getParametersFromOperation(\n operation.information?.parameters ?? [],\n operation.pathParameters ?? [],\n 'formData',\n false,\n )\n\n if (formDataParameters.length > 0) {\n return {\n mimeType: 'application/x-www-form-urlencoded',\n params: formDataParameters.map((parameter) => ({\n name: parameter.name,\n /**\n * TODO: This value MUST be a string\n * Figure out why this is not always a string\n *\n * JSON.stringify is a TEMPORARY fix\n */\n value: typeof parameter.value === 'string' ? parameter.value : JSON.stringify(parameter.value),\n })),\n }\n }\n\n // If no mime type is supported, exit early\n if (!mimeType) {\n return null\n }\n\n // Get the request body object for the mime type\n const requestBodyObject = content?.[mimeType]\n\n // Get example from operation\n const example = requestBodyObject?.example ? requestBodyObject?.example : undefined\n\n // Update the JSON handling section\n if (isJsonLike) {\n const exampleFromSchema = requestBodyObject?.schema\n ? getExampleFromSchema(requestBodyObject?.schema, {\n mode: 'write',\n omitEmptyAndOptionalProperties: omitEmptyAndOptionalProperties ?? false,\n })\n : null\n\n const body = example ?? exampleFromSchema\n\n return {\n mimeType,\n text: body ? (typeof body === 'string' ? body : JSON.stringify(body, null, 2)) : undefined,\n }\n }\n\n // XML\n if (mimeType === 'application/xml') {\n const exampleFromSchema = requestBodyObject?.schema\n ? getExampleFromSchema(requestBodyObject?.schema, {\n xml: true,\n mode: 'write',\n })\n : null\n\n return {\n mimeType,\n text: example ?? json2xml(exampleFromSchema, ' '),\n }\n }\n\n // Binary data\n if (mimeType === 'application/octet-stream') {\n return {\n mimeType,\n text: 'BINARY',\n }\n }\n\n // Plain text\n if (mimeType === 'text/plain') {\n const exampleFromSchema = requestBodyObject?.schema\n ? getExampleFromSchema(requestBodyObject?.schema, {\n xml: true,\n mode: 'write',\n })\n : null\n\n return {\n mimeType,\n text: example ?? exampleFromSchema ?? '',\n }\n }\n\n // URL encoded data\n if (mimeType === 'multipart/form-data' || mimeType === 'application/x-www-form-urlencoded') {\n const exampleFromSchema = requestBodyObject?.schema\n ? getExampleFromSchema(requestBodyObject?.schema, {\n xml: true,\n mode: 'write',\n })\n : null\n\n return {\n mimeType,\n params: getParamsFromObject(example ?? exampleFromSchema ?? {}),\n }\n }\n\n return null\n}\n"],
5
+ "mappings": "AAAA,SAAS,gBAAgB;AAGzB,SAAS,+BAA+B;AACxC,SAAS,uBAAuB;AAChC,S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4BAA4B;AAC3C,WAAO;AAAA,MACL;AAAA,MACA,MAAM;AAAA,IACR;AAAA,EACF;AAGA,MAAI,aAAa,cAAc;AAC7B,UAAM,oBAAoB,mBAAmB,SACzC,qBAAqB,mBAAmB,QAAQ;AAAA,MAC9C,KAAK;AAAA,MACL,MAAM;AAAA,IACR,CAAC,IACD;AAEJ,WAAO;AAAA,MACL;AAAA,MACA,MAAM,WAAW,qBAAqB;AAAA,IACxC;AAAA,EACF;AAGA,MAAI,aAAa,yBAAyB,aAAa,qCAAqC;AAC1F,UAAM,oBAAoB,mBAAmB,SACzC,qBAAqB,mBAAmB,QAAQ;AAAA,MAC9C,KAAK;AAAA,MACL,MAAM;AAAA,IACR,CAAC,IACD;AAEJ,WAAO;AAAA,MACL;AAAA,MACA,QAAQ,oBAAoB,WAAW,qBAAqB,CAAC,CAAC;AAAA,IAChE;AAAA,EACF;AAEA,SAAO;AACT;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -16,7 +16,7 @@
16
16
  "specification",
17
17
  "yaml"
18
18
  ],
19
- "version": "0.4.4",
19
+ "version": "0.4.5",
20
20
  "engines": {
21
21
  "node": ">=20"
22
22
  },
@@ -58,6 +58,11 @@
58
58
  "types": "./dist/helpers/index.d.ts",
59
59
  "default": "./dist/helpers/index.js"
60
60
  },
61
+ "./helpers/operation-to-har": {
62
+ "import": "./dist/helpers/operation-to-har/index.js",
63
+ "types": "./dist/helpers/operation-to-har/index.d.ts",
64
+ "default": "./dist/helpers/operation-to-har/index.js"
65
+ },
61
66
  "./helpers/security": {
62
67
  "import": "./dist/helpers/security/index.js",
63
68
  "types": "./dist/helpers/security/index.d.ts",
@@ -87,17 +92,18 @@
87
92
  "dependencies": {
88
93
  "@hyperjump/browser": "^1.1.0",
89
94
  "@hyperjump/json-schema": "^1.9.6",
95
+ "@types/har-format": "^1.2.15",
90
96
  "flatted": "^3.3.1",
91
97
  "microdiff": "^1.4.0",
92
98
  "nanoid": "^5.1.5",
93
99
  "type-fest": "^4.20.0",
94
100
  "yaml": "^2.4.5",
95
101
  "zod": "3.24.1",
96
- "@scalar/helpers": "0.0.3",
97
- "@scalar/themes": "0.13.2",
98
- "@scalar/types": "0.2.2",
99
- "@scalar/openapi-types": "0.3.2",
100
- "@scalar/object-utils": "1.2.1"
102
+ "@scalar/helpers": "0.0.4",
103
+ "@scalar/object-utils": "1.2.1",
104
+ "@scalar/openapi-types": "0.3.3",
105
+ "@scalar/themes": "0.13.3",
106
+ "@scalar/types": "0.2.3"
101
107
  },
102
108
  "devDependencies": {
103
109
  "@types/node": "^20.17.10",
@@ -105,9 +111,9 @@
105
111
  "vite": "5.4.19",
106
112
  "vitest": "^1.6.0",
107
113
  "zod-to-ts": "github:amritk/zod-to-ts#build",
108
- "@scalar/build-tooling": "0.2.2",
109
- "@scalar/openapi-parser": "0.15.0",
110
- "@scalar/openapi-types": "0.3.2"
114
+ "@scalar/build-tooling": "0.2.3",
115
+ "@scalar/openapi-parser": "0.17.0",
116
+ "@scalar/openapi-types": "0.3.3"
111
117
  },
112
118
  "scripts": {
113
119
  "build": "scalar-build-esbuild",