fix(docs): include API key header in generated code samples (#6630)

This commit is contained in:
Theodore Li
2026-08-12 13:58:39 -04:00
committed by GitHub
parent 74212ef333
commit afa02939bb
4 changed files with 166 additions and 1 deletions
+21
View File
@@ -0,0 +1,21 @@
import type { InlineCodeUsageGenerator } from 'fumadocs-openapi/requests/generators'
import { createCodeUsageGeneratorRegistry } from 'fumadocs-openapi/requests/generators'
import { registerDefault } from 'fumadocs-openapi/requests/generators/all'
import { generateWithAuth } from '@/lib/openapi-code-samples-client'
const generators = createCodeUsageGeneratorRegistry()
registerDefault(generators)
/**
* Replace every built-in language sample with one that prepends `headers`,
* preserving the built-in tab order, language, and label.
*/
export function buildAuthCodeSamples(headers: Record<string, string>): InlineCodeUsageGenerator[] {
return Array.from(generators.map().entries()).map(([id, generator]) => ({
id,
lang: generator.lang,
label: generator.label,
source: generateWithAuth,
serverContext: { generatorId: id, headers },
}))
}