fumadocs-openapi 10.3.16 → 10.3.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/css/generated/shared.css +1 -0
- package/dist/generate-file.js +1 -2
- package/dist/generate-file.js.map +1 -1
- package/dist/index.js +1 -2
- package/dist/playground/client.d.ts +4 -3
- package/dist/playground/client.d.ts.map +1 -1
- package/dist/playground/client.js +2 -4
- package/dist/playground/client.js.map +1 -1
- package/dist/playground/components/inputs.js +2 -4
- package/dist/playground/components/inputs.js.map +1 -1
- package/dist/playground/components/oauth-dialog.js +1 -2
- package/dist/playground/components/oauth-dialog.js.map +1 -1
- package/dist/playground/components/server-select.js +2 -4
- package/dist/playground/components/server-select.js.map +1 -1
- package/dist/playground/fetcher.js +1 -2
- package/dist/playground/fetcher.js.map +1 -1
- package/dist/playground/index.d.ts +2 -7
- package/dist/playground/index.d.ts.map +1 -1
- package/dist/playground/index.js +23 -3
- package/dist/playground/index.js.map +1 -1
- package/dist/playground/lazy.js +2 -4
- package/dist/playground/lazy.js.map +1 -1
- package/dist/playground/schema.js +1 -2
- package/dist/playground/schema.js.map +1 -1
- package/dist/playground/status-info.js +1 -2
- package/dist/playground/status-info.js.map +1 -1
- package/dist/requests/generators/all.js +1 -2
- package/dist/requests/generators/all.js.map +1 -1
- package/dist/requests/generators/csharp.js +1 -2
- package/dist/requests/generators/csharp.js.map +1 -1
- package/dist/requests/generators/curl.js +1 -2
- package/dist/requests/generators/curl.js.map +1 -1
- package/dist/requests/generators/go.js +1 -2
- package/dist/requests/generators/go.js.map +1 -1
- package/dist/requests/generators/index.js +1 -1
- package/dist/requests/generators/java.js +1 -2
- package/dist/requests/generators/java.js.map +1 -1
- package/dist/requests/generators/javascript.js +1 -2
- package/dist/requests/generators/javascript.js.map +1 -1
- package/dist/requests/generators/python.js +1 -2
- package/dist/requests/generators/python.js.map +1 -1
- package/dist/requests/media/adapter.js +2 -3
- package/dist/requests/media/adapter.js.map +1 -1
- package/dist/requests/media/encode.d.ts.map +1 -1
- package/dist/requests/media/encode.js +1 -2
- package/dist/requests/media/encode.js.map +1 -1
- package/dist/requests/media/resolve-adapter.js +1 -1
- package/dist/requests/media/resolve-adapter.js.map +1 -1
- package/dist/requests/string-utils.js +1 -2
- package/dist/requests/string-utils.js.map +1 -1
- package/dist/requests/to-python-object.js +1 -1
- package/dist/scalar/client.js +2 -4
- package/dist/scalar/client.js.map +1 -1
- package/dist/scalar/index.js +1 -2
- package/dist/scalar/index.js.map +1 -1
- package/dist/server/create.js +1 -2
- package/dist/server/create.js.map +1 -1
- package/dist/server/index.js +1 -2
- package/dist/server/proxy.js +1 -1
- package/dist/server/proxy.js.map +1 -1
- package/dist/server/source-api.js +1 -2
- package/dist/server/source-api.js.map +1 -1
- package/dist/ui/api-page.js +1 -2
- package/dist/ui/api-page.js.map +1 -1
- package/dist/ui/base.js +1 -2
- package/dist/ui/base.js.map +1 -1
- package/dist/ui/client/index.js +2 -3
- package/dist/ui/client/index.js.map +1 -1
- package/dist/ui/client/storage-key.js +1 -2
- package/dist/ui/client/storage-key.js.map +1 -1
- package/dist/ui/components/accordion.js +2 -4
- package/dist/ui/components/accordion.js.map +1 -1
- package/dist/ui/components/dialog.js +3 -5
- package/dist/ui/components/dialog.js.map +1 -1
- package/dist/ui/components/input.js +1 -2
- package/dist/ui/components/input.js.map +1 -1
- package/dist/ui/components/method-label.js +1 -2
- package/dist/ui/components/method-label.js.map +1 -1
- package/dist/ui/components/select.js +2 -3
- package/dist/ui/components/select.js.map +1 -1
- package/dist/ui/contexts/api.js +2 -4
- package/dist/ui/contexts/api.js.map +1 -1
- package/dist/ui/contexts/api.lazy.js +2 -4
- package/dist/ui/contexts/api.lazy.js.map +1 -1
- package/dist/ui/full.client.js +2 -4
- package/dist/ui/full.client.js.map +1 -1
- package/dist/ui/full.js +1 -2
- package/dist/ui/full.js.map +1 -1
- package/dist/ui/index.js +1 -2
- package/dist/ui/operation/client.js +2 -4
- package/dist/ui/operation/client.js.map +1 -1
- package/dist/ui/operation/index.js +1 -2
- package/dist/ui/operation/index.js.map +1 -1
- package/dist/ui/operation/request-tabs.js +1 -2
- package/dist/ui/operation/request-tabs.js.map +1 -1
- package/dist/ui/operation/response-tabs.js +1 -2
- package/dist/ui/operation/response-tabs.js.map +1 -1
- package/dist/ui/operation/usage-tabs/client.js +4 -7
- package/dist/ui/operation/usage-tabs/client.js.map +1 -1
- package/dist/ui/operation/usage-tabs/index.js +1 -2
- package/dist/ui/operation/usage-tabs/index.js.map +1 -1
- package/dist/ui/operation/usage-tabs/lazy.js +2 -4
- package/dist/ui/operation/usage-tabs/lazy.js.map +1 -1
- package/dist/ui/schema/client.js +2 -4
- package/dist/ui/schema/client.js.map +1 -1
- package/dist/ui/schema/index.js +1 -2
- package/dist/ui/schema/index.js.map +1 -1
- package/dist/ui/schema/lazy.js +2 -4
- package/dist/ui/schema/lazy.js.map +1 -1
- package/dist/utils/cn.js +1 -2
- package/dist/utils/deep-equal.js +1 -1
- package/dist/utils/id-to-title.js +1 -1
- package/dist/utils/lazy.js +1 -2
- package/dist/utils/lazy.js.map +1 -1
- package/dist/utils/merge-schema.js +1 -2
- package/dist/utils/merge-schema.js.map +1 -1
- package/dist/utils/pages/builder.js +1 -2
- package/dist/utils/pages/builder.js.map +1 -1
- package/dist/utils/pages/preset-auto.js +1 -2
- package/dist/utils/pages/preset-auto.js.map +1 -1
- package/dist/utils/pages/to-body.js +1 -1
- package/dist/utils/pages/to-static-data.js +1 -2
- package/dist/utils/pages/to-static-data.js.map +1 -1
- package/dist/utils/pages/to-text.js +1 -2
- package/dist/utils/pages/to-text.js.map +1 -1
- package/dist/utils/process-document.js +3 -5
- package/dist/utils/process-document.js.map +1 -1
- package/dist/utils/remove-undefined.js +1 -1
- package/dist/utils/remove-undefined.js.map +1 -1
- package/dist/utils/schema-to-string.js +1 -1
- package/dist/utils/schema-to-string.js.map +1 -1
- package/dist/utils/schema.js +1 -2
- package/dist/utils/schema.js.map +1 -1
- package/dist/utils/url.js +1 -1
- package/dist/utils/use-query.js +1 -2
- package/dist/utils/use-query.js.map +1 -1
- package/package.json +8 -8
- package/dist/_virtual/_rolldown/runtime.js +0 -5
- package/dist/node_modules/.pnpm/dereference-json-schema@0.2.1/node_modules/dereference-json-schema/dereference.js +0 -43
- package/dist/node_modules/.pnpm/dereference-json-schema@0.2.1/node_modules/dereference-json-schema/dereference.js.map +0 -1
- package/dist/node_modules/.pnpm/dereference-json-schema@0.2.1/node_modules/dereference-json-schema/index.js +0 -29
- package/dist/node_modules/.pnpm/dereference-json-schema@0.2.1/node_modules/dereference-json-schema/index.js.map +0 -1
- package/dist/node_modules/.pnpm/dereference-json-schema@0.2.1/node_modules/dereference-json-schema/klona.js +0 -42
- package/dist/node_modules/.pnpm/dereference-json-schema@0.2.1/node_modules/dereference-json-schema/klona.js.map +0 -1
- package/dist/node_modules/.pnpm/dereference-json-schema@0.2.1/node_modules/dereference-json-schema/resolveRef.js +0 -46
- package/dist/node_modules/.pnpm/dereference-json-schema@0.2.1/node_modules/dereference-json-schema/resolveRef.js.map +0 -1
- package/dist/node_modules/.pnpm/dereference-json-schema@0.2.1/node_modules/dereference-json-schema/types.js +0 -12
- package/dist/node_modules/.pnpm/dereference-json-schema@0.2.1/node_modules/dereference-json-schema/types.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"merge-schema.js","names":[],"sources":["../../src/utils/merge-schema.ts"],"sourcesContent":["import { type ParsedSchema } from '@/utils/schema';\nimport { deepEqual } from './deep-equal';\n\ninterface Options {\n dereference?: (schema: ParsedSchema) => ParsedSchema | undefined;\n}\n\n/**\n * Merge `allOf` object schema\n */\nexport function mergeAllOf(schema: ParsedSchema, options: Options = {}): ParsedSchema {\n if (typeof schema === 'boolean') return schema;\n\n const { dereference } = options;\n if (dereference && '$ref' in schema && typeof schema.$ref === 'string') {\n schema = dereference(schema) ?? schema;\n }\n\n if (typeof schema === 'boolean' || !schema.allOf) return schema;\n\n const { allOf, ...rest } = schema;\n let result: ParsedSchema = rest;\n for (const item of allOf) {\n result = intersection(result, item, options);\n }\n return result;\n}\n\nfunction intersection(a: ParsedSchema, b: ParsedSchema, options: Options): ParsedSchema {\n a = mergeAllOf(a, options);\n b = mergeAllOf(b, options);\n if (typeof a === 'boolean' && typeof b === 'boolean') return a && b;\n if (typeof a === 'boolean') return a;\n if (typeof b === 'boolean') return b;\n\n for (const unionField of ['anyOf', 'oneOf'] as const) {\n if (a[unionField] === undefined && b[unionField] !== undefined) {\n return {\n ...b,\n [unionField]: b[unionField].map((item) => intersection(item, a, options)),\n };\n }\n if (a[unionField] !== undefined && b[unionField] === undefined) {\n return {\n ...a,\n [unionField]: a[unionField].map((item) => intersection(item, b, options)),\n };\n }\n }\n\n const result: ParsedSchema = { ...a };\n for (const _k in b) {\n const key = _k as keyof typeof b;\n\n switch (key) {\n case '$id':\n case '$comment':\n case 'description':\n case 'examples':\n case 'allOf':\n case 'writeOnly':\n case 'readOnly':\n // ignored\n break;\n case 'title': {\n const value = b[key];\n if (value === undefined) break;\n if (result[key]) {\n result[key] = `${result[key]} & ${value}`;\n } else {\n result[key] = value;\n }\n break;\n }\n case 'minItems':\n case 'minimum':\n case 'exclusiveMinimum':\n case 'minProperties':\n case 'minContains':\n case 'minLength': {\n const value = b[key];\n if (value === undefined) break;\n result[key] = result[key] === undefined ? value : Math.max(result[key], value);\n break;\n }\n case 'maxContains':\n case 'maxItems':\n case 'maxLength':\n case 'maxProperties':\n case 'maximum':\n case 'exclusiveMaximum': {\n const value = b[key];\n if (value === undefined) break;\n result[key] = result[key] === undefined ? value : Math.min(result[key], value);\n break;\n }\n case 'enum': {\n const value = b[key];\n if (value === undefined) break;\n\n result[key] = result[key] === undefined ? value : intersectArray(result[key], value);\n break;\n }\n case 'anyOf':\n case 'oneOf': {\n const value = b[key];\n if (value !== undefined && result[key] !== undefined) {\n result[key] = intersectArray(result[key], value);\n }\n break;\n }\n // require same\n case 'format':\n case 'const':\n case 'type': {\n const value = b[key];\n if (value === undefined) break;\n result[key] ??= value;\n\n if (!deepEqual(result[key], value)) return false;\n break;\n }\n // add\n case 'required': {\n const value = b[key];\n if (value === undefined) break;\n result[key] = [...(result[key] ?? []), ...value];\n break;\n }\n case 'properties':\n case 'patternProperties': {\n const value = b[key];\n if (value === undefined) break;\n\n if (result[key] === undefined) {\n result[key] = value;\n break;\n }\n\n const out: Record<string, ParsedSchema> = {};\n const allProps = new Set<string>();\n for (const k in result[key]) allProps.add(k);\n for (const k in value) allProps.add(k);\n\n for (const prop of allProps) {\n const aProp = result[key][prop];\n const bProp = value[prop];\n if (aProp === undefined) {\n out[prop] = bProp;\n } else if (bProp === undefined) {\n out[prop] = aProp;\n } else {\n out[prop] = intersection(aProp, bProp, options);\n }\n }\n\n result[key] = out;\n break;\n }\n case 'additionalProperties':\n case 'additionalItems':\n case 'contains':\n case 'items': {\n const value = b[key];\n if (value === undefined) break;\n\n result[key] = result[key] === undefined ? value : intersection(result[key], value, options);\n break;\n }\n case 'not': {\n const value = b[key];\n if (value === undefined) break;\n\n if (result[key] && value) {\n result.not = { anyOf: [result[key], value] };\n } else if (value) {\n result.not = value;\n }\n break;\n }\n default:\n result[key] = b[key];\n }\n }\n\n return result;\n}\n\nfunction intersectArray<T>(a: readonly T[], b: readonly T[]): T[] {\n const out = new Set<T>();\n for (const item of a) {\n if (b.includes(item)) out.add(item);\n }\n for (const item of b) {\n if (a.includes(item)) out.add(item);\n }\n return Array.from(out);\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"merge-schema.js","names":[],"sources":["../../src/utils/merge-schema.ts"],"sourcesContent":["import { type ParsedSchema } from '@/utils/schema';\nimport { deepEqual } from './deep-equal';\n\ninterface Options {\n dereference?: (schema: ParsedSchema) => ParsedSchema | undefined;\n}\n\n/**\n * Merge `allOf` object schema\n */\nexport function mergeAllOf(schema: ParsedSchema, options: Options = {}): ParsedSchema {\n if (typeof schema === 'boolean') return schema;\n\n const { dereference } = options;\n if (dereference && '$ref' in schema && typeof schema.$ref === 'string') {\n schema = dereference(schema) ?? schema;\n }\n\n if (typeof schema === 'boolean' || !schema.allOf) return schema;\n\n const { allOf, ...rest } = schema;\n let result: ParsedSchema = rest;\n for (const item of allOf) {\n result = intersection(result, item, options);\n }\n return result;\n}\n\nfunction intersection(a: ParsedSchema, b: ParsedSchema, options: Options): ParsedSchema {\n a = mergeAllOf(a, options);\n b = mergeAllOf(b, options);\n if (typeof a === 'boolean' && typeof b === 'boolean') return a && b;\n if (typeof a === 'boolean') return a;\n if (typeof b === 'boolean') return b;\n\n for (const unionField of ['anyOf', 'oneOf'] as const) {\n if (a[unionField] === undefined && b[unionField] !== undefined) {\n return {\n ...b,\n [unionField]: b[unionField].map((item) => intersection(item, a, options)),\n };\n }\n if (a[unionField] !== undefined && b[unionField] === undefined) {\n return {\n ...a,\n [unionField]: a[unionField].map((item) => intersection(item, b, options)),\n };\n }\n }\n\n const result: ParsedSchema = { ...a };\n for (const _k in b) {\n const key = _k as keyof typeof b;\n\n switch (key) {\n case '$id':\n case '$comment':\n case 'description':\n case 'examples':\n case 'allOf':\n case 'writeOnly':\n case 'readOnly':\n // ignored\n break;\n case 'title': {\n const value = b[key];\n if (value === undefined) break;\n if (result[key]) {\n result[key] = `${result[key]} & ${value}`;\n } else {\n result[key] = value;\n }\n break;\n }\n case 'minItems':\n case 'minimum':\n case 'exclusiveMinimum':\n case 'minProperties':\n case 'minContains':\n case 'minLength': {\n const value = b[key];\n if (value === undefined) break;\n result[key] = result[key] === undefined ? value : Math.max(result[key], value);\n break;\n }\n case 'maxContains':\n case 'maxItems':\n case 'maxLength':\n case 'maxProperties':\n case 'maximum':\n case 'exclusiveMaximum': {\n const value = b[key];\n if (value === undefined) break;\n result[key] = result[key] === undefined ? value : Math.min(result[key], value);\n break;\n }\n case 'enum': {\n const value = b[key];\n if (value === undefined) break;\n\n result[key] = result[key] === undefined ? value : intersectArray(result[key], value);\n break;\n }\n case 'anyOf':\n case 'oneOf': {\n const value = b[key];\n if (value !== undefined && result[key] !== undefined) {\n result[key] = intersectArray(result[key], value);\n }\n break;\n }\n // require same\n case 'format':\n case 'const':\n case 'type': {\n const value = b[key];\n if (value === undefined) break;\n result[key] ??= value;\n\n if (!deepEqual(result[key], value)) return false;\n break;\n }\n // add\n case 'required': {\n const value = b[key];\n if (value === undefined) break;\n result[key] = [...(result[key] ?? []), ...value];\n break;\n }\n case 'properties':\n case 'patternProperties': {\n const value = b[key];\n if (value === undefined) break;\n\n if (result[key] === undefined) {\n result[key] = value;\n break;\n }\n\n const out: Record<string, ParsedSchema> = {};\n const allProps = new Set<string>();\n for (const k in result[key]) allProps.add(k);\n for (const k in value) allProps.add(k);\n\n for (const prop of allProps) {\n const aProp = result[key][prop];\n const bProp = value[prop];\n if (aProp === undefined) {\n out[prop] = bProp;\n } else if (bProp === undefined) {\n out[prop] = aProp;\n } else {\n out[prop] = intersection(aProp, bProp, options);\n }\n }\n\n result[key] = out;\n break;\n }\n case 'additionalProperties':\n case 'additionalItems':\n case 'contains':\n case 'items': {\n const value = b[key];\n if (value === undefined) break;\n\n result[key] = result[key] === undefined ? value : intersection(result[key], value, options);\n break;\n }\n case 'not': {\n const value = b[key];\n if (value === undefined) break;\n\n if (result[key] && value) {\n result.not = { anyOf: [result[key], value] };\n } else if (value) {\n result.not = value;\n }\n break;\n }\n default:\n result[key] = b[key];\n }\n }\n\n return result;\n}\n\nfunction intersectArray<T>(a: readonly T[], b: readonly T[]): T[] {\n const out = new Set<T>();\n for (const item of a) {\n if (b.includes(item)) out.add(item);\n }\n for (const item of b) {\n if (a.includes(item)) out.add(item);\n }\n return Array.from(out);\n}\n"],"mappings":";;;;;AAUA,SAAgB,WAAW,QAAsB,UAAmB,EAAE,EAAgB;AACpF,KAAI,OAAO,WAAW,UAAW,QAAO;CAExC,MAAM,EAAE,gBAAgB;AACxB,KAAI,eAAe,UAAU,UAAU,OAAO,OAAO,SAAS,SAC5D,UAAS,YAAY,OAAO,IAAI;AAGlC,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AK,MAAM,KAAK,MAAO,UAAS,IAAI,EAAE;AAEtC,SAAK,MAAM,QAAQ,UAAU;KAC3B,MAAM,QAAQ,OAAO,KAAK;KAC1B,MAAM,QAAQ,MAAM;AACpB,SAAI,UAAU,KAAA,EACZ,KAAI,QAAQ;cACH,UAAU,KAAA,EACnB,KAAI,QAAQ;SAEZ,KAAI,QAAQ,aAAa,OAAO,OAAO,QAAQ;;AAInD,WAAO,OAAO;AACd;;GAEF,KAAK;GACL,KAAK;GACL,KAAK;GACL,KAAK,SAAS;IACZ,MAAM,QAAQ,EAAE;AAChB,QAAI,UAAU,KAAA,EAAW;AAEzB,WAAO,OAAO,OAAO,SAAS,KAAA,IAAY,QAAQ,aAAa,OAAO,MAAM,OAAO,QAAQ;AAC3F;;GAEF,KAAK,OAAO;IACV,MAAM,QAAQ,EAAE;AAChB,QAAI,UAAU,KAAA,EAAW;AAEzB,QAAI,OAAO,QAAQ,MACjB,QAAO,MAAM,EAAE,OAAO,CAAC,OAAO,MAAM,MAAM,EAAE;aACnC,MACT,QAAO,MAAM;AAEf;;GAEF,QACE,QAAO,OAAO,EAAE;;;AAItB,QAAO;;AAGT,SAAS,eAAkB,GAAiB,GAAsB;CAChE,MAAM,sBAAM,IAAI,KAAQ;AACxB,MAAK,MAAM,QAAQ,EACjB,KAAI,EAAE,SAAS,KAAK,CAAE,KAAI,IAAI,KAAK;AAErC,MAAK,MAAM,QAAQ,EACjB,KAAI,EAAE,SAAS,KAAK,CAAE,KAAI,IAAI,KAAK;AAErC,QAAO,MAAM,KAAK,IAAI"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { idToTitle } from "../id-to-title.js";
|
|
2
2
|
import { getTagDisplayName, methodKeys } from "../schema.js";
|
|
3
|
-
|
|
4
3
|
//#region src/utils/pages/builder.ts
|
|
5
4
|
async function fromServer(server, config) {
|
|
6
5
|
const schemas = await server.getSchemas();
|
|
@@ -99,7 +98,7 @@ function extractInfo(document) {
|
|
|
99
98
|
}
|
|
100
99
|
return result;
|
|
101
100
|
}
|
|
102
|
-
|
|
103
101
|
//#endregion
|
|
104
102
|
export { fromSchema, fromServer };
|
|
103
|
+
|
|
105
104
|
//# sourceMappingURL=builder.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builder.js","names":[],"sources":["../../../src/utils/pages/builder.ts"],"sourcesContent":["import type { ProcessedDocument } from '@/utils/process-document';\nimport type { OpenAPIServer } from '@/server';\nimport type { OperationItem, WebhookItem } from '@/ui/api-page';\nimport type { Document, OperationObject, PathItemObject, TagObject } from '@/types';\nimport { getTagDisplayName, methodKeys, type NoReference } from '@/utils/schema';\nimport { idToTitle } from '@/utils/id-to-title';\n\ninterface BaseEntry {\n path: string;\n schemaId: string;\n info: {\n title: string;\n description?: string;\n };\n}\n\nexport interface OperationOutput extends BaseEntry {\n type: 'operation';\n item: OperationItem;\n}\n\nexport interface WebhookOutput extends BaseEntry {\n type: 'webhook';\n item: WebhookItem;\n}\n\nexport interface TagOutput extends BaseEntry {\n type: 'tag';\n tag: string;\n rawTag: TagObject;\n operations: OperationItem[];\n webhooks: WebhookItem[];\n}\n\nexport interface OutputGroup extends BaseEntry {\n type: 'group';\n operations: OperationItem[];\n webhooks: WebhookItem[];\n}\n\nexport type OutputEntry = TagOutput | OperationOutput | WebhookOutput | OutputGroup;\n\nexport interface PagesBuilderConfig {\n toPages: (builder: PagesBuilder) => void;\n}\n\nexport interface PagesBuilder {\n /**\n * the input ID in OpenAPI server\n */\n id: string;\n document: ProcessedDocument;\n /**\n * add output entry.\n *\n * When the `path` property is unspecified, it will generate one.\n */\n create: (entry: OutputEntry) => void;\n\n /**\n * get file path from operation path, useful for generating output paths.\n */\n routePathToFilePath: (path: string) => string;\n\n /**\n * Extract useful info for rendering\n */\n extract: () => ExtractedInfo;\n fromExtractedWebhook: (item: WebhookItem) =>\n | {\n get displayName(): string;\n pathItem: NoReference<PathItemObject>;\n operation: NoReference<OperationObject>;\n }\n | undefined;\n fromExtractedOperation: (item: OperationItem) =>\n | {\n get displayName(): string;\n pathItem: NoReference<PathItemObject>;\n operation: NoReference<OperationObject>;\n }\n | undefined;\n fromTag: (tag: TagObject) => {\n get displayName(): string;\n };\n fromTagName: (tag: string) =>\n | {\n info: TagObject;\n get displayName(): string;\n }\n | undefined;\n}\n\ninterface ExtractedInfo {\n webhooks: (WebhookItem & { tags?: string[] })[];\n operations: (OperationItem & {\n tags?: string[];\n })[];\n}\n\nexport async function fromServer(\n server: OpenAPIServer,\n config: PagesBuilderConfig,\n): Promise<Record<string, OutputEntry[]>> {\n const schemas = await server.getSchemas();\n const generated: Record<string, OutputEntry[]> = {};\n\n const entries = Object.entries(schemas);\n if (entries.length === 0) {\n throw new Error('No input files found.');\n }\n\n for (const [id, schema] of entries) {\n generated[id] = fromSchema(id, schema, config);\n }\n\n return generated;\n}\n\nexport function fromSchema(\n schemaId: string,\n processed: ProcessedDocument,\n config: PagesBuilderConfig,\n): OutputEntry[] {\n const files: OutputEntry[] = [];\n const { toPages } = config;\n const { dereferenced } = processed;\n\n toPages({\n id: schemaId,\n document: processed,\n create(entry) {\n files.push(entry);\n },\n extract: () => extractInfo(dereferenced),\n routePathToFilePath(path) {\n return path\n .toLowerCase()\n .replaceAll('.', '-')\n .split('/')\n .flatMap((v) => {\n if (v.startsWith('{') && v.endsWith('}')) return v.slice(1, -1);\n if (v.length === 0) return [];\n return v;\n })\n .join('/');\n },\n fromExtractedWebhook(item) {\n const pathItem = dereferenced.webhooks?.[item.name];\n if (!pathItem) return;\n const operation = pathItem?.[item.method];\n if (!operation) return;\n return {\n pathItem,\n operation,\n get displayName() {\n return operation.summary || pathItem.summary || idToTitle(item.name);\n },\n };\n },\n fromExtractedOperation(item) {\n const pathItem = dereferenced.paths?.[item.path];\n if (!pathItem) return;\n const operation = pathItem?.[item.method];\n if (!operation) return;\n return {\n pathItem,\n operation,\n get displayName() {\n return (\n operation.summary ||\n pathItem.summary ||\n (operation.operationId ? idToTitle(operation.operationId) : item.path)\n );\n },\n };\n },\n fromTag(tag) {\n return {\n get displayName() {\n return getTagDisplayName(tag);\n },\n };\n },\n fromTagName(name) {\n const tag = dereferenced.tags?.find((item) => item.name === name);\n if (!tag) return;\n\n return {\n info: tag,\n ...this.fromTag(tag),\n };\n },\n });\n\n return files;\n}\n\nfunction extractInfo(document: NoReference<Document>): ExtractedInfo {\n const result: ExtractedInfo = { webhooks: [], operations: [] };\n\n for (const [path, pathItem] of Object.entries(document.paths ?? {})) {\n if (!pathItem) continue;\n\n for (const methodKey of methodKeys) {\n if (!pathItem[methodKey]) continue;\n\n result.operations.push({\n method: methodKey,\n path,\n tags: pathItem[methodKey]?.tags,\n });\n }\n }\n\n for (const [name, pathItem] of Object.entries(document.webhooks ?? {})) {\n if (!pathItem) continue;\n\n for (const methodKey of methodKeys) {\n if (!pathItem[methodKey]) continue;\n\n result.webhooks.push({\n method: methodKey,\n name,\n tags: pathItem[methodKey]?.tags,\n });\n }\n }\n\n return result;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"builder.js","names":[],"sources":["../../../src/utils/pages/builder.ts"],"sourcesContent":["import type { ProcessedDocument } from '@/utils/process-document';\nimport type { OpenAPIServer } from '@/server';\nimport type { OperationItem, WebhookItem } from '@/ui/api-page';\nimport type { Document, OperationObject, PathItemObject, TagObject } from '@/types';\nimport { getTagDisplayName, methodKeys, type NoReference } from '@/utils/schema';\nimport { idToTitle } from '@/utils/id-to-title';\n\ninterface BaseEntry {\n path: string;\n schemaId: string;\n info: {\n title: string;\n description?: string;\n };\n}\n\nexport interface OperationOutput extends BaseEntry {\n type: 'operation';\n item: OperationItem;\n}\n\nexport interface WebhookOutput extends BaseEntry {\n type: 'webhook';\n item: WebhookItem;\n}\n\nexport interface TagOutput extends BaseEntry {\n type: 'tag';\n tag: string;\n rawTag: TagObject;\n operations: OperationItem[];\n webhooks: WebhookItem[];\n}\n\nexport interface OutputGroup extends BaseEntry {\n type: 'group';\n operations: OperationItem[];\n webhooks: WebhookItem[];\n}\n\nexport type OutputEntry = TagOutput | OperationOutput | WebhookOutput | OutputGroup;\n\nexport interface PagesBuilderConfig {\n toPages: (builder: PagesBuilder) => void;\n}\n\nexport interface PagesBuilder {\n /**\n * the input ID in OpenAPI server\n */\n id: string;\n document: ProcessedDocument;\n /**\n * add output entry.\n *\n * When the `path` property is unspecified, it will generate one.\n */\n create: (entry: OutputEntry) => void;\n\n /**\n * get file path from operation path, useful for generating output paths.\n */\n routePathToFilePath: (path: string) => string;\n\n /**\n * Extract useful info for rendering\n */\n extract: () => ExtractedInfo;\n fromExtractedWebhook: (item: WebhookItem) =>\n | {\n get displayName(): string;\n pathItem: NoReference<PathItemObject>;\n operation: NoReference<OperationObject>;\n }\n | undefined;\n fromExtractedOperation: (item: OperationItem) =>\n | {\n get displayName(): string;\n pathItem: NoReference<PathItemObject>;\n operation: NoReference<OperationObject>;\n }\n | undefined;\n fromTag: (tag: TagObject) => {\n get displayName(): string;\n };\n fromTagName: (tag: string) =>\n | {\n info: TagObject;\n get displayName(): string;\n }\n | undefined;\n}\n\ninterface ExtractedInfo {\n webhooks: (WebhookItem & { tags?: string[] })[];\n operations: (OperationItem & {\n tags?: string[];\n })[];\n}\n\nexport async function fromServer(\n server: OpenAPIServer,\n config: PagesBuilderConfig,\n): Promise<Record<string, OutputEntry[]>> {\n const schemas = await server.getSchemas();\n const generated: Record<string, OutputEntry[]> = {};\n\n const entries = Object.entries(schemas);\n if (entries.length === 0) {\n throw new Error('No input files found.');\n }\n\n for (const [id, schema] of entries) {\n generated[id] = fromSchema(id, schema, config);\n }\n\n return generated;\n}\n\nexport function fromSchema(\n schemaId: string,\n processed: ProcessedDocument,\n config: PagesBuilderConfig,\n): OutputEntry[] {\n const files: OutputEntry[] = [];\n const { toPages } = config;\n const { dereferenced } = processed;\n\n toPages({\n id: schemaId,\n document: processed,\n create(entry) {\n files.push(entry);\n },\n extract: () => extractInfo(dereferenced),\n routePathToFilePath(path) {\n return path\n .toLowerCase()\n .replaceAll('.', '-')\n .split('/')\n .flatMap((v) => {\n if (v.startsWith('{') && v.endsWith('}')) return v.slice(1, -1);\n if (v.length === 0) return [];\n return v;\n })\n .join('/');\n },\n fromExtractedWebhook(item) {\n const pathItem = dereferenced.webhooks?.[item.name];\n if (!pathItem) return;\n const operation = pathItem?.[item.method];\n if (!operation) return;\n return {\n pathItem,\n operation,\n get displayName() {\n return operation.summary || pathItem.summary || idToTitle(item.name);\n },\n };\n },\n fromExtractedOperation(item) {\n const pathItem = dereferenced.paths?.[item.path];\n if (!pathItem) return;\n const operation = pathItem?.[item.method];\n if (!operation) return;\n return {\n pathItem,\n operation,\n get displayName() {\n return (\n operation.summary ||\n pathItem.summary ||\n (operation.operationId ? idToTitle(operation.operationId) : item.path)\n );\n },\n };\n },\n fromTag(tag) {\n return {\n get displayName() {\n return getTagDisplayName(tag);\n },\n };\n },\n fromTagName(name) {\n const tag = dereferenced.tags?.find((item) => item.name === name);\n if (!tag) return;\n\n return {\n info: tag,\n ...this.fromTag(tag),\n };\n },\n });\n\n return files;\n}\n\nfunction extractInfo(document: NoReference<Document>): ExtractedInfo {\n const result: ExtractedInfo = { webhooks: [], operations: [] };\n\n for (const [path, pathItem] of Object.entries(document.paths ?? {})) {\n if (!pathItem) continue;\n\n for (const methodKey of methodKeys) {\n if (!pathItem[methodKey]) continue;\n\n result.operations.push({\n method: methodKey,\n path,\n tags: pathItem[methodKey]?.tags,\n });\n }\n }\n\n for (const [name, pathItem] of Object.entries(document.webhooks ?? {})) {\n if (!pathItem) continue;\n\n for (const methodKey of methodKeys) {\n if (!pathItem[methodKey]) continue;\n\n result.webhooks.push({\n method: methodKey,\n name,\n tags: pathItem[methodKey]?.tags,\n });\n }\n }\n\n return result;\n}\n"],"mappings":";;;AAoGA,eAAsB,WACpB,QACA,QACwC;CACxC,MAAM,UAAU,MAAM,OAAO,YAAY;CACzC,MAAM,YAA2C,EAAE;CAEnD,MAAM,UAAU,OAAO,QAAQ,QAAQ;AACvC,KAAI,QAAQ,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aAAa,MAAM,MAAM,SAAS,KAAK,SAAS,KAAK;AACjE,OAAI,CAAC,IAAK;AAEV,UAAO;IACL,MAAM;IACN,GAAG,KAAK,QAAQ,IAAI;IACrB;;EAEJ,CAAC;AAEF,QAAO;;AAGT,SAAS,YAAY,UAAgD;CACnE,MAAM,SAAwB;EAAE,UAAU,EAAE;EAAE,YAAY,EAAE;EAAE;AAE9D,MAAK,MAAM,CAAC,MAAM,aAAa,OAAO,QAAQ,SAAS,SAAS,EAAE,CAAC,EAAE;AACnE,MAAI,CAAC,SAAU;AAEf,OAAK,MAAM,aAAa,YAAY;AAClC,OAAI,CAAC,SAAS,WAAY;AAE1B,UAAO,WAAW,KAAK;IACrB,QAAQ;IACR;IACA,MAAM,SAAS,YAAY;IAC5B,CAAC;;;AAIN,MAAK,MAAM,CAAC,MAAM,aAAa,OAAO,QAAQ,SAAS,YAAY,EAAE,CAAC,EAAE;AACtE,MAAI,CAAC,SAAU;AAEf,OAAK,MAAM,aAAa,YAAY;AAClC,OAAI,CAAC,SAAS,WAAY;AAE1B,UAAO,SAAS,KAAK;IACnB,QAAQ;IACR;IACA,MAAM,SAAS,YAAY;IAC5B,CAAC;;;AAIN,QAAO"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { isUrl } from "../url.js";
|
|
2
2
|
import * as path from "node:path";
|
|
3
|
-
|
|
4
3
|
//#region src/utils/pages/preset-auto.ts
|
|
5
4
|
function createAutoPreset(options) {
|
|
6
5
|
if (options.per === "custom") return options;
|
|
@@ -119,7 +118,7 @@ function createAutoPreset(options) {
|
|
|
119
118
|
}
|
|
120
119
|
} };
|
|
121
120
|
}
|
|
122
|
-
|
|
123
121
|
//#endregion
|
|
124
122
|
export { createAutoPreset };
|
|
123
|
+
|
|
125
124
|
//# sourceMappingURL=preset-auto.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preset-auto.js","names":[],"sources":["../../../src/utils/pages/preset-auto.ts"],"sourcesContent":["import * as path from 'node:path';\nimport type { ProcessedDocument } from '@/utils/process-document';\nimport type {\n OperationOutput,\n OutputEntry,\n OutputGroup,\n PagesBuilder,\n PagesBuilderConfig,\n TagOutput,\n WebhookOutput,\n} from '@/utils/pages/builder';\nimport { isUrl } from '@/utils/url';\n\ninterface OperationConfig extends BaseConfig {\n /**\n * Generate a page for each API endpoint/operation (default).\n */\n per?: 'operation';\n\n /**\n * Group output using folders (Only works on `operation` mode)\n * - tag: `{tag}/{file}`\n * - route: `{endpoint}/{method}` (it will ignore the `name` option)\n * - none: `{file}` (default)\n * - a function that aligns group name (folder path) to each entry\n *\n * @defaultValue 'none'\n */\n groupBy?: 'tag' | 'route' | 'none' | ((entry: OperationOutput | WebhookOutput) => string);\n\n /**\n * Specify name for output file\n */\n name?: NameFn<OperationOutput | WebhookOutput> | NameFnOptions;\n}\n\ninterface TagConfig extends BaseConfig {\n /**\n * Generate a page for each tag.\n */\n per: 'tag';\n\n /**\n * Specify name for output file\n */\n name?: NameFn<TagOutput> | NameFnOptions;\n}\n\ninterface SchemaConfig extends BaseConfig {\n /**\n * Generate a page for each schema file.\n */\n per: 'file';\n\n /**\n * Specify name for output file\n */\n name?: NameFn<OutputGroup> | NameFnOptions;\n}\n\nexport type SchemaToPagesOptions =\n | SchemaConfig\n | TagConfig\n | OperationConfig\n | ({\n per: 'custom';\n } & PagesBuilderConfig);\n\ntype NameFn<Entry> = (\n this: PagesBuilder,\n output: Entry,\n document: ProcessedDocument['dereferenced'],\n) => string;\n\ninterface NameFnOptions {\n /**\n * The version of algorithm used to generate file paths.\n *\n * v1: Fumadocs OpenAPI v8\n * v2: Fumadocs OpenAPI v9\n *\n * @defaultValue v2\n */\n algorithm?: 'v2' | 'v1';\n}\n\ninterface BaseConfig {\n /**\n * Custom function to convert names into file names.\n *\n * By default, it only escapes whitespaces and upper case (English) characters\n */\n slugify?: (name: string) => string;\n}\n\nexport function createAutoPreset(options: SchemaToPagesOptions): PagesBuilderConfig {\n if (options.per === 'custom') return options;\n const {\n slugify = (s) => {\n return s.replace(/\\s+/g, '-').toLowerCase();\n },\n } = options;\n let nameFn: NameFn<OutputEntry>;\n\n if (typeof options.name === 'function') {\n nameFn = options.name as NameFn<OutputEntry>;\n } else {\n const { algorithm = 'v2' } = options.name ?? {};\n\n nameFn = function (result, document) {\n if (result.type === 'tag') {\n return slugify(result.tag);\n }\n\n if (result.type === 'group') {\n const schemaId = result.schemaId;\n\n return isUrl(schemaId) ? 'index' : path.basename(schemaId, path.extname(schemaId));\n }\n\n if (result.type === 'operation') {\n const operation = document.paths![result.item.path]![result.item.method]!;\n\n if (algorithm === 'v2' && operation.operationId) {\n return operation.operationId;\n }\n\n return path.join(\n this.routePathToFilePath(result.item.path),\n result.item.method.toLowerCase(),\n );\n }\n\n const hook = document.webhooks![result.item.name][result.item.method]!;\n\n if (algorithm === 'v2' && hook.operationId) {\n return hook.operationId;\n }\n\n return slugify(result.item.name);\n };\n }\n\n function groupOutput(builder: PagesBuilder, entry: OperationOutput | WebhookOutput): string[] {\n const { dereferenced } = builder.document;\n const { groupBy = 'none' } = options as OperationConfig;\n\n if (groupBy === 'route') {\n return [\n path.join(\n builder.routePathToFilePath(\n entry.type === 'operation' ? entry.item.path : entry.item.name,\n ),\n `${entry.item.method.toLowerCase()}.mdx`,\n ),\n ];\n }\n\n const file = nameFn.call(builder, entry, dereferenced);\n if (groupBy === 'tag') {\n let tags =\n entry.type === 'operation'\n ? dereferenced.paths![entry.item.path]![entry.item.method]!.tags\n : dereferenced.webhooks![entry.item.name][entry.item.method]!.tags;\n\n if (!tags || tags.length === 0) {\n console.warn(\n 'When `groupBy` is set to `tag`, make sure a `tags` is defined for every operation schema.',\n );\n\n tags = ['unknown'];\n }\n\n return tags.map((tag) => path.join(slugify(tag), `${file}.mdx`));\n }\n\n if (typeof groupBy === 'function') {\n return [path.join(slugify(groupBy(entry)), `${file}.mdx`)];\n }\n\n return [`${file}.mdx`];\n }\n\n return {\n toPages(builder) {\n const { dereferenced } = builder.document;\n const items = builder.extract();\n\n if (options.per === 'file') {\n const entry: OutputGroup = {\n type: 'group',\n schemaId: builder.id,\n path: '',\n info: {\n title: dereferenced.info?.title ?? 'Unknown',\n description: dereferenced.info?.description,\n },\n ...items,\n };\n entry.path = nameFn.call(builder, entry, dereferenced) + '.mdx';\n builder.create(entry);\n return;\n }\n\n if (options.per === 'tag') {\n const tags = dereferenced.tags ?? [];\n for (const tag of tags) {\n const { displayName } = builder.fromTag(tag);\n const entry: TagOutput = {\n type: 'tag',\n path: '',\n schemaId: builder.id,\n info: {\n title: displayName,\n description: tag.description,\n },\n webhooks: items.webhooks.filter((webhook) => webhook.tags?.includes(tag.name!)),\n operations: items.operations.filter((op) => op.tags?.includes(tag.name!)),\n tag: tag.name!,\n rawTag: tag,\n };\n\n entry.path = nameFn.call(builder, entry, dereferenced) + '.mdx';\n builder.create(entry);\n }\n\n return;\n }\n\n for (const op of items.operations) {\n const { pathItem, operation, displayName } = builder.fromExtractedOperation(op)!;\n\n const entry: OperationOutput = {\n type: 'operation',\n schemaId: builder.id,\n item: op,\n path: '',\n info: {\n title: displayName,\n description: operation.description ?? pathItem.description,\n },\n };\n\n for (const outputPath of groupOutput(builder, entry)) {\n builder.create({ ...entry, path: outputPath });\n }\n }\n\n for (const webhook of items.webhooks) {\n const { pathItem, operation, displayName } = builder.fromExtractedWebhook(webhook)!;\n\n const entry: WebhookOutput = {\n type: 'webhook',\n schemaId: builder.id,\n info: {\n title: displayName,\n description: operation.description ?? pathItem.description,\n },\n item: webhook,\n path: '',\n };\n\n for (const outputPath of groupOutput(builder, entry)) {\n builder.create({ ...entry, path: outputPath });\n }\n }\n },\n };\n}\n"],"mappings":";;;;AA+FA,SAAgB,iBAAiB,SAAmD;AAClF,KAAI,QAAQ,QAAQ,SAAU,QAAO;CACrC,MAAM,EACJ,WAAW,MAAM;AACf,SAAO,EAAE,QAAQ,QAAQ,IAAI,CAAC,aAAa;OAE3C;CACJ,IAAI;AAEJ,KAAI,OAAO,QAAQ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BAAgB,QAAQ,uBAAuB,GAAG;GAE/E,MAAM,QAAyB;IAC7B,MAAM;IACN,UAAU,QAAQ;IAClB,MAAM;IACN,MAAM;IACN,MAAM;KACJ,OAAO;KACP,aAAa,UAAU,eAAe,SAAS;KAChD;IACF;AAED,QAAK,MAAM,cAAc,YAAY,SAAS,MAAM,CAClD,SAAQ,OAAO;IAAE,GAAG;IAAO,MAAM;IAAY,CAAC;;AAIlD,OAAK,MAAM,WAAW,MAAM,UAAU;GACpC,MAAM,EAAE,UAAU,WAAW,gBAAgB,QAAQ,qBAAqB,QAAQ;GAElF,MAAM,QAAuB;IAC3B,MAAM;IACN,UAAU,QAAQ;IAClB,MAAM;KACJ,OAAO;KACP,aAAa,UAAU,eAAe,SAAS;KAChD;IACD,MAAM;IACN,MAAM;IACP;AAED,QAAK,MAAM,cAAc,YAAY,SAAS,MAAM,CAClD,SAAQ,OAAO;IAAE,GAAG;IAAO,MAAM;IAAY,CAAC;;IAIrD"}
|
|
1
|
+
{"version":3,"file":"preset-auto.js","names":[],"sources":["../../../src/utils/pages/preset-auto.ts"],"sourcesContent":["import * as path from 'node:path';\nimport type { ProcessedDocument } from '@/utils/process-document';\nimport type {\n OperationOutput,\n OutputEntry,\n OutputGroup,\n PagesBuilder,\n PagesBuilderConfig,\n TagOutput,\n WebhookOutput,\n} from '@/utils/pages/builder';\nimport { isUrl } from '@/utils/url';\n\ninterface OperationConfig extends BaseConfig {\n /**\n * Generate a page for each API endpoint/operation (default).\n */\n per?: 'operation';\n\n /**\n * Group output using folders (Only works on `operation` mode)\n * - tag: `{tag}/{file}`\n * - route: `{endpoint}/{method}` (it will ignore the `name` option)\n * - none: `{file}` (default)\n * - a function that aligns group name (folder path) to each entry\n *\n * @defaultValue 'none'\n */\n groupBy?: 'tag' | 'route' | 'none' | ((entry: OperationOutput | WebhookOutput) => string);\n\n /**\n * Specify name for output file\n */\n name?: NameFn<OperationOutput | WebhookOutput> | NameFnOptions;\n}\n\ninterface TagConfig extends BaseConfig {\n /**\n * Generate a page for each tag.\n */\n per: 'tag';\n\n /**\n * Specify name for output file\n */\n name?: NameFn<TagOutput> | NameFnOptions;\n}\n\ninterface SchemaConfig extends BaseConfig {\n /**\n * Generate a page for each schema file.\n */\n per: 'file';\n\n /**\n * Specify name for output file\n */\n name?: NameFn<OutputGroup> | NameFnOptions;\n}\n\nexport type SchemaToPagesOptions =\n | SchemaConfig\n | TagConfig\n | OperationConfig\n | ({\n per: 'custom';\n } & PagesBuilderConfig);\n\ntype NameFn<Entry> = (\n this: PagesBuilder,\n output: Entry,\n document: ProcessedDocument['dereferenced'],\n) => string;\n\ninterface NameFnOptions {\n /**\n * The version of algorithm used to generate file paths.\n *\n * v1: Fumadocs OpenAPI v8\n * v2: Fumadocs OpenAPI v9\n *\n * @defaultValue v2\n */\n algorithm?: 'v2' | 'v1';\n}\n\ninterface BaseConfig {\n /**\n * Custom function to convert names into file names.\n *\n * By default, it only escapes whitespaces and upper case (English) characters\n */\n slugify?: (name: string) => string;\n}\n\nexport function createAutoPreset(options: SchemaToPagesOptions): PagesBuilderConfig {\n if (options.per === 'custom') return options;\n const {\n slugify = (s) => {\n return s.replace(/\\s+/g, '-').toLowerCase();\n },\n } = options;\n let nameFn: NameFn<OutputEntry>;\n\n if (typeof options.name === 'function') {\n nameFn = options.name as NameFn<OutputEntry>;\n } else {\n const { algorithm = 'v2' } = options.name ?? {};\n\n nameFn = function (result, document) {\n if (result.type === 'tag') {\n return slugify(result.tag);\n }\n\n if (result.type === 'group') {\n const schemaId = result.schemaId;\n\n return isUrl(schemaId) ? 'index' : path.basename(schemaId, path.extname(schemaId));\n }\n\n if (result.type === 'operation') {\n const operation = document.paths![result.item.path]![result.item.method]!;\n\n if (algorithm === 'v2' && operation.operationId) {\n return operation.operationId;\n }\n\n return path.join(\n this.routePathToFilePath(result.item.path),\n result.item.method.toLowerCase(),\n );\n }\n\n const hook = document.webhooks![result.item.name][result.item.method]!;\n\n if (algorithm === 'v2' && hook.operationId) {\n return hook.operationId;\n }\n\n return slugify(result.item.name);\n };\n }\n\n function groupOutput(builder: PagesBuilder, entry: OperationOutput | WebhookOutput): string[] {\n const { dereferenced } = builder.document;\n const { groupBy = 'none' } = options as OperationConfig;\n\n if (groupBy === 'route') {\n return [\n path.join(\n builder.routePathToFilePath(\n entry.type === 'operation' ? entry.item.path : entry.item.name,\n ),\n `${entry.item.method.toLowerCase()}.mdx`,\n ),\n ];\n }\n\n const file = nameFn.call(builder, entry, dereferenced);\n if (groupBy === 'tag') {\n let tags =\n entry.type === 'operation'\n ? dereferenced.paths![entry.item.path]![entry.item.method]!.tags\n : dereferenced.webhooks![entry.item.name][entry.item.method]!.tags;\n\n if (!tags || tags.length === 0) {\n console.warn(\n 'When `groupBy` is set to `tag`, make sure a `tags` is defined for every operation schema.',\n );\n\n tags = ['unknown'];\n }\n\n return tags.map((tag) => path.join(slugify(tag), `${file}.mdx`));\n }\n\n if (typeof groupBy === 'function') {\n return [path.join(slugify(groupBy(entry)), `${file}.mdx`)];\n }\n\n return [`${file}.mdx`];\n }\n\n return {\n toPages(builder) {\n const { dereferenced } = builder.document;\n const items = builder.extract();\n\n if (options.per === 'file') {\n const entry: OutputGroup = {\n type: 'group',\n schemaId: builder.id,\n path: '',\n info: {\n title: dereferenced.info?.title ?? 'Unknown',\n description: dereferenced.info?.description,\n },\n ...items,\n };\n entry.path = nameFn.call(builder, entry, dereferenced) + '.mdx';\n builder.create(entry);\n return;\n }\n\n if (options.per === 'tag') {\n const tags = dereferenced.tags ?? [];\n for (const tag of tags) {\n const { displayName } = builder.fromTag(tag);\n const entry: TagOutput = {\n type: 'tag',\n path: '',\n schemaId: builder.id,\n info: {\n title: displayName,\n description: tag.description,\n },\n webhooks: items.webhooks.filter((webhook) => webhook.tags?.includes(tag.name!)),\n operations: items.operations.filter((op) => op.tags?.includes(tag.name!)),\n tag: tag.name!,\n rawTag: tag,\n };\n\n entry.path = nameFn.call(builder, entry, dereferenced) + '.mdx';\n builder.create(entry);\n }\n\n return;\n }\n\n for (const op of items.operations) {\n const { pathItem, operation, displayName } = builder.fromExtractedOperation(op)!;\n\n const entry: OperationOutput = {\n type: 'operation',\n schemaId: builder.id,\n item: op,\n path: '',\n info: {\n title: displayName,\n description: operation.description ?? pathItem.description,\n },\n };\n\n for (const outputPath of groupOutput(builder, entry)) {\n builder.create({ ...entry, path: outputPath });\n }\n }\n\n for (const webhook of items.webhooks) {\n const { pathItem, operation, displayName } = builder.fromExtractedWebhook(webhook)!;\n\n const entry: WebhookOutput = {\n type: 'webhook',\n schemaId: builder.id,\n info: {\n title: displayName,\n description: operation.description ?? pathItem.description,\n },\n item: webhook,\n path: '',\n };\n\n for (const outputPath of groupOutput(builder, entry)) {\n builder.create({ ...entry, path: outputPath });\n }\n }\n },\n };\n}\n"],"mappings":";;;AA+FA,SAAgB,iBAAiB,SAAmD;AAClF,KAAI,QAAQ,QAAQ,SAAU,QAAO;CACrC,MAAM,EACJ,WAAW,MAAM;AACf,SAAO,EAAE,QAAQ,QAAQ,IAAI,CAAC,aAAa;OAE3C;CACJ,IAAI;AAEJ,KAAI,OAAO,QAAQ,SAAS,WAC1B,UAAS,QAAQ;MACZ;EACL,MAAM,EAAE,YAAY,SAAS,QAAQ,QAAQ,EAAE;AAE/C,WAAS,SAAU,QAAQ,UAAU;AACnC,OAAI,OAAO,SAAS,MAClB,QAAO,QAAQ,OAAO,IAAI;AAG5B,OAAI,OAAO,SAAS,SAAS;IAC3B,MAAM,WAAW,OAAO;AAExB,WAAO,MAAM,SAAS,GAAG,UAAU,KAAK,SAAS,UAAU,KAAK,QAAQ,SAAS,CAAC;;AAGpF,OAAI,OAAO,SAAS,aAAa;IAC/B,MAAM,YAAY,SAAS,MAAO,OAAO,KAAK,MAAO,OAAO,KAAK;AAEjE,QAAI,cAAc,QAAQ,UAAU,YAClC,QAAO,UAAU;AAGnB,WAAO,KAAK,KACV,KAAK,oBAAoB,OAAO,KAAK,KAAK,EAC1C,OAAO,KAAK,OAAO,aAAa,CACj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D,SAAQ,OAAO;IAAE,GAAG;IAAO,MAAM;IAAY,CAAC;;IAIrD"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { idToTitle } from "../id-to-title.js";
|
|
2
2
|
import Slugger from "github-slugger";
|
|
3
|
-
|
|
4
3
|
//#region src/utils/pages/to-static-data.ts
|
|
5
4
|
function toStaticData(page, dereferenced) {
|
|
6
5
|
const slugger = new Slugger();
|
|
@@ -43,7 +42,7 @@ function toStaticData(page, dereferenced) {
|
|
|
43
42
|
structuredData
|
|
44
43
|
};
|
|
45
44
|
}
|
|
46
|
-
|
|
47
45
|
//#endregion
|
|
48
46
|
export { toStaticData };
|
|
47
|
+
|
|
49
48
|
//# sourceMappingURL=to-static-data.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"to-static-data.js","names":[],"sources":["../../../src/utils/pages/to-static-data.ts"],"sourcesContent":["import type { NoReference } from '@/utils/schema';\nimport type { Document, OperationObject } from '@/types';\nimport Slugger from 'github-slugger';\nimport { idToTitle } from '@/utils/id-to-title';\nimport type { TOCItemType } from 'fumadocs-core/toc';\nimport type { StructuredData } from 'fumadocs-core/mdx-plugins';\nimport type { ApiPageProps } from '@/ui';\n\nexport function toStaticData(\n page: ApiPageProps,\n dereferenced: NoReference<Document>,\n): {\n toc: TOCItemType[];\n structuredData: StructuredData;\n} {\n const slugger = new Slugger();\n const toc: TOCItemType[] = [];\n const structuredData: StructuredData = { headings: [], contents: [] };\n\n function pathItem(item: NoReference<OperationObject>, defaultTitle: string) {\n if (page.showTitle && item.operationId) {\n const title = item.summary || (item.operationId ? idToTitle(item.operationId) : defaultTitle);\n const id = slugger.slug(title);\n\n toc.push({\n depth: 2,\n title,\n url: `#${id}`,\n });\n structuredData.headings.push({\n content: title,\n id,\n });\n }\n\n if (item.description)\n structuredData.contents.push({\n content: item.description,\n heading: structuredData.headings.at(-1)?.id,\n });\n }\n\n for (const item of page.operations ?? []) {\n const operation = dereferenced.paths?.[item.path]?.[item.method];\n if (!operation) continue;\n\n pathItem(operation, item.path);\n }\n\n for (const item of page.webhooks ?? []) {\n const webhook = dereferenced.webhooks?.[item.name]?.[item.method];\n if (!webhook) continue;\n\n pathItem(webhook, item.name);\n }\n\n return { toc, structuredData };\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"to-static-data.js","names":[],"sources":["../../../src/utils/pages/to-static-data.ts"],"sourcesContent":["import type { NoReference } from '@/utils/schema';\nimport type { Document, OperationObject } from '@/types';\nimport Slugger from 'github-slugger';\nimport { idToTitle } from '@/utils/id-to-title';\nimport type { TOCItemType } from 'fumadocs-core/toc';\nimport type { StructuredData } from 'fumadocs-core/mdx-plugins';\nimport type { ApiPageProps } from '@/ui';\n\nexport function toStaticData(\n page: ApiPageProps,\n dereferenced: NoReference<Document>,\n): {\n toc: TOCItemType[];\n structuredData: StructuredData;\n} {\n const slugger = new Slugger();\n const toc: TOCItemType[] = [];\n const structuredData: StructuredData = { headings: [], contents: [] };\n\n function pathItem(item: NoReference<OperationObject>, defaultTitle: string) {\n if (page.showTitle && item.operationId) {\n const title = item.summary || (item.operationId ? idToTitle(item.operationId) : defaultTitle);\n const id = slugger.slug(title);\n\n toc.push({\n depth: 2,\n title,\n url: `#${id}`,\n });\n structuredData.headings.push({\n content: title,\n id,\n });\n }\n\n if (item.description)\n structuredData.contents.push({\n content: item.description,\n heading: structuredData.headings.at(-1)?.id,\n });\n }\n\n for (const item of page.operations ?? []) {\n const operation = dereferenced.paths?.[item.path]?.[item.method];\n if (!operation) continue;\n\n pathItem(operation, item.path);\n }\n\n for (const item of page.webhooks ?? []) {\n const webhook = dereferenced.webhooks?.[item.name]?.[item.method];\n if (!webhook) continue;\n\n pathItem(webhook, item.name);\n }\n\n return { toc, structuredData };\n}\n"],"mappings":";;;AAQA,SAAgB,aACd,MACA,cAIA;CACA,MAAM,UAAU,IAAI,SAAS;CAC7B,MAAM,MAAqB,EAAE;CAC7B,MAAM,iBAAiC;EAAE,UAAU,EAAE;EAAE,UAAU,EAAE;EAAE;CAErE,SAAS,SAAS,MAAoC,cAAsB;AAC1E,MAAI,KAAK,aAAa,KAAK,aAAa;GACtC,MAAM,QAAQ,KAAK,YAAY,KAAK,cAAc,UAAU,KAAK,YAAY,GAAG;GAChF,MAAM,KAAK,QAAQ,KAAK,MAAM;AAE9B,OAAI,KAAK;IACP,OAAO;IACP;IACA,KAAK,IAAI;IACV,CAAC;AACF,kBAAe,SAAS,KAAK;IAC3B,SAAS;IACT;IACD,CAAC;;AAGJ,MAAI,KAAK,YACP,gBAAe,SAAS,KAAK;GAC3B,SAAS,KAAK;GACd,SAAS,eAAe,SAAS,GAAG,GAAG,EAAE;GAC1C,CAAC;;AAGN,MAAK,MAAM,QAAQ,KAAK,cAAc,EAAE,EAAE;EACxC,MAAM,YAAY,aAAa,QAAQ,KAAK,QAAQ,KAAK;AACzD,MAAI,CAAC,UAAW;AAEhB,WAAS,WAAW,KAAK,KAAK;;AAGhC,MAAK,MAAM,QAAQ,KAAK,YAAY,EAAE,EAAE;EACtC,MAAM,UAAU,aAAa,WAAW,KAAK,QAAQ,KAAK;AAC1D,MAAI,CAAC,QAAS;AAEd,WAAS,SAAS,KAAK,KAAK;;AAG9B,QAAO;EAAE;EAAK;EAAgB"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { removeUndefined } from "../remove-undefined.js";
|
|
2
2
|
import { toStaticData } from "./to-static-data.js";
|
|
3
3
|
import { dump } from "js-yaml";
|
|
4
|
-
|
|
5
4
|
//#region src/utils/pages/to-text.ts
|
|
6
5
|
function toText(entry, processed, options = {}) {
|
|
7
6
|
switch (entry.type) {
|
|
@@ -92,7 +91,7 @@ function pageContent({ showTitle, showDescription, document, webhooks, operation
|
|
|
92
91
|
if (showDescription) propStrs.push(`showDescription={${JSON.stringify(showDescription)}}`);
|
|
93
92
|
return `<APIPage ${propStrs.join(" ")} />`;
|
|
94
93
|
}
|
|
95
|
-
|
|
96
94
|
//#endregion
|
|
97
95
|
export { generateDocument, toText };
|
|
96
|
+
|
|
98
97
|
//# sourceMappingURL=to-text.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"to-text.js","names":[],"sources":["../../../src/utils/pages/to-text.ts"],"sourcesContent":["import type { ApiPageProps, OperationItem, WebhookItem } from '@/ui/api-page';\nimport type { ProcessedDocument } from '@/utils/process-document';\nimport type { TagObject } from '@/types';\nimport { dump } from 'js-yaml';\nimport { removeUndefined } from '@/utils/remove-undefined';\nimport type { OutputEntry } from '@/utils/pages/builder';\nimport type { InternalOpenAPIMeta } from '@/server/source-api';\nimport { toStaticData } from '@/utils/pages/to-static-data';\n\nexport interface PagesToTextOptions {\n /**\n * Additional imports of your MDX components.\n */\n imports?: {\n names: string[];\n from: string;\n }[];\n\n /**\n * Customise frontmatter.\n *\n * A `full: true` property will be added by default.\n */\n frontmatter?: (\n title: string,\n description: string | undefined,\n context: DocumentContext,\n ) => Record<string, unknown>;\n\n /**\n * Add description to document body.\n *\n * We recommend but don't enable it by default because some OpenAPI schemas have invalid description that breaks MDX syntax.\n *\n * @defaultValue false\n */\n includeDescription?: boolean;\n\n /**\n * Add a comment to the top of generated files indicating they are auto-generated.\n * - `true`: Adds a standardized comment\n * - `false`: No comment is added\n * - `string`: Adds the provided custom comment\n *\n * @defaultValue true\n */\n addGeneratedComment?: boolean | string;\n}\n\nexport function toText(\n entry: OutputEntry,\n processed: ProcessedDocument,\n options: PagesToTextOptions = {},\n) {\n switch (entry.type) {\n case 'operation':\n return generatePage(\n entry.schemaId,\n processed,\n {\n operations: [entry.item],\n },\n {\n ...options,\n ...entry.info,\n },\n {\n type: 'operation',\n },\n );\n case 'group':\n return generatePage(\n entry.schemaId,\n processed,\n {\n operations: entry.operations,\n webhooks: entry.webhooks,\n showTitle: true,\n },\n {\n ...options,\n ...entry.info,\n },\n {\n type: 'file',\n },\n );\n case 'tag':\n return generatePage(\n entry.schemaId,\n processed,\n {\n operations: entry.operations,\n webhooks: entry.webhooks,\n showTitle: true,\n },\n {\n ...options,\n ...entry.info,\n },\n {\n type: 'tag',\n tag: entry.rawTag,\n },\n );\n case 'webhook':\n return generatePage(\n entry.schemaId,\n processed,\n {\n webhooks: [entry.item],\n },\n {\n ...options,\n ...entry.info,\n },\n {\n type: 'operation',\n },\n );\n }\n}\n\nexport function generateDocument(\n frontmatter: unknown,\n content: string,\n options: PagesToTextOptions,\n): string {\n const { addGeneratedComment = true, imports } = options;\n const out: string[] = [];\n const banner = dump(removeUndefined(frontmatter as object)).trimEnd();\n if (banner.length > 0) out.push(`---\\n${banner}\\n---`);\n\n if (addGeneratedComment) {\n let commentContent =\n 'This file was generated by Fumadocs. Do not edit this file directly. Any changes should be made by running the generation command again.';\n\n if (typeof addGeneratedComment === 'string') {\n commentContent = addGeneratedComment;\n }\n\n commentContent = commentContent.replaceAll('/', '\\\\/');\n out.push(`{/* ${commentContent} */}`);\n }\n\n if (imports) {\n out.push(\n ...imports\n .map((item) => `import { ${item.names.join(', ')} } from ${JSON.stringify(item.from)};`)\n .join('\\n'),\n );\n }\n\n out.push(content);\n return out.join('\\n\\n');\n}\n\nexport type DocumentContext =\n | {\n type: 'tag';\n tag: TagObject | undefined;\n }\n | {\n type: 'operation';\n }\n | {\n type: 'file';\n };\n\nfunction generatePage(\n schemaId: string,\n processed: ProcessedDocument,\n pageProps: Omit<ApiPageProps, 'document'>,\n options: PagesToTextOptions & {\n title: string;\n description?: string;\n },\n context: DocumentContext,\n): string {\n const { frontmatter, includeDescription = false } = options;\n const extend = frontmatter?.(options.title, options.description, context);\n const page: ApiPageProps = {\n ...pageProps,\n document: schemaId,\n };\n\n let meta: InternalOpenAPIMeta | undefined;\n if (page.operations?.length === 1) {\n const operation = page.operations[0];\n\n meta = {\n method: operation.method.toUpperCase(),\n };\n } else if (page.webhooks?.length === 1) {\n const webhook = page.webhooks[0];\n\n meta = {\n method: webhook.method.toUpperCase(),\n webhook: true,\n };\n }\n\n const data = toStaticData(page, processed.dereferenced);\n const content: string[] = [];\n\n if (options.description && includeDescription) content.push(options.description);\n content.push(pageContent(page));\n\n return generateDocument(\n {\n title: options.title,\n description: !includeDescription ? options.description : undefined,\n full: true,\n ...extend,\n _openapi: {\n ...meta,\n ...data,\n ...(extend?._openapi as object | undefined),\n },\n },\n content.join('\\n\\n'),\n options,\n );\n}\n\nfunction pageContent({\n showTitle,\n showDescription,\n document,\n webhooks,\n operations,\n}: ApiPageProps): string {\n const propStrs: string[] = [`document={${JSON.stringify(document)}}`];\n\n // filter extra properties in props\n if (webhooks) {\n propStrs.push(\n `webhooks={${JSON.stringify(\n webhooks.map(\n (item) =>\n ({\n name: item.name,\n method: item.method,\n }) satisfies WebhookItem,\n ),\n )}}`,\n );\n }\n if (operations) {\n propStrs.push(\n `operations={${JSON.stringify(\n operations.map(\n (item) =>\n ({\n path: item.path,\n method: item.method,\n }) satisfies OperationItem,\n ),\n )}}`,\n );\n }\n if (showTitle) {\n propStrs.push(`showTitle={${JSON.stringify(showTitle)}}`);\n }\n if (showDescription) {\n propStrs.push(`showDescription={${JSON.stringify(showDescription)}}`);\n }\n\n return `<APIPage ${propStrs.join(' ')} />`;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"to-text.js","names":[],"sources":["../../../src/utils/pages/to-text.ts"],"sourcesContent":["import type { ApiPageProps, OperationItem, WebhookItem } from '@/ui/api-page';\nimport type { ProcessedDocument } from '@/utils/process-document';\nimport type { TagObject } from '@/types';\nimport { dump } from 'js-yaml';\nimport { removeUndefined } from '@/utils/remove-undefined';\nimport type { OutputEntry } from '@/utils/pages/builder';\nimport type { InternalOpenAPIMeta } from '@/server/source-api';\nimport { toStaticData } from '@/utils/pages/to-static-data';\n\nexport interface PagesToTextOptions {\n /**\n * Additional imports of your MDX components.\n */\n imports?: {\n names: string[];\n from: string;\n }[];\n\n /**\n * Customise frontmatter.\n *\n * A `full: true` property will be added by default.\n */\n frontmatter?: (\n title: string,\n description: string | undefined,\n context: DocumentContext,\n ) => Record<string, unknown>;\n\n /**\n * Add description to document body.\n *\n * We recommend but don't enable it by default because some OpenAPI schemas have invalid description that breaks MDX syntax.\n *\n * @defaultValue false\n */\n includeDescription?: boolean;\n\n /**\n * Add a comment to the top of generated files indicating they are auto-generated.\n * - `true`: Adds a standardized comment\n * - `false`: No comment is added\n * - `string`: Adds the provided custom comment\n *\n * @defaultValue true\n */\n addGeneratedComment?: boolean | string;\n}\n\nexport function toText(\n entry: OutputEntry,\n processed: ProcessedDocument,\n options: PagesToTextOptions = {},\n) {\n switch (entry.type) {\n case 'operation':\n return generatePage(\n entry.schemaId,\n processed,\n {\n operations: [entry.item],\n },\n {\n ...options,\n ...entry.info,\n },\n {\n type: 'operation',\n },\n );\n case 'group':\n return generatePage(\n entry.schemaId,\n processed,\n {\n operations: entry.operations,\n webhooks: entry.webhooks,\n showTitle: true,\n },\n {\n ...options,\n ...entry.info,\n },\n {\n type: 'file',\n },\n );\n case 'tag':\n return generatePage(\n entry.schemaId,\n processed,\n {\n operations: entry.operations,\n webhooks: entry.webhooks,\n showTitle: true,\n },\n {\n ...options,\n ...entry.info,\n },\n {\n type: 'tag',\n tag: entry.rawTag,\n },\n );\n case 'webhook':\n return generatePage(\n entry.schemaId,\n processed,\n {\n webhooks: [entry.item],\n },\n {\n ...options,\n ...entry.info,\n },\n {\n type: 'operation',\n },\n );\n }\n}\n\nexport function generateDocument(\n frontmatter: unknown,\n content: string,\n options: PagesToTextOptions,\n): string {\n const { addGeneratedComment = true, imports } = options;\n const out: string[] = [];\n const banner = dump(removeUndefined(frontmatter as object)).trimEnd();\n if (banner.length > 0) out.push(`---\\n${banner}\\n---`);\n\n if (addGeneratedComment) {\n let commentContent =\n 'This file was generated by Fumadocs. Do not edit this file directly. Any changes should be made by running the generation command again.';\n\n if (typeof addGeneratedComment === 'string') {\n commentContent = addGeneratedComment;\n }\n\n commentContent = commentContent.replaceAll('/', '\\\\/');\n out.push(`{/* ${commentContent} */}`);\n }\n\n if (imports) {\n out.push(\n ...imports\n .map((item) => `import { ${item.names.join(', ')} } from ${JSON.stringify(item.from)};`)\n .join('\\n'),\n );\n }\n\n out.push(content);\n return out.join('\\n\\n');\n}\n\nexport type DocumentContext =\n | {\n type: 'tag';\n tag: TagObject | undefined;\n }\n | {\n type: 'operation';\n }\n | {\n type: 'file';\n };\n\nfunction generatePage(\n schemaId: string,\n processed: ProcessedDocument,\n pageProps: Omit<ApiPageProps, 'document'>,\n options: PagesToTextOptions & {\n title: string;\n description?: string;\n },\n context: DocumentContext,\n): string {\n const { frontmatter, includeDescription = false } = options;\n const extend = frontmatter?.(options.title, options.description, context);\n const page: ApiPageProps = {\n ...pageProps,\n document: schemaId,\n };\n\n let meta: InternalOpenAPIMeta | undefined;\n if (page.operations?.length === 1) {\n const operation = page.operations[0];\n\n meta = {\n method: operation.method.toUpperCase(),\n };\n } else if (page.webhooks?.length === 1) {\n const webhook = page.webhooks[0];\n\n meta = {\n method: webhook.method.toUpperCase(),\n webhook: true,\n };\n }\n\n const data = toStaticData(page, processed.dereferenced);\n const content: string[] = [];\n\n if (options.description && includeDescription) content.push(options.description);\n content.push(pageContent(page));\n\n return generateDocument(\n {\n title: options.title,\n description: !includeDescription ? options.description : undefined,\n full: true,\n ...extend,\n _openapi: {\n ...meta,\n ...data,\n ...(extend?._openapi as object | undefined),\n },\n },\n content.join('\\n\\n'),\n options,\n );\n}\n\nfunction pageContent({\n showTitle,\n showDescription,\n document,\n webhooks,\n operations,\n}: ApiPageProps): string {\n const propStrs: string[] = [`document={${JSON.stringify(document)}}`];\n\n // filter extra properties in props\n if (webhooks) {\n propStrs.push(\n `webhooks={${JSON.stringify(\n webhooks.map(\n (item) =>\n ({\n name: item.name,\n method: item.method,\n }) satisfies WebhookItem,\n ),\n )}}`,\n );\n }\n if (operations) {\n propStrs.push(\n `operations={${JSON.stringify(\n operations.map(\n (item) =>\n ({\n path: item.path,\n method: item.method,\n }) satisfies OperationItem,\n ),\n )}}`,\n );\n }\n if (showTitle) {\n propStrs.push(`showTitle={${JSON.stringify(showTitle)}}`);\n }\n if (showDescription) {\n propStrs.push(`showDescription={${JSON.stringify(showDescription)}}`);\n }\n\n return `<APIPage ${propStrs.join(' ')} />`;\n}\n"],"mappings":";;;;AAiDA,SAAgB,OACd,OACA,WACA,UAA8B,EAAE,EAChC;AACA,SAAQ,MAAM,MAAd;EACE,KAAK,YACH,QAAO,aACL,MAAM,UACN,WACA,EACE,YAAY,CAAC,MAAM,KAAK,EACzB,EACD;GACE,GAAG;GACH,GAAG,MAAM;GACV,EACD,EACE,MAAM,aACP,CACF;EACH,KAAK,QACH,QAAO,aACL,MAAM,UACN,WACA;GACE,YAAY,MAAM;GAClB,UAAU,MAAM;GAChB,WAAW;GACZ,EACD;GACE,GAAG;GACH,GAAG,MAAM;GACV,EACD,EACE,MAAM,QACP,CACF;EACH,KAAK,MACH,QAAO,aACL,MAAM,UACN,WACA;GACE,YAAY,MAAM;GAClB,UAAU,MAAM;GAChB,WAAW;GACZ,EACD;GACE,GAAG;GACH,GAAG,MAAM;GACV,EACD;GACE,MAAM;GACN,KAAK,MAAM;GACZ,CACF;EACH,KAAK,UACH,QAAO,aACL,MAAM,UACN,WACA,EACE,UAAU,CAAC,MAAM,KAAK,EACvB,EACD;GACE,GAAG;GACH,GAAG,MAAM;GACV,EACD,EACE,MAAM,aACP,CACF;;;AAIP,SAAgB,iBACd,aACA,SACA,SACQ;CACR,MAAM,EAAE,sBAAsB,MAAM,YAAY;CAChD,MAAM,MAAgB,EAAE;CACxB,MAAM,SAAS,KAAK,gBAAgB,YAAsB,CAAC,CAAC,SAAS;AACrE,KAAI,OAAO,SAAS,EAAG,KAAI,KAAK,QAAQ,OAAO,OAAO;AAEtD,KAAI,qBAAqB;EACvB,IAAI,iBACF;AAEF,MAAI,OAAO,wBAAwB,SACjC,kBAAiB;AAGnB,mBAAiB,eAAe,WAAW,KAAK,MAAM;AACtD,MAAI,KAAK,OAAO,eAAe,MAAM;;AAGvC,KAAI,QACF,KAAI,KACF,GAAG,QACA,KAAK,SA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AAQ,KAAK;EACd,EACJ,CACF,CAAC,GACH;AAEH,KAAI,UACF,UAAS,KAAK,cAAc,KAAK,UAAU,UAAU,CAAC,GAAG;AAE3D,KAAI,gBACF,UAAS,KAAK,oBAAoB,KAAK,UAAU,gBAAgB,CAAC,GAAG;AAGvE,QAAO,YAAY,SAAS,KAAK,IAAI,CAAC"}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { require_dereference_json_schema } from "../node_modules/.pnpm/dereference-json-schema@0.2.1/node_modules/dereference-json-schema/index.js";
|
|
2
1
|
import { bundle } from "@scalar/json-magic/bundle";
|
|
3
2
|
import { upgrade } from "@scalar/openapi-upgrader";
|
|
4
3
|
import { fetchUrls, readFiles } from "@scalar/json-magic/bundle/plugins/node";
|
|
5
|
-
|
|
4
|
+
import dereference from "dereference-json-schema";
|
|
6
5
|
//#region src/utils/process-document.ts
|
|
7
|
-
var import_dereference_json_schema = require_dereference_json_schema();
|
|
8
6
|
/**
|
|
9
7
|
* process & reference input document to a Fumadocs OpenAPI compatible format
|
|
10
8
|
*/
|
|
@@ -47,7 +45,7 @@ function dereferenceSync(schema, onDereference) {
|
|
|
47
45
|
else {
|
|
48
46
|
if ("$ref" in current && typeof current["$ref"] === "string") {
|
|
49
47
|
const ref = current["$ref"];
|
|
50
|
-
const out =
|
|
48
|
+
const out = dereference.resolveRefSync(cloned, ref);
|
|
51
49
|
onDereference(ref, out);
|
|
52
50
|
return out;
|
|
53
51
|
}
|
|
@@ -59,7 +57,7 @@ function dereferenceSync(schema, onDereference) {
|
|
|
59
57
|
}
|
|
60
58
|
return resolve(cloned, "#");
|
|
61
59
|
}
|
|
62
|
-
|
|
63
60
|
//#endregion
|
|
64
61
|
export { processDocument };
|
|
62
|
+
|
|
65
63
|
//# sourceMappingURL=process-document.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"process-document.js","names":[],"sources":["../../src/utils/process-document.ts"],"sourcesContent":["import type { Document } from '@/types';\nimport type { NoReference } from '@/utils/schema';\nimport { bundle } from '@scalar/json-magic/bundle';\nimport { upgrade } from '@scalar/openapi-upgrader';\nimport { fetchUrls, readFiles } from '@scalar/json-magic/bundle/plugins/node';\nimport type { JSONSchema } from 'json-schema-typed/draft-2020-12';\nimport
|
|
1
|
+
{"version":3,"file":"process-document.js","names":[],"sources":["../../src/utils/process-document.ts"],"sourcesContent":["import type { Document } from '@/types';\nimport type { NoReference } from '@/utils/schema';\nimport { bundle } from '@scalar/json-magic/bundle';\nimport { upgrade } from '@scalar/openapi-upgrader';\nimport { fetchUrls, readFiles } from '@scalar/json-magic/bundle/plugins/node';\nimport type { JSONSchema } from 'json-schema-typed/draft-2020-12';\nimport dereference from 'dereference-json-schema';\n\nexport interface ProcessedDocument {\n /**\n * dereferenced document\n */\n dereferenced: NoReference<Document>;\n\n /**\n * Get raw object from dereferenced object\n */\n getRawRef: (obj: object) => string | undefined;\n\n bundled: Document;\n}\n\n/**\n * process & reference input document to a Fumadocs OpenAPI compatible format\n */\nexport async function processDocument(input: string | Document): Promise<ProcessedDocument> {\n const bundled: Document = await bundle(input, {\n plugins: [fetchUrls(), readFiles()],\n treeShake: true,\n hooks: {\n onResolveError(node) {\n throw new Error(`Failed to resolve ${node.$ref}`);\n },\n },\n })\n .then((v) => upgrade(v as never, '3.2') as Document)\n .catch((e) => {\n throw new Error(`[OpenAPI] Failed to resolve input: ${input}`, {\n cause: e,\n });\n });\n\n /**\n * Dereferenced value and its original `$ref` value\n */\n const dereferenceMap = new WeakMap<object, string>();\n\n return {\n dereferenced: dereferenceSync(bundled as JSONSchema, (ref, schema) => {\n dereferenceMap.set(schema as object, ref);\n }) as NoReference<Document>,\n getRawRef(obj) {\n return dereferenceMap.get(obj);\n },\n bundled,\n };\n}\n\n/**\n * Resolves all $ref pointers in a schema and returns a new schema without any $ref pointers.\n */\nfunction dereferenceSync(\n schema: JSONSchema,\n onDereference: (ref: string, schema: JSONSchema) => void,\n): JSONSchema {\n if (typeof schema === 'boolean') return schema;\n const visitedNodes = new Set<unknown>();\n const cloned = structuredClone(schema);\n\n function resolve(current: unknown, path: string): JSONSchema {\n if (typeof current === 'object' && current !== null) {\n // make sure we don't visit the same node twice\n if (visitedNodes.has(current)) {\n return current;\n }\n visitedNodes.add(current);\n\n if (Array.isArray(current)) {\n // array\n for (let index = 0; index < current.length; index++) {\n current[index] = resolve(current[index], `${path}/${index}`);\n }\n } else {\n // object\n if ('$ref' in current && typeof current['$ref'] === 'string') {\n const ref = current['$ref'];\n const out = dereference.resolveRefSync(cloned as never, ref) as JSONSchema;\n onDereference(ref, out);\n return out;\n }\n\n const obj = current as Record<string, unknown>;\n for (const key in current) {\n obj[key] = resolve(obj[key], `${path}/${key}`);\n }\n }\n }\n\n return current as JSONSchema;\n }\n\n return resolve(cloned, '#');\n}\n"],"mappings":";;;;;;;;AAyBA,eAAsB,gBAAgB,OAAsD;CAC1F,MAAM,UAAoB,MAAM,OAAO,OAAO;EAC5C,SAAS,CAAC,WAAW,EAAE,WAAW,CAAC;EACnC,WAAW;EACX,OAAO,EACL,eAAe,MAAM;AACnB,SAAM,IAAI,MAAM,qBAAqB,KAAK,OAAO;KAEpD;EACF,CAAC,CACC,MAAM,MAAM,QAAQ,GAAY,MAAM,CAAa,CACnD,OAAO,MAAM;AACZ,QAAM,IAAI,MAAM,sCAAsC,SAAS,EAC7D,OAAO,GACR,CAAC;GACF;;;;CAKJ,MAAM,iCAAiB,IAAI,SAAyB;AAEpD,QAAO;EACL,cAAc,gBAAgB,UAAwB,KAAK,WAAW;AACpE,kBAAe,IAAI,QAAkB,IAAI;IACzC;EACF,UAAU,KAAK;AACb,UAAO,eAAe,IAAI,IAAI;;EAEhC;EACD;;;;;AAMH,SAAS,gBACP,QACA,eACY;AACZ,KAAI,OAAO,WAAW,UAAW,QAAO;CACxC,MAAM,+BAAe,IAAI,KAAc;CACvC,MAAM,SAAS,gBAAgB,OAAO;CAEtC,SAAS,QAAQ,SAAkB,MAA0B;AAC3D,MAAI,OAAO,YAAY,YAAY,YAAY,MAAM;AAEnD,OAAI,aAAa,IAAI,QAAQ,CAC3B,QAAO;AAET,gBAAa,IAAI,QAAQ;AAEzB,OAAI,MAAM,QAAQ,QAAQ,CAExB,MAAK,IAAI,QAAQ,GAAG,QAAQ,QAAQ,QAAQ,QAC1C,SAAQ,SAAS,QAAQ,QAAQ,QAAQ,GAAG,KAAK,GAAG,QAAQ;QAEzD;AAEL,QAAI,UAAU,WAAW,OAAO,QAAQ,YAAY,UAAU;KAC5D,MAAM,MAAM,QAAQ;KACpB,MAAM,MAAM,YAAY,eAAe,QAAiB,IAAI;AAC5D,mBAAc,KAAK,IAAI;AACvB,YAAO;;IAGT,MAAM,MAAM;AACZ,SAAK,MAAM,OAAO,QAChB,KAAI,OAAO,QAAQ,IAAI,MAAM,GAAG,KAAK,GAAG,MAAM;;;AAKpD,SAAO;;AAGT,QAAO,QAAQ,QAAQ,IAAI"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remove-undefined.js","names":[],"sources":["../../src/utils/remove-undefined.ts"],"sourcesContent":["export function removeUndefined<T extends object>(value: T, deep = false): T {\n const obj = value as Record<string, unknown>;\n\n for (const key in obj) {\n if (obj[key] === undefined) delete obj[key];\n if (!deep) continue;\n\n const entry = obj[key];\n\n if (typeof entry === 'object' && entry !== null) {\n removeUndefined(entry, deep);\n continue;\n }\n\n if (Array.isArray(entry)) {\n for (const item of entry) removeUndefined(item, deep);\n }\n }\n\n return value;\n}\n"],"mappings":";AAAA,SAAgB,gBAAkC,OAAU,OAAO,OAAU;CAC3E,MAAM,MAAM;AAEZ,MAAK,MAAM,OAAO,KAAK;AACrB,MAAI,IAAI,SAAS,
|
|
1
|
+
{"version":3,"file":"remove-undefined.js","names":[],"sources":["../../src/utils/remove-undefined.ts"],"sourcesContent":["export function removeUndefined<T extends object>(value: T, deep = false): T {\n const obj = value as Record<string, unknown>;\n\n for (const key in obj) {\n if (obj[key] === undefined) delete obj[key];\n if (!deep) continue;\n\n const entry = obj[key];\n\n if (typeof entry === 'object' && entry !== null) {\n removeUndefined(entry, deep);\n continue;\n }\n\n if (Array.isArray(entry)) {\n for (const item of entry) removeUndefined(item, deep);\n }\n }\n\n return value;\n}\n"],"mappings":";AAAA,SAAgB,gBAAkC,OAAU,OAAO,OAAU;CAC3E,MAAM,MAAM;AAEZ,MAAK,MAAM,OAAO,KAAK;AACrB,MAAI,IAAI,SAAS,KAAA,EAAW,QAAO,IAAI;AACvC,MAAI,CAAC,KAAM;EAEX,MAAM,QAAQ,IAAI;AAElB,MAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAC/C,mBAAgB,OAAO,KAAK;AAC5B;;AAGF,MAAI,MAAM,QAAQ,MAAM,CACtB,MAAK,MAAM,QAAQ,MAAO,iBAAgB,MAAM,KAAK;;AAIzD,QAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-to-string.js","names":[],"sources":["../../src/utils/schema-to-string.ts"],"sourcesContent":["import type { ParsedSchema, ResolvedSchema } from '@/utils/schema';\nimport type { ProcessedDocument } from '@/utils/process-document';\n\nexport enum FormatFlags {\n None = 0,\n UseAlias = 1 << 0,\n}\n\ntype Resolver = (schema: ResolvedSchema) => {\n dereferenced: ResolvedSchema;\n raw?: ParsedSchema;\n};\n\nexport function schemaToString(\n value: ResolvedSchema,\n _resolver?: ProcessedDocument | Resolver,\n flags: FormatFlags = FormatFlags.None,\n): string {\n const resolver: Resolver =\n typeof _resolver === 'function'\n ? _resolver\n : (schema) => {\n const ref =\n _resolver && typeof schema === 'object' ? _resolver.getRawRef(schema) : undefined;\n\n return {\n dereferenced: schema,\n raw: ref ? { $ref: ref } : undefined,\n };\n };\n function union(union: readonly ResolvedSchema[], sep: string, flags: FormatFlags) {\n const members = new Set();\n let nullable = false;\n\n for (const item of union) {\n const result = run(item, flags | FormatFlags.UseAlias);\n\n if (result === 'null') {\n nullable = true;\n } else if (result !== 'unknown') {\n members.add(result);\n }\n }\n\n const result = Array.from(members).join(sep);\n return nullable ? `${result} | null` : result;\n }\n\n function run(schema: ResolvedSchema, flags: FormatFlags): string {\n const resolved = resolver(schema);\n schema = resolved.dereferenced;\n\n if (schema === true) return 'any';\n else if (schema === false) return 'never';\n\n if ((flags & FormatFlags.UseAlias) === FormatFlags.UseAlias) {\n if (schema.title) return schema.title;\n\n if (typeof resolved.raw === 'object' && resolved.raw.$ref) {\n const ref = resolved.raw.$ref.split('/');\n if (ref.length > 0) return ref[ref.length - 1];\n }\n }\n\n if (Array.isArray(schema.type)) {\n return union(\n schema.type.map((type) => ({\n ...schema,\n type,\n })),\n ' | ',\n flags,\n );\n }\n\n if (schema.type === 'array')\n return `array<${schema.items ? run(schema.items, flags | FormatFlags.UseAlias) : 'unknown'}>`;\n\n const or = schema.oneOf ?? schema.anyOf;\n if (schema.oneOf && schema.anyOf) {\n return `(${union(schema.oneOf, ' | ', flags)}) & (${union(schema.anyOf, ' | ', flags)})`;\n } else if (or) {\n return union(or, ' | ', flags);\n }\n\n if (schema.allOf) {\n return union(schema.allOf, ' & ', flags);\n }\n\n if (schema.not) return `not ${run(schema.not, flags)}`;\n if (schema.type === 'string' && schema.format === 'binary') return 'file';\n\n if (schema.type && Array.isArray(schema.type)) {\n return schema.type.filter((v) => v !== 'null').join(' | ');\n }\n\n if (schema.type) {\n return schema.type as string;\n }\n\n return 'unknown';\n }\n\n return run(value, flags);\n}\n"],"mappings":";AAGA,IAAY,
|
|
1
|
+
{"version":3,"file":"schema-to-string.js","names":[],"sources":["../../src/utils/schema-to-string.ts"],"sourcesContent":["import type { ParsedSchema, ResolvedSchema } from '@/utils/schema';\nimport type { ProcessedDocument } from '@/utils/process-document';\n\nexport enum FormatFlags {\n None = 0,\n UseAlias = 1 << 0,\n}\n\ntype Resolver = (schema: ResolvedSchema) => {\n dereferenced: ResolvedSchema;\n raw?: ParsedSchema;\n};\n\nexport function schemaToString(\n value: ResolvedSchema,\n _resolver?: ProcessedDocument | Resolver,\n flags: FormatFlags = FormatFlags.None,\n): string {\n const resolver: Resolver =\n typeof _resolver === 'function'\n ? _resolver\n : (schema) => {\n const ref =\n _resolver && typeof schema === 'object' ? _resolver.getRawRef(schema) : undefined;\n\n return {\n dereferenced: schema,\n raw: ref ? { $ref: ref } : undefined,\n };\n };\n function union(union: readonly ResolvedSchema[], sep: string, flags: FormatFlags) {\n const members = new Set();\n let nullable = false;\n\n for (const item of union) {\n const result = run(item, flags | FormatFlags.UseAlias);\n\n if (result === 'null') {\n nullable = true;\n } else if (result !== 'unknown') {\n members.add(result);\n }\n }\n\n const result = Array.from(members).join(sep);\n return nullable ? `${result} | null` : result;\n }\n\n function run(schema: ResolvedSchema, flags: FormatFlags): string {\n const resolved = resolver(schema);\n schema = resolved.dereferenced;\n\n if (schema === true) return 'any';\n else if (schema === false) return 'never';\n\n if ((flags & FormatFlags.UseAlias) === FormatFlags.UseAlias) {\n if (schema.title) return schema.title;\n\n if (typeof resolved.raw === 'object' && resolved.raw.$ref) {\n const ref = resolved.raw.$ref.split('/');\n if (ref.length > 0) return ref[ref.length - 1];\n }\n }\n\n if (Array.isArray(schema.type)) {\n return union(\n schema.type.map((type) => ({\n ...schema,\n type,\n })),\n ' | ',\n flags,\n );\n }\n\n if (schema.type === 'array')\n return `array<${schema.items ? run(schema.items, flags | FormatFlags.UseAlias) : 'unknown'}>`;\n\n const or = schema.oneOf ?? schema.anyOf;\n if (schema.oneOf && schema.anyOf) {\n return `(${union(schema.oneOf, ' | ', flags)}) & (${union(schema.anyOf, ' | ', flags)})`;\n } else if (or) {\n return union(or, ' | ', flags);\n }\n\n if (schema.allOf) {\n return union(schema.allOf, ' & ', flags);\n }\n\n if (schema.not) return `not ${run(schema.not, flags)}`;\n if (schema.type === 'string' && schema.format === 'binary') return 'file';\n\n if (schema.type && Array.isArray(schema.type)) {\n return schema.type.filter((v) => v !== 'null').join(' | ');\n }\n\n if (schema.type) {\n return schema.type as string;\n }\n\n return 'unknown';\n }\n\n return run(value, flags);\n}\n"],"mappings":";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AAO,OAAO,QAAQ,YAAY,SAAS,GAAG,UAAU;EAE7F,MAAM,KAAK,OAAO,SAAS,OAAO;AAClC,MAAI,OAAO,SAAS,OAAO,MACzB,QAAO,IAAI,MAAM,OAAO,OAAO,OAAO,MAAM,CAAC,OAAO,MAAM,OAAO,OAAO,OAAO,MAAM,CAAC;WAC7E,GACT,QAAO,MAAM,IAAI,OAAO,MAAM;AAGhC,MAAI,OAAO,MACT,QAAO,MAAM,OAAO,OAAO,OAAO,MAAM;AAG1C,MAAI,OAAO,IAAK,QAAO,OAAO,IAAI,OAAO,KAAK,MAAM;AACpD,MAAI,OAAO,SAAS,YAAY,OAAO,WAAW,SAAU,QAAO;AAEnE,MAAI,OAAO,QAAQ,MAAM,QAAQ,OAAO,KAAK,CAC3C,QAAO,OAAO,KAAK,QAAQ,MAAM,MAAM,OAAO,CAAC,KAAK,MAAM;AAG5D,MAAI,OAAO,KACT,QAAO,OAAO;AAGhB,SAAO;;AAGT,QAAO,IAAI,OAAO,MAAM"}
|
package/dist/utils/schema.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { idToTitle } from "./id-to-title.js";
|
|
2
|
-
|
|
3
2
|
//#region src/utils/schema.ts
|
|
4
3
|
const methodKeys = [
|
|
5
4
|
"get",
|
|
@@ -46,7 +45,7 @@ function pickExample(value) {
|
|
|
46
45
|
if (examples.length > 0) return examples[0].value;
|
|
47
46
|
}
|
|
48
47
|
}
|
|
49
|
-
|
|
50
48
|
//#endregion
|
|
51
49
|
export { createMethod, getPreferredType, getTagDisplayName, methodKeys, pickExample };
|
|
50
|
+
|
|
52
51
|
//# sourceMappingURL=schema.js.map
|
package/dist/utils/schema.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","names":[],"sources":["../../src/utils/schema.ts"],"sourcesContent":["import type { JSONSchema } from 'json-schema-typed/draft-2020-12';\nimport type {\n ExampleObject,\n MediaTypeObject,\n MethodInformation,\n OperationObject,\n PathItemObject,\n ReferenceObject,\n TagObject,\n} from '@/types';\nimport { idToTitle } from '@/utils/id-to-title';\n\nexport const methodKeys = ['get', 'post', 'patch', 'delete', 'head', 'put'] as const;\n\nexport type NoReference<T> = T extends (infer I)[]\n ? NoReference<I>[]\n : T extends ReferenceObject\n ? Exclude<T, ReferenceObject>\n : T extends object\n ? {\n [K in keyof T]: NoReference<T[K]>;\n }\n : T;\n\ntype NoReferenceJSONSchema<T> = T extends (infer I)[]\n ? NoReference<I>[]\n : T extends { $ref?: string }\n ? Omit<T, '$ref'>\n : T;\n\nexport type ParsedSchema =\n | (JSONSchema & {\n 'x-playground-lazy'?: boolean;\n })\n | boolean;\nexport type ResolvedSchema = NoReferenceJSONSchema<ParsedSchema>;\n\nexport function getPreferredType(body: Record<string, unknown>): string | undefined {\n if ('application/json' in body) return 'application/json';\n\n return Object.keys(body)[0];\n}\n\nexport function getTagDisplayName(tag: TagObject): string {\n if ('x-displayName' in tag && typeof tag['x-displayName'] === 'string')\n return tag['x-displayName'];\n\n if (tag.summary) return tag.summary;\n return idToTitle(tag.name!);\n}\n\n/**\n * Summarize method endpoint information\n */\nexport function createMethod(\n method: string,\n path: NoReference<PathItemObject>,\n operation: NoReference<OperationObject>,\n): MethodInformation {\n return {\n description: path.description,\n summary: path.summary,\n ...operation,\n servers: operation.servers ?? path.servers,\n parameters: [...(operation.parameters ?? []), ...(path.parameters ?? [])],\n method: method.toUpperCase(),\n };\n}\n\ninterface ExampleLike {\n example?: unknown;\n examples?: {\n [media: string]: ExampleObject;\n };\n content?: {\n [media: string]: MediaTypeObject;\n };\n}\n\nexport function pickExample(value: ExampleLike): unknown | undefined {\n if (value.example !== undefined) {\n return value.example;\n }\n\n if (value.content) {\n const type = getPreferredType(value.content);\n const content = type ? value.content[type] : undefined;\n\n if (type && content) {\n const out = value.examples?.[type].value ?? pickExample(content);\n if (out !== undefined) return out;\n }\n }\n\n if (value.examples) {\n const examples = Object.values(value.examples);\n if (examples.length > 0) return examples[0].value;\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"schema.js","names":[],"sources":["../../src/utils/schema.ts"],"sourcesContent":["import type { JSONSchema } from 'json-schema-typed/draft-2020-12';\nimport type {\n ExampleObject,\n MediaTypeObject,\n MethodInformation,\n OperationObject,\n PathItemObject,\n ReferenceObject,\n TagObject,\n} from '@/types';\nimport { idToTitle } from '@/utils/id-to-title';\n\nexport const methodKeys = ['get', 'post', 'patch', 'delete', 'head', 'put'] as const;\n\nexport type NoReference<T> = T extends (infer I)[]\n ? NoReference<I>[]\n : T extends ReferenceObject\n ? Exclude<T, ReferenceObject>\n : T extends object\n ? {\n [K in keyof T]: NoReference<T[K]>;\n }\n : T;\n\ntype NoReferenceJSONSchema<T> = T extends (infer I)[]\n ? NoReference<I>[]\n : T extends { $ref?: string }\n ? Omit<T, '$ref'>\n : T;\n\nexport type ParsedSchema =\n | (JSONSchema & {\n 'x-playground-lazy'?: boolean;\n })\n | boolean;\nexport type ResolvedSchema = NoReferenceJSONSchema<ParsedSchema>;\n\nexport function getPreferredType(body: Record<string, unknown>): string | undefined {\n if ('application/json' in body) return 'application/json';\n\n return Object.keys(body)[0];\n}\n\nexport function getTagDisplayName(tag: TagObject): string {\n if ('x-displayName' in tag && typeof tag['x-displayName'] === 'string')\n return tag['x-displayName'];\n\n if (tag.summary) return tag.summary;\n return idToTitle(tag.name!);\n}\n\n/**\n * Summarize method endpoint information\n */\nexport function createMethod(\n method: string,\n path: NoReference<PathItemObject>,\n operation: NoReference<OperationObject>,\n): MethodInformation {\n return {\n description: path.description,\n summary: path.summary,\n ...operation,\n servers: operation.servers ?? path.servers,\n parameters: [...(operation.parameters ?? []), ...(path.parameters ?? [])],\n method: method.toUpperCase(),\n };\n}\n\ninterface ExampleLike {\n example?: unknown;\n examples?: {\n [media: string]: ExampleObject;\n };\n content?: {\n [media: string]: MediaTypeObject;\n };\n}\n\nexport function pickExample(value: ExampleLike): unknown | undefined {\n if (value.example !== undefined) {\n return value.example;\n }\n\n if (value.content) {\n const type = getPreferredType(value.content);\n const content = type ? value.content[type] : undefined;\n\n if (type && content) {\n const out = value.examples?.[type].value ?? pickExample(content);\n if (out !== undefined) return out;\n }\n }\n\n if (value.examples) {\n const examples = Object.values(value.examples);\n if (examples.length > 0) return examples[0].value;\n }\n}\n"],"mappings":";;AAYA,MAAa,aAAa;CAAC;CAAO;CAAQ;CAAS;CAAU;CAAQ;CAAM;AAyB3E,SAAgB,iBAAiB,MAAmD;AAClF,KAAI,sBAAsB,KAAM,QAAO;AAEvC,QAAO,OAAO,KAAK,KAAK,CAAC;;AAG3B,SAAgB,kBAAkB,KAAwB;AACxD,KAAI,mBAAmB,OAAO,OAAO,IAAI,qBAAqB,SAC5D,QAAO,IAAI;AAEb,KAAI,IAAI,QAAS,QAAO,IAAI;AAC5B,QAAO,UAAU,IAAI,KAAM;;;;;AAM7B,SAAgB,aACd,QACA,MACA,WACmB;AACnB,QAAO;EACL,aAAa,KAAK;EAClB,SAAS,KAAK;EACd,GAAG;EACH,SAAS,UAAU,WAAW,KAAK;EACnC,YAAY,CAAC,GAAI,UAAU,cAAc,EAAE,EAAG,GAAI,KAAK,cAAc,EAAE,CAAE;EACzE,QAAQ,OAAO,aAAa;EAC7B;;AAaH,SAAgB,YAAY,OAAyC;AACnE,KAAI,MAAM,YAAY,KAAA,EACpB,QAAO,MAAM;AAGf,KAAI,MAAM,SAAS;EACjB,MAAM,OAAO,iBAAiB,MAAM,QAAQ;EAC5C,MAAM,UAAU,OAAO,MAAM,QAAQ,QAAQ,KAAA;AAE7C,MAAI,QAAQ,SAAS;GACnB,MAAM,MAAM,MAAM,WAAW,MAAM,SAAS,YAAY,QAAQ;AAChE,OAAI,QAAQ,KAAA,EAAW,QAAO;;;AAIlC,KAAI,MAAM,UAAU;EAClB,MAAM,WAAW,OAAO,OAAO,MAAM,SAAS;AAC9C,MAAI,SAAS,SAAS,EAAG,QAAO,SAAS,GAAG"}
|
package/dist/utils/url.js
CHANGED
|
@@ -35,7 +35,7 @@ function resolveRequestData(pathname, { path, query }) {
|
|
|
35
35
|
}
|
|
36
36
|
return searchParams.size > 0 ? `${pathPart}?${searchParams}` : pathPart;
|
|
37
37
|
}
|
|
38
|
-
|
|
39
38
|
//#endregion
|
|
40
39
|
export { isUrl, joinURL, resolveRequestData, resolveServerUrl, withBase };
|
|
40
|
+
|
|
41
41
|
//# sourceMappingURL=url.js.map
|
package/dist/utils/use-query.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { useMemo, useRef, useState } from "react";
|
|
2
|
-
|
|
3
2
|
//#region src/utils/use-query.ts
|
|
4
3
|
function useQuery(fn) {
|
|
5
4
|
const [loading, setLoading] = useState(false);
|
|
@@ -34,7 +33,7 @@ function useQuery(fn) {
|
|
|
34
33
|
loading
|
|
35
34
|
]);
|
|
36
35
|
}
|
|
37
|
-
|
|
38
36
|
//#endregion
|
|
39
37
|
export { useQuery };
|
|
38
|
+
|
|
40
39
|
//# sourceMappingURL=use-query.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-query.js","names":[],"sources":["../../src/utils/use-query.ts"],"sourcesContent":["import { useMemo, useRef, useState } from 'react';\n\nexport function useQuery<I extends unknown[], T>(\n fn: (...input: I) => Promise<T>,\n): {\n start: (...input: I) => void;\n reset: () => void;\n data?: T;\n error?: unknown;\n isLoading: boolean;\n} {\n const [loading, setLoading] = useState(false);\n const [data, setData] = useState<T>();\n const [error, setError] = useState<T>();\n const fnRef = useRef(fn);\n fnRef.current = fn;\n\n return useMemo(\n () => ({\n isLoading: loading,\n data,\n error,\n start(...input) {\n setLoading(true);\n\n void fnRef\n .current(...input)\n .then((res) => {\n setData(res);\n setError(undefined);\n })\n .catch((err) => {\n setData(undefined);\n setError(err);\n })\n .finally(() => {\n setLoading(false);\n });\n },\n reset() {\n setData(undefined);\n setError(undefined);\n setLoading(false);\n },\n }),\n [error, data, loading],\n );\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-query.js","names":[],"sources":["../../src/utils/use-query.ts"],"sourcesContent":["import { useMemo, useRef, useState } from 'react';\n\nexport function useQuery<I extends unknown[], T>(\n fn: (...input: I) => Promise<T>,\n): {\n start: (...input: I) => void;\n reset: () => void;\n data?: T;\n error?: unknown;\n isLoading: boolean;\n} {\n const [loading, setLoading] = useState(false);\n const [data, setData] = useState<T>();\n const [error, setError] = useState<T>();\n const fnRef = useRef(fn);\n fnRef.current = fn;\n\n return useMemo(\n () => ({\n isLoading: loading,\n data,\n error,\n start(...input) {\n setLoading(true);\n\n void fnRef\n .current(...input)\n .then((res) => {\n setData(res);\n setError(undefined);\n })\n .catch((err) => {\n setData(undefined);\n setError(err);\n })\n .finally(() => {\n setLoading(false);\n });\n },\n reset() {\n setData(undefined);\n setError(undefined);\n setLoading(false);\n },\n }),\n [error, data, loading],\n );\n}\n"],"mappings":";;AAEA,SAAgB,SACd,IAOA;CACA,MAAM,CAAC,SAAS,cAAc,SAAS,MAAM;CAC7C,MAAM,CAAC,MAAM,WAAW,UAAa;CACrC,MAAM,CAAC,OAAO,YAAY,UAAa;CACvC,MAAM,QAAQ,OAAO,GAAG;AACxB,OAAM,UAAU;AAEhB,QAAO,eACE;EACL,WAAW;EACX;EACA;EACA,MAAM,GAAG,OAAO;AACd,cAAW,KAAK;AAEX,SACF,QAAQ,GAAG,MAAM,CACjB,MAAM,QAAQ;AACb,YAAQ,IAAI;AACZ,aAAS,KAAA,EAAU;KACnB,CACD,OAAO,QAAQ;AACd,YAAQ,KAAA,EAAU;AAClB,aAAS,IAAI;KACb,CACD,cAAc;AACb,eAAW,MAAM;KACjB;;EAEN,QAAQ;AACN,WAAQ,KAAA,EAAU;AAClB,YAAS,KAAA,EAAU;AACnB,cAAW,MAAM;;EAEpB,GACD;EAAC;EAAO;EAAM;EAAQ,CACvB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fumadocs-openapi",
|
|
3
|
-
"version": "10.3.
|
|
3
|
+
"version": "10.3.17",
|
|
4
4
|
"description": "Generate MDX docs for your OpenAPI spec",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Docs",
|
|
@@ -51,6 +51,7 @@
|
|
|
51
51
|
"@scalar/openapi-upgrader": "^0.2.0",
|
|
52
52
|
"ajv": "^8.18.0",
|
|
53
53
|
"class-variance-authority": "^0.7.1",
|
|
54
|
+
"dereference-json-schema": "^0.2.1",
|
|
54
55
|
"github-slugger": "^2.0.0",
|
|
55
56
|
"hast-util-to-jsx-runtime": "^2.3.6",
|
|
56
57
|
"js-yaml": "^4.1.1",
|
|
@@ -67,18 +68,17 @@
|
|
|
67
68
|
"devDependencies": {
|
|
68
69
|
"@scalar/api-client-react": "^1.4.1",
|
|
69
70
|
"@types/js-yaml": "^4.0.9",
|
|
70
|
-
"@types/node": "25.3.
|
|
71
|
+
"@types/node": "25.3.5",
|
|
71
72
|
"@types/openapi-sampler": "^1.0.3",
|
|
72
73
|
"@types/react": "^19.2.14",
|
|
73
|
-
"dereference-json-schema": "^0.2.1",
|
|
74
74
|
"json-schema-typed": "^8.0.2",
|
|
75
75
|
"tailwindcss": "^4.2.1",
|
|
76
|
-
"tsdown": "0.
|
|
76
|
+
"tsdown": "0.21.0",
|
|
77
77
|
"eslint-config-custom": "0.0.0",
|
|
78
|
-
"fumadocs-core": "16.6.
|
|
79
|
-
"fumadocs-ui": "16.6.
|
|
80
|
-
"
|
|
81
|
-
"
|
|
78
|
+
"fumadocs-core": "16.6.11",
|
|
79
|
+
"fumadocs-ui": "16.6.11",
|
|
80
|
+
"tsconfig": "0.0.0",
|
|
81
|
+
"@fumadocs/tailwind": "0.0.3"
|
|
82
82
|
},
|
|
83
83
|
"peerDependencies": {
|
|
84
84
|
"@scalar/api-client-react": "*",
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { __commonJSMin } from "../../../../../_virtual/_rolldown/runtime.js";
|
|
2
|
-
import { require_klona } from "./klona.js";
|
|
3
|
-
import { require_resolveRef } from "./resolveRef.js";
|
|
4
|
-
|
|
5
|
-
//#region ../../node_modules/.pnpm/dereference-json-schema@0.2.1/node_modules/dereference-json-schema/dereference.js
|
|
6
|
-
var require_dereference = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
7
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
Object.defineProperty(exports, "dereferenceSync", {
|
|
9
|
-
enumerable: true,
|
|
10
|
-
get: function() {
|
|
11
|
-
return dereferenceSync;
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
var _klona = require_klona();
|
|
15
|
-
var _resolveRef = require_resolveRef();
|
|
16
|
-
var cache = /* @__PURE__ */ new Map();
|
|
17
|
-
var dereferenceSync = function(schema) {
|
|
18
|
-
if (cache.has(schema)) return cache.get(schema);
|
|
19
|
-
var visitedNodes = /* @__PURE__ */ new Set();
|
|
20
|
-
var cloned = (0, _klona.klona)(schema);
|
|
21
|
-
var resolve = function(current, path) {
|
|
22
|
-
if (typeof current === "object" && current !== null) {
|
|
23
|
-
if (visitedNodes.has(current)) return current;
|
|
24
|
-
visitedNodes.add(current);
|
|
25
|
-
if (Array.isArray(current)) for (var index = 0; index < current.length; index++) current[index] = resolve(current[index], "".concat(path, "/").concat(index));
|
|
26
|
-
else {
|
|
27
|
-
if ("$ref" in current && typeof current["$ref"] === "string") return (0, _resolveRef.resolveRefSync)(cloned, current["$ref"]);
|
|
28
|
-
for (var key in current) current[key] = resolve(current[key], "".concat(path, "/").concat(key));
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return current;
|
|
32
|
-
};
|
|
33
|
-
var result = resolve(cloned, "#");
|
|
34
|
-
cache.set(schema, result);
|
|
35
|
-
return result;
|
|
36
|
-
};
|
|
37
|
-
}));
|
|
38
|
-
|
|
39
|
-
//#endregion
|
|
40
|
-
export default require_dereference();
|
|
41
|
-
|
|
42
|
-
export { require_dereference };
|
|
43
|
-
//# sourceMappingURL=dereference.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dereference.js","names":[],"sources":["../../../../../../../../node_modules/.pnpm/dereference-json-schema@0.2.1/node_modules/dereference-json-schema/dereference.js"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\nObject.defineProperty(exports, \"dereferenceSync\", {\n enumerable: true,\n get: function() {\n return dereferenceSync;\n }\n});\nvar _klona = require(\"./klona\");\nvar _resolveRef = require(\"./resolveRef\");\nvar cache = new Map();\nvar dereferenceSync = function(schema) {\n if (cache.has(schema)) {\n return cache.get(schema);\n }\n var visitedNodes = new Set();\n var cloned = (0, _klona.klona)(schema);\n var resolve = function(current, path) {\n if (typeof current === \"object\" && current !== null) {\n // make sure we don't visit the same node twice\n if (visitedNodes.has(current)) {\n return current;\n }\n visitedNodes.add(current);\n if (Array.isArray(current)) {\n // array\n for(var index = 0; index < current.length; index++){\n current[index] = resolve(current[index], \"\".concat(path, \"/\").concat(index));\n }\n } else {\n // object\n if (\"$ref\" in current && typeof current[\"$ref\"] === \"string\") {\n return (0, _resolveRef.resolveRefSync)(cloned, current[\"$ref\"]);\n }\n for(var key in current){\n current[key] = resolve(current[key], \"\".concat(path, \"/\").concat(key));\n }\n }\n }\n return current;\n };\n var result = resolve(cloned, \"#\");\n cache.set(schema, result);\n return result;\n};\n"],"x_google_ignoreList":[0],"mappings":";;;;;;AACA,QAAO,eAAe,SAAS,cAAc,EACzC,OAAO,MACV,CAAC;AACF,QAAO,eAAe,SAAS,mBAAmB;EAC9C,YAAY;EACZ,KAAK,WAAW;AACZ,UAAO;;EAEd,CAAC;CACF,IAAI;CACJ,IAAI;CACJ,IAAI,wBAAQ,IAAI,KAAK;CACrB,IAAI,kBAAkB,SAAS,QAAQ;AACnC,MAAI,MAAM,IAAI,OAAO,CACjB,QAAO,MAAM,IAAI,OAAO;EAE5B,IAAI,+BAAe,IAAI,KAAK;EAC5B,IAAI,UAAU,GAAG,OAAO,OAAO,OAAO;EACtC,IAAI,UAAU,SAAS,SAAS,MAAM;AAClC,OAAI,OAAO,YAAY,YAAY,YAAY,MAAM;AAEjD,QAAI,aAAa,IAAI,QAAQ,CACzB,QAAO;AAEX,iBAAa,IAAI,QAAQ;AACzB,QAAI,MAAM,QAAQ,QAAQ,CAEtB,MAAI,IAAI,QAAQ,GAAG,QAAQ,QAAQ,QAAQ,QACvC,SAAQ,SAAS,QAAQ,QAAQ,QAAQ,GAAG,OAAO,MAAM,IAAI,CAAC,OAAO,MAAM,CAAC;SAE7E;AAEH,SAAI,UAAU,WAAW,OAAO,QAAQ,YAAY,SAChD,SAAQ,GAAG,YAAY,gBAAgB,QAAQ,QAAQ,QAAQ;AAEnE,UAAI,IAAI,OAAO,QACX,SAAQ,OAAO,QAAQ,QAAQ,MAAM,GAAG,OAAO,MAAM,IAAI,CAAC,OAAO,IAAI,CAAC;;;AAIlF,UAAO;;EAEX,IAAI,SAAS,QAAQ,QAAQ,IAAI;AACjC,QAAM,IAAI,QAAQ,OAAO;AACzB,SAAO"}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { __commonJSMin } from "../../../../../_virtual/_rolldown/runtime.js";
|
|
2
|
-
import { require_types } from "./types.js";
|
|
3
|
-
import { require_resolveRef } from "./resolveRef.js";
|
|
4
|
-
import { require_dereference } from "./dereference.js";
|
|
5
|
-
|
|
6
|
-
//#region ../../node_modules/.pnpm/dereference-json-schema@0.2.1/node_modules/dereference-json-schema/index.js
|
|
7
|
-
var require_dereference_json_schema = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
_exportStar(require_types(), exports);
|
|
10
|
-
_exportStar(require_dereference(), exports);
|
|
11
|
-
_exportStar(require_resolveRef(), exports);
|
|
12
|
-
function _exportStar(from, to) {
|
|
13
|
-
Object.keys(from).forEach(function(k) {
|
|
14
|
-
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
|
|
15
|
-
enumerable: true,
|
|
16
|
-
get: function() {
|
|
17
|
-
return from[k];
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
return from;
|
|
22
|
-
}
|
|
23
|
-
}));
|
|
24
|
-
|
|
25
|
-
//#endregion
|
|
26
|
-
export default require_dereference_json_schema();
|
|
27
|
-
|
|
28
|
-
export { require_dereference_json_schema };
|
|
29
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../../../../../../node_modules/.pnpm/dereference-json-schema@0.2.1/node_modules/dereference-json-schema/index.js"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n_exportStar(require(\"./types\"), exports);\n_exportStar(require(\"./dereference\"), exports);\n_exportStar(require(\"./resolveRef\"), exports);\nfunction _exportStar(from, to) {\n Object.keys(from).forEach(function(k) {\n if (k !== \"default\" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {\n enumerable: true,\n get: function() {\n return from[k];\n }\n });\n });\n return from;\n}\n"],"x_google_ignoreList":[0],"mappings":";;;;;;;AACA,QAAO,eAAe,SAAS,cAAc,EACzC,OAAO,MACV,CAAC;AACF,8BAAgC,QAAQ;AACxC,oCAAsC,QAAQ;AAC9C,mCAAqC,QAAQ;CAC7C,SAAS,YAAY,MAAM,IAAI;AAC3B,SAAO,KAAK,KAAK,CAAC,QAAQ,SAAS,GAAG;AAClC,OAAI,MAAM,aAAa,CAAC,OAAO,UAAU,eAAe,KAAK,IAAI,EAAE,CAAE,QAAO,eAAe,IAAI,GAAG;IAC9F,YAAY;IACZ,KAAK,WAAW;AACZ,YAAO,KAAK;;IAEnB,CAAC;IACJ;AACF,SAAO"}
|