@scalar/oas-utils 0.4.15 → 0.4.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -0
- package/dist/entities/spec/operation.d.ts +15 -15
- package/dist/entities/spec/parameters.d.ts +5 -5
- package/dist/entities/spec/request-examples.d.ts +68 -68
- package/dist/entities/spec/requests.d.ts +31 -31
- package/dist/helpers/index.d.ts +0 -1
- package/dist/helpers/index.d.ts.map +1 -1
- package/dist/helpers/index.js +0 -3
- package/dist/helpers/index.js.map +2 -2
- package/dist/helpers/normalize-mime-type-object.d.ts +2 -13
- package/dist/helpers/normalize-mime-type-object.d.ts.map +1 -1
- package/dist/helpers/normalize-mime-type-object.js +4 -8
- package/dist/helpers/normalize-mime-type-object.js.map +2 -2
- package/dist/helpers/normalize-mime-type.d.ts +3 -1
- package/dist/helpers/normalize-mime-type.d.ts.map +1 -1
- package/dist/helpers/normalize-mime-type.js.map +2 -2
- package/dist/helpers/operation-to-har/process-body.d.ts +1 -1
- package/dist/helpers/operation-to-har/process-body.d.ts.map +1 -1
- package/dist/helpers/operation-to-har/process-body.js +3 -30
- package/dist/helpers/operation-to-har/process-body.js.map +2 -2
- package/dist/helpers/security/get-schemes.d.ts +3 -0
- package/dist/helpers/security/get-schemes.d.ts.map +1 -1
- package/dist/spec-getters/get-example-from-schema.d.ts.map +1 -1
- package/dist/spec-getters/get-example-from-schema.js +5 -2
- package/dist/spec-getters/get-example-from-schema.js.map +2 -2
- package/dist/spec-getters/get-request-body-from-operation.js +1 -1
- package/dist/spec-getters/get-request-body-from-operation.js.map +2 -2
- package/package.json +11 -11
- package/dist/helpers/ssr-state.d.ts +0 -12
- package/dist/helpers/ssr-state.d.ts.map +0 -1
- package/dist/helpers/ssr-state.js +0 -7
- package/dist/helpers/ssr-state.js.map +0 -7
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/spec-getters/get-example-from-schema.ts"],
|
|
4
|
-
"sourcesContent": ["const MAX_LEVELS_DEEP = 5\n/** Sets the max number of properties after the third level to prevent exponential horizontal growth */\nconst MAX_PROPERTIES = 10\n\n/** The default name for additional properties. */\nconst DEFAULT_ADDITIONAL_PROPERTIES_NAME = 'propertyName*'\n\nconst genericExampleValues: Record<string, string> = {\n // 'date-time': '1970-01-01T00:00:00Z',\n 'date-time': new Date().toISOString(),\n // 'date': '1970-01-01',\n 'date': new Date().toISOString().split('T')[0]!,\n 'email': 'hello@example.com',\n 'hostname': 'example.com',\n // https://tools.ietf.org/html/rfc6531#section-3.3\n 'idn-email': 'jane.doe@example.com',\n // https://tools.ietf.org/html/rfc5890#section-2.3.2.3\n 'idn-hostname': 'example.com',\n 'ipv4': '127.0.0.1',\n 'ipv6': '51d4:7fab:bfbf:b7d7:b2cb:d4b4:3dad:d998',\n 'iri-reference': '/entitiy/1',\n // https://tools.ietf.org/html/rfc3987\n 'iri': 'https://example.com/entity/123',\n 'json-pointer': '/nested/objects',\n 'password': 'super-secret',\n 'regex': '/[a-z]/',\n // https://tools.ietf.org/html/draft-handrews-relative-json-pointer-01\n 'relative-json-pointer': '1/nested/objects',\n // full-time in https://tools.ietf.org/html/rfc3339#section-5.6\n // 'time': '00:00:00Z',\n 'time': new Date().toISOString().split('T')[1]!.split('.')[0]!,\n // either a URI or relative-reference https://tools.ietf.org/html/rfc3986#section-4.1\n 'uri-reference': '../folder',\n 'uri-template': 'https://example.com/{id}',\n 'uri': 'https://example.com',\n 'uuid': '123e4567-e89b-12d3-a456-426614174000',\n 'object-id': '6592008029c8c3e4dc76256c',\n}\n\n/**\n * We can use the `format` to generate some random values.\n */\nfunction guessFromFormat(schema: Record<string, any>, makeUpRandomData: boolean = false, fallback: string = '') {\n if (schema.format === 'binary') {\n return new File([''], 'filename')\n }\n return makeUpRandomData ? (genericExampleValues[schema.format] ?? fallback) : ''\n}\n\n/** Map of all the results */\nconst resultCache = new WeakMap<Record<string, any>, any>()\n\n/** Store result in the cache, and return the result */\nfunction cache(schema: Record<string, any>, result: unknown) {\n // Avoid unnecessary WeakMap operations for primitive values\n if (typeof result !== 'object' || result === null) {\n return result\n }\n\n resultCache.set(schema, result)\n\n return result\n}\n\n/**\n * This function takes an OpenAPI schema and generates an example from it\n */\nexport const getExampleFromSchema = (\n schema: Record<string, any>,\n options?: {\n /**\n * The fallback string for empty string values.\n * @default ''\n */\n emptyString?: string\n /**\n * Whether to use the XML tag names as keys\n * @default false\n */\n xml?: boolean\n /**\n * Whether to show read-only/write-only properties. Otherwise all properties are shown.\n * @default undefined\n */\n mode?: 'read' | 'write'\n /**\n * Dynamic values to add to the example.\n */\n variables?: Record<string, any>\n /**\n * Whether to omit empty and optional properties.\n * @default false\n */\n omitEmptyAndOptionalProperties?: boolean\n },\n level: number = 0,\n parentSchema?: Record<string, any>,\n name?: string,\n): any => {\n // Check if the result is already cached\n if (resultCache.has(schema)) {\n return resultCache.get(schema)\n }\n\n // Check whether it's a circular reference\n if (level === MAX_LEVELS_DEEP + 1) {\n try {\n // Fails if it contains a circular reference\n JSON.stringify(schema)\n } catch {\n return '[Circular Reference]'\n }\n }\n\n // Sometimes, we just want the structure and no values.\n // But if `emptyString` is set, we do want to see some values.\n const makeUpRandomData = !!options?.emptyString\n\n // If the property is deprecated anyway, we don't want to show it.\n if (schema.deprecated) {\n return undefined\n }\n\n // Check if the property is read-only/write-only\n if ((options?.mode === 'write' && schema.readOnly) || (options?.mode === 'read' && schema.writeOnly)) {\n return undefined\n }\n\n // Use given variables as values\n if (schema['x-variable']) {\n const value = options?.variables?.[schema['x-variable']]\n\n // Return the value if it's defined\n if (value !== undefined) {\n // Type-casting\n if (schema.type === 'number' || schema.type === 'integer') {\n return Number.parseInt(value, 10)\n }\n\n return cache(schema, value)\n }\n }\n\n // Use the first example, if there's an array\n if (Array.isArray(schema.examples) && schema.examples.length > 0) {\n return cache(schema, schema.examples[0])\n }\n\n // Use an example, if there's one\n if (schema.example !== undefined) {\n return cache(schema, schema.example)\n }\n\n // Use a default value, if there's one\n if (schema.default !== undefined) {\n return cache(schema, schema.default)\n }\n\n // enum: [ 'available', 'pending', 'sold' ]\n if (Array.isArray(schema.enum) && schema.enum.length > 0) {\n return cache(schema, schema.enum[0])\n }\n\n // Check if the property is required\n const isObjectOrArray =\n schema.type === 'object' ||\n schema.type === 'array' ||\n !!schema.allOf?.at?.(0) ||\n !!schema.anyOf?.at?.(0) ||\n !!schema.oneOf?.at?.(0)\n if (!isObjectOrArray && options?.omitEmptyAndOptionalProperties === true) {\n const isRequired =\n schema.required === true ||\n parentSchema?.required === true ||\n parentSchema?.required?.includes(name ?? schema.name)\n\n if (!isRequired) {\n return undefined\n }\n }\n\n // Object\n if (schema.type === 'object' || schema.properties !== undefined) {\n const response: Record<string, any> = {}\n let propertyCount = 0\n\n // Regular properties\n if (schema.properties !== undefined) {\n for (const propertyName in schema.properties) {\n if (Object.prototype.hasOwnProperty.call(schema.properties, propertyName)) {\n // Only apply property limit for nested levels (level > 0)\n if (level > 3 && propertyCount >= MAX_PROPERTIES) {\n response['...'] = '[Additional Properties Truncated]'\n break\n }\n\n const property = schema.properties[propertyName]\n const propertyXmlTagName = options?.xml ? property.xml?.name : undefined\n\n const value = getExampleFromSchema(property, options, level + 1, schema, propertyName)\n\n if (typeof value !== 'undefined') {\n response[propertyXmlTagName ?? propertyName] = value\n propertyCount++\n }\n }\n }\n }\n\n // Pattern properties (regex)\n if (schema.patternProperties !== undefined) {\n for (const pattern in schema.patternProperties) {\n if (Object.prototype.hasOwnProperty.call(schema.patternProperties, pattern)) {\n const property = schema.patternProperties[pattern]\n\n // Use the regex pattern as an example key\n const exampleKey = pattern\n\n response[exampleKey] = getExampleFromSchema(property, options, level + 1, schema, exampleKey)\n }\n }\n }\n\n // Additional properties\n if (schema.additionalProperties !== undefined) {\n const anyTypeIsValid =\n // true\n schema.additionalProperties === true ||\n // or an empty object {}\n (typeof schema.additionalProperties === 'object' && !Object.keys(schema.additionalProperties).length)\n\n // Get the custom name for additional properties if available\n const additionalPropertiesName =\n typeof schema.additionalProperties === 'object' &&\n schema.additionalProperties['x-additionalPropertiesName'] &&\n typeof schema.additionalProperties['x-additionalPropertiesName'] === 'string' &&\n schema.additionalProperties['x-additionalPropertiesName'].trim().length > 0\n ? `${schema.additionalProperties['x-additionalPropertiesName'].trim()}*`\n : DEFAULT_ADDITIONAL_PROPERTIES_NAME\n\n if (anyTypeIsValid) {\n response[additionalPropertiesName] = 'anything'\n } else if (schema.additionalProperties !== false) {\n response[additionalPropertiesName] = getExampleFromSchema(schema.additionalProperties, options, level + 1)\n }\n }\n\n if (schema.anyOf !== undefined) {\n Object.assign(response, getExampleFromSchema(schema.anyOf[0], options, level + 1))\n } else if (schema.oneOf !== undefined) {\n Object.assign(response, getExampleFromSchema(schema.oneOf[0], options, level + 1))\n } else if (schema.allOf !== undefined) {\n Object.assign(\n response,\n ...schema.allOf\n .map((item: Record<string, any>) => getExampleFromSchema(item, options, level + 1, schema))\n .filter((item: any) => item !== undefined),\n )\n }\n\n return cache(schema, response)\n }\n\n // Array\n if (schema.type === 'array' || schema.items !== undefined) {\n const itemsXmlTagName = schema?.items?.xml?.name\n const wrapItems = !!(options?.xml && schema.xml?.wrapped && itemsXmlTagName)\n\n if (schema.example !== undefined) {\n return cache(schema, wrapItems ? { [itemsXmlTagName]: schema.example } : schema.example)\n }\n\n // Check whether the array has a anyOf, oneOf, or allOf rule\n if (schema.items) {\n // First handle allOf separately since it needs special handling\n if (schema.items.allOf) {\n // If the first item is an object type, merge all schemas\n if (schema.items.allOf[0].type === 'object') {\n const mergedExample = getExampleFromSchema(\n { type: 'object', allOf: schema.items.allOf },\n options,\n level + 1,\n schema,\n )\n\n return cache(schema, wrapItems ? [{ [itemsXmlTagName]: mergedExample }] : [mergedExample])\n }\n // For non-objects (like strings), collect all examples\n const examples = schema.items.allOf\n .map((item: Record<string, any>) => getExampleFromSchema(item, options, level + 1, schema))\n .filter((item: any) => item !== undefined)\n\n return cache(schema, wrapItems ? examples.map((example: any) => ({ [itemsXmlTagName]: example })) : examples)\n }\n\n // Handle other rules (anyOf, oneOf)\n const rules = ['anyOf', 'oneOf']\n for (const rule of rules) {\n if (!schema.items[rule]) {\n continue\n }\n\n const schemas = schema.items[rule].slice(0, 1)\n const exampleFromRule = schemas\n .map((item: Record<string, any>) => getExampleFromSchema(item, options, level + 1, schema))\n .filter((item: any) => item !== undefined)\n\n return cache(schema, wrapItems ? [{ [itemsXmlTagName]: exampleFromRule }] : exampleFromRule)\n }\n }\n\n // if it has type: 'object', or properties, it's an object\n const isObject = schema.items?.type === 'object' || schema.items?.properties !== undefined\n // if it has type: 'array', or items, it's an array\n const isArray = schema.items?.type === 'array' || schema.items?.items !== undefined\n\n if (schema.items?.type || isObject || isArray) {\n const exampleFromSchema = getExampleFromSchema(schema.items, options, level + 1)\n\n return wrapItems ? [{ [itemsXmlTagName]: exampleFromSchema }] : [exampleFromSchema]\n }\n\n return []\n }\n\n const exampleValues: Record<any, any> = {\n string: guessFromFormat(schema, makeUpRandomData, options?.emptyString),\n boolean: true,\n integer: schema.min ?? 1,\n number: schema.min ?? 1,\n array: [],\n }\n\n if (schema.type !== undefined && exampleValues[schema.type] !== undefined) {\n return cache(schema, exampleValues[schema.type])\n }\n\n const discriminateSchema = schema.oneOf || schema.anyOf\n // Check if property has the `oneOf` | `anyOf` key\n if (Array.isArray(discriminateSchema) && discriminateSchema.length > 0) {\n // Get the first item from the `oneOf` | `anyOf` array\n const firstOneOfItem = discriminateSchema[0]\n\n // Return an example for the first item\n return getExampleFromSchema(firstOneOfItem, options, level + 1)\n }\n\n // Check if schema has the `allOf` key\n if (Array.isArray(schema.allOf)) {\n let example: any = null\n\n // Loop through all `allOf` schemas\n schema.allOf.forEach((allOfItem: Record<string, any>) => {\n // Return an example from the schema\n const newExample = getExampleFromSchema(allOfItem, options, level + 1)\n\n // Merge or overwrite the example\n example =\n typeof newExample === 'object' && typeof example === 'object'\n ? {\n ...(example ?? {}),\n ...newExample,\n }\n : Array.isArray(newExample) && Array.isArray(example)\n ? [...(example ?? {}), ...newExample]\n : newExample\n })\n\n return cache(schema, example)\n }\n\n // Check if schema is a union type\n if (Array.isArray(schema.type)) {\n // Return null if the type is nullable\n if (schema.type.includes('null')) {\n return null\n }\n // Return an example for the first type in the union\n const exampleValue = exampleValues[schema.type[0]]\n if (exampleValue !== undefined) {\n return cache(schema, exampleValue)\n }\n }\n\n // Warn if the type is unknown \u2026\n // console.warn(`[getExampleFromSchema] Unknown property type \"${schema.type}\".`)\n\n // \u2026 and just return null for now.\n return null\n}\n"],
|
|
5
|
-
"mappings": "AAAA,MAAM,kBAAkB;AAExB,MAAM,iBAAiB;AAGvB,MAAM,qCAAqC;AAE3C,MAAM,uBAA+C;AAAA;AAAA,EAEnD,cAAa,oBAAI,KAAK,GAAE,YAAY;AAAA;AAAA,EAEpC,SAAQ,oBAAI,KAAK,GAAE,YAAY,EAAE,MAAM,GAAG,EAAE,CAAC;AAAA,EAC7C,SAAS;AAAA,EACT,YAAY;AAAA;AAAA,EAEZ,aAAa;AAAA;AAAA,EAEb,gBAAgB;AAAA,EAChB,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,iBAAiB;AAAA;AAAA,EAEjB,OAAO;AAAA,EACP,gBAAgB;AAAA,EAChB,YAAY;AAAA,EACZ,SAAS;AAAA;AAAA,EAET,yBAAyB;AAAA;AAAA;AAAA,EAGzB,SAAQ,oBAAI,KAAK,GAAE,YAAY,EAAE,MAAM,GAAG,EAAE,CAAC,EAAG,MAAM,GAAG,EAAE,CAAC;AAAA;AAAA,EAE5D,iBAAiB;AAAA,EACjB,gBAAgB;AAAA,EAChB,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,aAAa;AACf;AAKA,SAAS,gBAAgB,QAA6B,mBAA4B,OAAO,WAAmB,IAAI;AAC9G,MAAI,OAAO,WAAW,UAAU;AAC9B,WAAO,IAAI,KAAK,CAAC,EAAE,GAAG,UAAU;AAAA,EAClC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,GAAG,gBAAgB,CAAC,IAAI,eAAe;AAAA,MAC7F;AAAA,IACF;AAGA,UAAM,WAAW,OAAO,OAAO,SAAS,YAAY,OAAO,OAAO,eAAe;AAEjF,UAAM,UAAU,OAAO,OAAO,SAAS,WAAW,OAAO,OAAO,UAAU;AAE1E,QAAI,OAAO,OAAO,QAAQ,YAAY,SAAS;AAC7C,YAAM,oBAAoB,qBAAqB,OAAO,OAAO,SAAS,QAAQ,CAAC;AAE/E,aAAO,YAAY,CAAC,EAAE,CAAC,eAAe,GAAG,kBAAkB,CAAC,IAAI,CAAC,iBAAiB;AAAA,IACpF;AAEA,WAAO,CAAC;AAAA,EACV;AAEA,QAAM,gBAAkC;AAAA,IACtC,QAAQ,gBAAgB,QAAQ,kBAAkB,SAAS,WAAW;AAAA,IACtE,SAAS;AAAA,IACT,SAAS,OAAO,OAAO;AAAA,IACvB,QAAQ,OAAO,OAAO;AAAA,IACtB,OAAO,CAAC;AAAA,EACV;AAEA,MAAI,OAAO,SAAS,UAAa,cAAc,OAAO,IAAI,MAAM,QAAW;AACzE,WAAO,MAAM,QAAQ,cAAc,OAAO,IAAI,CAAC;AAAA,EACjD;AAEA,QAAM,qBAAqB,OAAO,SAAS,OAAO;AAElD,MAAI,MAAM,QAAQ,kBAAkB,KAAK,mBAAmB,SAAS,GAAG;AAEtE,UAAM,
|
|
4
|
+
"sourcesContent": ["const MAX_LEVELS_DEEP = 5\n/** Sets the max number of properties after the third level to prevent exponential horizontal growth */\nconst MAX_PROPERTIES = 10\n\n/** The default name for additional properties. */\nconst DEFAULT_ADDITIONAL_PROPERTIES_NAME = 'propertyName*'\n\nconst genericExampleValues: Record<string, string> = {\n // 'date-time': '1970-01-01T00:00:00Z',\n 'date-time': new Date().toISOString(),\n // 'date': '1970-01-01',\n 'date': new Date().toISOString().split('T')[0]!,\n 'email': 'hello@example.com',\n 'hostname': 'example.com',\n // https://tools.ietf.org/html/rfc6531#section-3.3\n 'idn-email': 'jane.doe@example.com',\n // https://tools.ietf.org/html/rfc5890#section-2.3.2.3\n 'idn-hostname': 'example.com',\n 'ipv4': '127.0.0.1',\n 'ipv6': '51d4:7fab:bfbf:b7d7:b2cb:d4b4:3dad:d998',\n 'iri-reference': '/entitiy/1',\n // https://tools.ietf.org/html/rfc3987\n 'iri': 'https://example.com/entity/123',\n 'json-pointer': '/nested/objects',\n 'password': 'super-secret',\n 'regex': '/[a-z]/',\n // https://tools.ietf.org/html/draft-handrews-relative-json-pointer-01\n 'relative-json-pointer': '1/nested/objects',\n // full-time in https://tools.ietf.org/html/rfc3339#section-5.6\n // 'time': '00:00:00Z',\n 'time': new Date().toISOString().split('T')[1]!.split('.')[0]!,\n // either a URI or relative-reference https://tools.ietf.org/html/rfc3986#section-4.1\n 'uri-reference': '../folder',\n 'uri-template': 'https://example.com/{id}',\n 'uri': 'https://example.com',\n 'uuid': '123e4567-e89b-12d3-a456-426614174000',\n 'object-id': '6592008029c8c3e4dc76256c',\n}\n\n/**\n * We can use the `format` to generate some random values.\n */\nfunction guessFromFormat(schema: Record<string, any>, makeUpRandomData: boolean = false, fallback: string = '') {\n if (schema.format === 'binary') {\n return new File([''], 'filename')\n }\n return makeUpRandomData ? (genericExampleValues[schema.format] ?? fallback) : ''\n}\n\n/** Map of all the results */\nconst resultCache = new WeakMap<Record<string, any>, any>()\n\n/** Store result in the cache, and return the result */\nfunction cache(schema: Record<string, any>, result: unknown) {\n // Avoid unnecessary WeakMap operations for primitive values\n if (typeof result !== 'object' || result === null) {\n return result\n }\n\n resultCache.set(schema, result)\n\n return result\n}\n\n/**\n * This function takes an OpenAPI schema and generates an example from it\n */\nexport const getExampleFromSchema = (\n schema: Record<string, any>,\n options?: {\n /**\n * The fallback string for empty string values.\n * @default ''\n */\n emptyString?: string\n /**\n * Whether to use the XML tag names as keys\n * @default false\n */\n xml?: boolean\n /**\n * Whether to show read-only/write-only properties. Otherwise all properties are shown.\n * @default undefined\n */\n mode?: 'read' | 'write'\n /**\n * Dynamic values to add to the example.\n */\n variables?: Record<string, any>\n /**\n * Whether to omit empty and optional properties.\n * @default false\n */\n omitEmptyAndOptionalProperties?: boolean\n },\n level: number = 0,\n parentSchema?: Record<string, any>,\n name?: string,\n): any => {\n // Check if the result is already cached\n if (resultCache.has(schema)) {\n return resultCache.get(schema)\n }\n\n // Check whether it's a circular reference\n if (level === MAX_LEVELS_DEEP + 1) {\n try {\n // Fails if it contains a circular reference\n JSON.stringify(schema)\n } catch {\n return '[Circular Reference]'\n }\n }\n\n // Sometimes, we just want the structure and no values.\n // But if `emptyString` is set, we do want to see some values.\n const makeUpRandomData = !!options?.emptyString\n\n // If the property is deprecated anyway, we don't want to show it.\n if (schema.deprecated) {\n return undefined\n }\n\n // Check if the property is read-only/write-only\n if ((options?.mode === 'write' && schema.readOnly) || (options?.mode === 'read' && schema.writeOnly)) {\n return undefined\n }\n\n // Use given variables as values\n if (schema['x-variable']) {\n const value = options?.variables?.[schema['x-variable']]\n\n // Return the value if it's defined\n if (value !== undefined) {\n // Type-casting\n if (schema.type === 'number' || schema.type === 'integer') {\n return Number.parseInt(value, 10)\n }\n\n return cache(schema, value)\n }\n }\n\n // Use the first example, if there's an array\n if (Array.isArray(schema.examples) && schema.examples.length > 0) {\n return cache(schema, schema.examples[0])\n }\n\n // Use an example, if there's one\n if (schema.example !== undefined) {\n return cache(schema, schema.example)\n }\n\n // Use a default value, if there's one\n if (schema.default !== undefined) {\n return cache(schema, schema.default)\n }\n\n // enum: [ 'available', 'pending', 'sold' ]\n if (Array.isArray(schema.enum) && schema.enum.length > 0) {\n return cache(schema, schema.enum[0])\n }\n\n // Check if the property is required\n const isObjectOrArray =\n schema.type === 'object' ||\n schema.type === 'array' ||\n !!schema.allOf?.at?.(0) ||\n !!schema.anyOf?.at?.(0) ||\n !!schema.oneOf?.at?.(0)\n if (!isObjectOrArray && options?.omitEmptyAndOptionalProperties === true) {\n const isRequired =\n schema.required === true ||\n parentSchema?.required === true ||\n parentSchema?.required?.includes(name ?? schema.name)\n\n if (!isRequired) {\n return undefined\n }\n }\n\n // Object\n if (schema.type === 'object' || schema.properties !== undefined) {\n const response: Record<string, any> = {}\n let propertyCount = 0\n\n // Regular properties\n if (schema.properties !== undefined) {\n for (const propertyName in schema.properties) {\n if (Object.prototype.hasOwnProperty.call(schema.properties, propertyName)) {\n // Only apply property limit for nested levels (level > 0)\n if (level > 3 && propertyCount >= MAX_PROPERTIES) {\n response['...'] = '[Additional Properties Truncated]'\n break\n }\n\n const property = schema.properties[propertyName]\n const propertyXmlTagName = options?.xml ? property.xml?.name : undefined\n\n const value = getExampleFromSchema(property, options, level + 1, schema, propertyName)\n\n if (typeof value !== 'undefined') {\n response[propertyXmlTagName ?? propertyName] = value\n propertyCount++\n }\n }\n }\n }\n\n // Pattern properties (regex)\n if (schema.patternProperties !== undefined) {\n for (const pattern in schema.patternProperties) {\n if (Object.prototype.hasOwnProperty.call(schema.patternProperties, pattern)) {\n const property = schema.patternProperties[pattern]\n\n // Use the regex pattern as an example key\n const exampleKey = pattern\n\n response[exampleKey] = getExampleFromSchema(property, options, level + 1, schema, exampleKey)\n }\n }\n }\n\n // Additional properties\n if (schema.additionalProperties !== undefined) {\n const anyTypeIsValid =\n // true\n schema.additionalProperties === true ||\n // or an empty object {}\n (typeof schema.additionalProperties === 'object' && !Object.keys(schema.additionalProperties).length)\n\n // Get the custom name for additional properties if available\n const additionalPropertiesName =\n typeof schema.additionalProperties === 'object' &&\n schema.additionalProperties['x-additionalPropertiesName'] &&\n typeof schema.additionalProperties['x-additionalPropertiesName'] === 'string' &&\n schema.additionalProperties['x-additionalPropertiesName'].trim().length > 0\n ? `${schema.additionalProperties['x-additionalPropertiesName'].trim()}*`\n : DEFAULT_ADDITIONAL_PROPERTIES_NAME\n\n if (anyTypeIsValid) {\n response[additionalPropertiesName] = 'anything'\n } else if (schema.additionalProperties !== false) {\n response[additionalPropertiesName] = getExampleFromSchema(schema.additionalProperties, options, level + 1)\n }\n }\n\n if (schema.anyOf !== undefined) {\n Object.assign(response, getExampleFromSchema(schema.anyOf[0], options, level + 1))\n } else if (schema.oneOf !== undefined) {\n Object.assign(response, getExampleFromSchema(schema.oneOf[0], options, level + 1))\n } else if (schema.allOf !== undefined) {\n Object.assign(\n response,\n ...schema.allOf\n .map((item: Record<string, any>) => getExampleFromSchema(item, options, level + 1, schema))\n .filter((item: any) => item !== undefined),\n )\n }\n\n return cache(schema, response)\n }\n\n // Array\n if (schema.type === 'array' || schema.items !== undefined) {\n const itemsXmlTagName = schema?.items?.xml?.name\n const wrapItems = !!(options?.xml && schema.xml?.wrapped && itemsXmlTagName)\n\n if (schema.example !== undefined) {\n return cache(schema, wrapItems ? { [itemsXmlTagName]: schema.example } : schema.example)\n }\n\n // Check whether the array has a anyOf, oneOf, or allOf rule\n if (schema.items) {\n // First handle allOf separately since it needs special handling\n if (schema.items.allOf) {\n // If the first item is an object type, merge all schemas\n if (schema.items.allOf[0].type === 'object') {\n const mergedExample = getExampleFromSchema(\n { type: 'object', allOf: schema.items.allOf },\n options,\n level + 1,\n schema,\n )\n\n return cache(schema, wrapItems ? [{ [itemsXmlTagName]: mergedExample }] : [mergedExample])\n }\n // For non-objects (like strings), collect all examples\n const examples = schema.items.allOf\n .map((item: Record<string, any>) => getExampleFromSchema(item, options, level + 1, schema))\n .filter((item: any) => item !== undefined)\n\n return cache(schema, wrapItems ? examples.map((example: any) => ({ [itemsXmlTagName]: example })) : examples)\n }\n\n // Handle other rules (anyOf, oneOf)\n const rules = ['anyOf', 'oneOf']\n for (const rule of rules) {\n if (!schema.items[rule]) {\n continue\n }\n\n const schemas = schema.items[rule].slice(0, 1)\n const exampleFromRule = schemas\n .map((item: Record<string, any>) => getExampleFromSchema(item, options, level + 1, schema))\n .filter((item: any) => item !== undefined)\n\n return cache(schema, wrapItems ? [{ [itemsXmlTagName]: exampleFromRule }] : exampleFromRule)\n }\n }\n\n // if it has type: 'object', or properties, it's an object\n const isObject = schema.items?.type === 'object' || schema.items?.properties !== undefined\n // if it has type: 'array', or items, it's an array\n const isArray = schema.items?.type === 'array' || schema.items?.items !== undefined\n\n if (schema.items?.type || isObject || isArray) {\n const exampleFromSchema = getExampleFromSchema(schema.items, options, level + 1)\n\n return wrapItems ? [{ [itemsXmlTagName]: exampleFromSchema }] : [exampleFromSchema]\n }\n\n return []\n }\n\n const exampleValues: Record<any, any> = {\n string: guessFromFormat(schema, makeUpRandomData, options?.emptyString),\n boolean: true,\n integer: schema.min ?? 1,\n number: schema.min ?? 1,\n array: [],\n }\n\n if (schema.type !== undefined && exampleValues[schema.type] !== undefined) {\n return cache(schema, exampleValues[schema.type])\n }\n\n const discriminateSchema = schema.oneOf || schema.anyOf\n // Check if property has the `oneOf` | `anyOf` key\n if (Array.isArray(discriminateSchema) && discriminateSchema.length > 0) {\n // Find the first non-null type in the oneOf/anyOf array\n const firstNonNullItem = discriminateSchema.find((item) => item.type !== 'null')\n\n if (firstNonNullItem) {\n // Return an example for the first non-null item\n return getExampleFromSchema(firstNonNullItem, options, level + 1)\n }\n\n // If all items are null, return null\n return null\n }\n\n // Check if schema has the `allOf` key\n if (Array.isArray(schema.allOf)) {\n let example: any = null\n\n // Loop through all `allOf` schemas\n schema.allOf.forEach((allOfItem: Record<string, any>) => {\n // Return an example from the schema\n const newExample = getExampleFromSchema(allOfItem, options, level + 1)\n\n // Merge or overwrite the example\n example =\n typeof newExample === 'object' && typeof example === 'object'\n ? {\n ...(example ?? {}),\n ...newExample,\n }\n : Array.isArray(newExample) && Array.isArray(example)\n ? [...(example ?? {}), ...newExample]\n : newExample\n })\n\n return cache(schema, example)\n }\n\n // Check if schema is a union type\n if (Array.isArray(schema.type)) {\n // Return null if the type is nullable\n if (schema.type.includes('null')) {\n return null\n }\n // Return an example for the first type in the union\n const exampleValue = exampleValues[schema.type[0]]\n if (exampleValue !== undefined) {\n return cache(schema, exampleValue)\n }\n }\n\n // Warn if the type is unknown \u2026\n // console.warn(`[getExampleFromSchema] Unknown property type \"${schema.type}\".`)\n\n // \u2026 and just return null for now.\n return null\n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;AAC9B,aAAO,MAAM,QAAQ,YAAY;AAAA,IACnC;AAAA,EACF;AAMA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -33,7 +33,7 @@ function getRequestBodyFromOperation(operation, selectedExampleKey, omitEmptyAnd
|
|
|
33
33
|
if (selectedExample) {
|
|
34
34
|
return {
|
|
35
35
|
mimeType,
|
|
36
|
-
text: prettyPrintJson(selectedExample
|
|
36
|
+
text: prettyPrintJson("value" in selectedExample ? selectedExample.value : selectedExample)
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
39
|
const bodyParameters = getParametersFromOperation(
|
|
@@ -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 } from '@scalar/types/legacy'\n\nimport type { Operation } from '@/entities/spec'\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<Operation, 'requestBody' | 'parameters'>,\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.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's 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
|
|
5
|
-
"mappings": "AAAA,SAAS,gBAAgB;AAIzB,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;AAE3E,cAAQ,KAAK,UAAU,KAAK;AAAA,IAC9B;AAEA,WAAO,CAAC,EAAE,MAAM,MAAM,CAAC;AAAA,EACzB,CAAC;AACH;AAEA,MAAM,oBAAmC;AAAA,EACvC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAKO,SAAS,4BACd,WACA,oBACA,gCAQO;AACP,QAAM,kBAAkB,UAAU,aAAa;AAC/C,QAAM,UAAU,wBAAwB,eAAe;AAGvD,QAAM,WACJ,kBAAkB,KAAK,CAAC,oBAAoB,CAAC,CAAC,UAAU,eAAe,CAAC,MACtE,OAAO,KAAK,WAAW,CAAC,CAAC,EAAE,CAAC,KAAK;AAGrC,QAAM,aAAa,SAAS,SAAS,MAAM,KAAK,SAAS,SAAS,OAAO;AAGzE,QAAM,WAAW,UAAU,QAAQ,GAAG,YAAY,UAAU,kBAAkB,GAAG;AAGjF,QAAM,kBAAkB,WAAW,sBAAsB,OAAO,KAAK,YAAY,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE;AAE7F,MAAI,iBAAiB;AACnB,WAAO;AAAA,MACL;AAAA,MACA,MAAM,gBAAgB,
|
|
4
|
+
"sourcesContent": ["import { json2xml } from '@scalar/helpers/file/json2xml'\nimport type { ContentType } from '@scalar/types/legacy'\n\nimport type { Operation } from '@/entities/spec'\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<Operation, 'requestBody' | 'parameters'>,\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.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's use the first example\n const selectedExample = examples?.[selectedExampleKey ?? Object.keys(examples ?? {})[0] ?? '']\n\n if (selectedExample) {\n return {\n mimeType,\n text: prettyPrintJson('value' in selectedExample ? selectedExample.value : selectedExample),\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.parameters ?? [],\n // TODO: Add path parameters\n [], // operation.path ?? [],\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.parameters ?? [],\n // TODO: Add path parameters\n [], // operation.path ?? [],\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;AAIzB,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;AAE3E,cAAQ,KAAK,UAAU,KAAK;AAAA,IAC9B;AAEA,WAAO,CAAC,EAAE,MAAM,MAAM,CAAC;AAAA,EACzB,CAAC;AACH;AAEA,MAAM,oBAAmC;AAAA,EACvC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAKO,SAAS,4BACd,WACA,oBACA,gCAQO;AACP,QAAM,kBAAkB,UAAU,aAAa;AAC/C,QAAM,UAAU,wBAAwB,eAAe;AAGvD,QAAM,WACJ,kBAAkB,KAAK,CAAC,oBAAoB,CAAC,CAAC,UAAU,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.4.
|
|
19
|
+
"version": "0.4.17",
|
|
20
20
|
"engines": {
|
|
21
21
|
"node": ">=20"
|
|
22
22
|
},
|
|
@@ -99,22 +99,22 @@
|
|
|
99
99
|
"type-fest": "4.41.0",
|
|
100
100
|
"yaml": "2.8.0",
|
|
101
101
|
"zod": "3.24.1",
|
|
102
|
-
"@scalar/
|
|
103
|
-
"@scalar/
|
|
104
|
-
"@scalar/
|
|
105
|
-
"@scalar/
|
|
106
|
-
"@scalar/
|
|
107
|
-
"@scalar/
|
|
102
|
+
"@scalar/helpers": "0.0.7",
|
|
103
|
+
"@scalar/object-utils": "1.2.3",
|
|
104
|
+
"@scalar/openapi-types": "0.3.7",
|
|
105
|
+
"@scalar/themes": "0.13.12",
|
|
106
|
+
"@scalar/workspace-store": "0.12.0",
|
|
107
|
+
"@scalar/types": "0.2.11"
|
|
108
108
|
},
|
|
109
109
|
"devDependencies": {
|
|
110
110
|
"@types/node": "^22.9.0",
|
|
111
111
|
"type-fest": "^4.20.0",
|
|
112
|
-
"vite": "
|
|
113
|
-
"vitest": "^
|
|
112
|
+
"vite": "6.1.6",
|
|
113
|
+
"vitest": "^3.2.4",
|
|
114
114
|
"zod-to-ts": "github:amritk/zod-to-ts#build",
|
|
115
115
|
"@scalar/build-tooling": "0.2.4",
|
|
116
|
-
"@scalar/openapi-parser": "0.
|
|
117
|
-
"@scalar/openapi-types": "0.3.
|
|
116
|
+
"@scalar/openapi-parser": "0.19.0",
|
|
117
|
+
"@scalar/openapi-types": "0.3.7"
|
|
118
118
|
},
|
|
119
119
|
"scripts": {
|
|
120
120
|
"build": "scalar-build-esbuild",
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { ScalarState } from '@scalar/types/legacy';
|
|
2
|
-
declare global {
|
|
3
|
-
interface Window {
|
|
4
|
-
__SCALAR__: ScalarState;
|
|
5
|
-
}
|
|
6
|
-
}
|
|
7
|
-
export declare const defaultStateFactory: () => ScalarState;
|
|
8
|
-
/**
|
|
9
|
-
* This allows us to access the server state in the front-end
|
|
10
|
-
*/
|
|
11
|
-
export declare const ssrState: ScalarState;
|
|
12
|
-
//# sourceMappingURL=ssr-state.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ssr-state.d.ts","sourceRoot":"","sources":["../../src/helpers/ssr-state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAEvD,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,UAAU,EAAE,WAAW,CAAA;KACxB;CACF;AAED,eAAO,MAAM,mBAAmB,QAAO,WAAmB,CAAA;AAE1D;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,WAC+E,CAAA"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/helpers/ssr-state.ts"],
|
|
4
|
-
"sourcesContent": ["import type { ScalarState } from '@scalar/types/legacy'\n\ndeclare global {\n interface Window {\n __SCALAR__: ScalarState\n }\n}\n\nexport const defaultStateFactory = (): ScalarState => ({})\n\n/**\n * This allows us to access the server state in the front-end\n */\nexport const ssrState: ScalarState =\n typeof window !== 'undefined' ? (window.__SCALAR__ ?? defaultStateFactory()) : defaultStateFactory()\n"],
|
|
5
|
-
"mappings": "AAQO,MAAM,sBAAsB,OAAoB,CAAC;AAKjD,MAAM,WACX,OAAO,WAAW,cAAe,OAAO,cAAc,oBAAoB,IAAK,oBAAoB;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|