| Server IP : 35.80.110.71 / Your IP : 216.73.216.221 Web Server : Apache/2.4.58 (Ubuntu) System : Linux ip-172-31-21-44 6.17.0-1019-aws #19~24.04.1-Ubuntu SMP Tue Jun 23 18:53:06 UTC 2026 x86_64 User : ubuntu ( 1000) PHP Version : 8.3.31 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/foyer-web/current/node_modules/@scalar/api-reference/dist/helpers/ |
Upload File : |
{"version":3,"file":"openapi.js","names":[],"sources":["../../src/helpers/openapi.ts"],"sourcesContent":["import { getResolvedRef } from '@scalar/workspace-store/helpers/get-resolved-ref'\nimport type {\n MediaTypeObject,\n OpenApiDocument,\n OperationObject,\n ParameterObject,\n ReferenceType,\n SchemaObject,\n SchemaReferenceType,\n} from '@scalar/workspace-store/schemas/v3.1/strict/openapi-document'\nimport { isObjectSchema } from '@scalar/workspace-store/schemas/v3.1/strict/type-guards'\n\nconst isSchemaObject = (value: unknown): value is SchemaObject => typeof value === 'object' && value !== null\n\n/**\n * Resolves a schema reference from workspace-store to a SchemaObject.\n * Returns undefined when a reference exists but has not been resolved yet.\n */\nfunction resolveSchemaRef(ref: SchemaReferenceType<SchemaObject>): SchemaObject | undefined {\n if (typeof ref === 'object' && ref !== null && '$ref' in ref) {\n return isSchemaObject(ref['$ref-value']) ? ref['$ref-value'] : undefined\n }\n\n return ref\n}\n\nfunction pushUnique(target: string[], value: string | undefined): void {\n if (!value) {\n return\n }\n if (!target.includes(value)) {\n target.push(value)\n }\n}\n\ntype CollectOptions = {\n visit: (key: string, schema: SchemaObject | undefined) => void\n visited: Set<SchemaObject>\n maxPropertyDepth: number\n}\n\n/**\n * Recursively visits every property of a schema, descending transparently through composition\n * keywords (`oneOf`, `anyOf`, `allOf`) and one level into nested object properties.\n *\n * Composition is treated as transparent — a `oneOf` of two object variants is *the same level* as a\n * single object, just expressed as multiple shapes. Property nesting is capped to keep the index\n * focused on shallow, commonly-searched fields. A visited-set keyed by resolved-schema identity\n * guards against recursive (`Tree → Tree`) schemas.\n */\nfunction collectSchemaProperties(schema: SchemaObject | undefined, options: CollectOptions, propertyDepth = 0): void {\n if (!schema || options.visited.has(schema)) {\n return\n }\n options.visited.add(schema)\n\n const variants = [...(schema.oneOf ?? []), ...(schema.anyOf ?? []), ...(schema.allOf ?? [])]\n variants.forEach((variantRef) => {\n collectSchemaProperties(resolveSchemaRef(variantRef), options, propertyDepth)\n })\n\n if (isObjectSchema(schema) && schema.properties) {\n Object.entries(schema.properties).forEach(([key, propRef]) => {\n const property = resolveSchemaRef(propRef)\n options.visit(key, property)\n if (propertyDepth + 1 < options.maxPropertyDepth) {\n collectSchemaProperties(property, options, propertyDepth + 1)\n }\n })\n }\n}\n\n/**\n * Walks the request body schemas of an operation and yields each property schema with its key.\n */\nfunction forEachRequestBodyProperty(\n operation: OperationObject,\n visit: (key: string, schema: SchemaObject | undefined) => void,\n): void {\n const content = getResolvedRef(operation?.requestBody)?.content\n if (!content) {\n return\n }\n\n const visited = new Set<SchemaObject>()\n Object.values(content).forEach((media) => {\n const resolvedMedia = getResolvedRef(media) as MediaTypeObject | undefined\n const schema = getResolvedRef(resolvedMedia?.schema)\n collectSchemaProperties(schema, { visit, visited, maxPropertyDepth: 2 })\n })\n}\n\n/**\n * Extracts the names of every parameter on an operation.\n *\n * The returned strings contain only parameter names (e.g. `userId`, `limit`) so they can be indexed\n * as a high-signal field for search. Filter-style metadata like `REQUIRED`, `optional`, `query` and\n * the schema type are intentionally excluded — those tokens dilute fuzzy matches and produce false\n * positives for queries like `query` or `integer`.\n */\nexport function extractParameterNames(parameters: ReferenceType<ParameterObject>[]): string[] {\n const names: string[] = []\n\n parameters.forEach((parameter) => {\n const resolved = getResolvedRef(parameter)\n pushUnique(names, resolved?.name)\n })\n\n return names\n}\n\n/**\n * Extracts the descriptions of every parameter on an operation.\n *\n * Kept separate from parameter names so the search index can weight each independently.\n */\nexport function extractParameterDescriptions(parameters: ReferenceType<ParameterObject>[]): string[] {\n const descriptions: string[] = []\n\n parameters.forEach((parameter) => {\n const resolved = getResolvedRef(parameter)\n pushUnique(descriptions, resolved?.description)\n })\n\n return descriptions\n}\n\n/**\n * Extracts the names of properties from the request body schema(s) of an operation.\n *\n * Walks every media type and includes both top-level and one level of nested property names so\n * common fields like `email` or `username` surface in search regardless of how the body is shaped.\n */\nexport function extractBodyFieldNames(operation: OperationObject): string[] {\n const names: string[] = []\n\n forEachRequestBodyProperty(operation, (key) => {\n pushUnique(names, key)\n })\n\n return names\n}\n\n/**\n * Extracts the descriptions of properties from the request body schema(s) of an operation.\n */\nexport function extractBodyDescriptions(operation: OperationObject): string[] {\n const descriptions: string[] = []\n\n forEachRequestBodyProperty(operation, (_key, schema) => {\n if (schema && 'description' in schema && typeof schema.description === 'string') {\n pushUnique(descriptions, schema.description)\n }\n })\n\n return descriptions\n}\n\n/**\n * Extracts the property names of a schema for the search index.\n *\n * Same depth and composition behavior as `extractBodyFieldNames` — descends transparently through\n * `oneOf`/`anyOf`/`allOf`, walks one level into nested object properties, dedupes.\n */\nexport function extractSchemaFieldNames(schema: SchemaObject | undefined): string[] {\n const names: string[] = []\n collectSchemaProperties(schema, {\n visit: (key) => pushUnique(names, key),\n visited: new Set<SchemaObject>(),\n maxPropertyDepth: 2,\n })\n return names\n}\n\n/**\n * Extracts the property descriptions of a schema for the search index.\n */\nexport function extractSchemaDescriptions(schema: SchemaObject | undefined): string[] {\n const descriptions: string[] = []\n collectSchemaProperties(schema, {\n visit: (_key, propertySchema) => {\n if (propertySchema && 'description' in propertySchema && typeof propertySchema.description === 'string') {\n pushUnique(descriptions, propertySchema.description)\n }\n },\n visited: new Set<SchemaObject>(),\n maxPropertyDepth: 2,\n })\n return descriptions\n}\n\n/**\n * Deep merge for objects\n */\nexport function deepMerge(source: Record<any, any>, target: Record<any, any>) {\n for (const [key, val] of Object.entries(source)) {\n if (val !== null && typeof val === 'object') {\n target[key] ??= new val.__proto__.constructor()\n deepMerge(val, target[key])\n } else if (typeof val !== 'undefined') {\n target[key] = val\n }\n }\n\n return target\n}\n\n/**\n * Creates an empty specification object.\n * The returning object has the same structure as a valid OpenAPI specification, but everything is empty.\n */\nexport function createEmptySpecification(partialSpecification?: Partial<OpenApiDocument>) {\n const emptySpecification = {\n openapi: '3.1.0',\n info: {\n title: '',\n description: '',\n termsOfService: '',\n version: '',\n license: {\n name: '',\n url: '',\n },\n contact: {\n email: '',\n },\n },\n servers: [],\n tags: [],\n 'x-scalar-original-document-hash': '',\n }\n\n if (!partialSpecification) {\n return emptySpecification as OpenApiDocument\n }\n\n deepMerge(partialSpecification, emptySpecification)\n\n return emptySpecification as OpenApiDocument\n}\n"],"mappings":";;;AAYA,IAAM,kBAAkB,UAA0C,OAAO,UAAU,YAAY,UAAU;;;;;AAMzG,SAAS,iBAAiB,KAAkE;AAC1F,KAAI,OAAO,QAAQ,YAAY,QAAQ,QAAQ,UAAU,IACvD,QAAO,eAAe,IAAI,cAAc,GAAG,IAAI,gBAAgB,KAAA;AAGjE,QAAO;;AAGT,SAAS,WAAW,QAAkB,OAAiC;AACrE,KAAI,CAAC,MACH;AAEF,KAAI,CAAC,OAAO,SAAS,MAAM,CACzB,QAAO,KAAK,MAAM;;;;;;;;;;;AAmBtB,SAAS,wBAAwB,QAAkC,SAAyB,gBAAgB,GAAS;AACnH,KAAI,CAAC,UAAU,QAAQ,QAAQ,IAAI,OAAO,CACxC;AAEF,SAAQ,QAAQ,IAAI,OAAO;AAEV;EAAC,GAAI,OAAO,SAAS,EAAE;EAAG,GAAI,OAAO,SAAS,EAAE;EAAG,GAAI,OAAO,SAAS,EAAE;EAAE,CACnF,SAAS,eAAe;AAC/B,0BAAwB,iBAAiB,WAAW,EAAE,SAAS,cAAc;GAC7E;AAEF,KAAI,eAAe,OAAO,IAAI,OAAO,WACnC,QAAO,QAAQ,OAAO,WAAW,CAAC,SAAS,CAAC,KAAK,aAAa;EAC5D,MAAM,WAAW,iBAAiB,QAAQ;AAC1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