#3608·fumadocs

[Bug][OpenAPI] Operation page crashes when a response Example Object has no `value`

Author: mehnoorsiddiquiCreated Sep 29, 2026Updated Sep 29, 2026

To Reproduce

json
{
  "openapi": "3.0.0",
  "info": { "title": "Repro", "version": "1.0.0" },
  "paths": {
    "/items": {
      "get": {
        "operationId": "listItems",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": { "type": "object" },
                "examples": {
                  "Default": {},
                  "Populated": { "value": { "id": "1" } }
                }
              }
            }
          }
        }
      }
    }
  }
}

Open the listItems page.

Current vs. Expected behavior

Current: The page crashes with TypeError: Cannot read properties of undefined (reading 'split'). React reports it from the <Placeholder> component in fumadocs-ui/dist/components/dynamic-codeblock.core.js.

Expected: The page renders. Every field on an Example Object is optional in OpenAPI 3.0 and 3.1, so {} is valid (an example can also use externalValue instead). The example could be skipped or shown as empty.

Framework

Tanstack Start

Provide environment information

bash
Framework: TanStack Start 1.168.50 (@tanstack/react-router 1.170.33), Vite 8.2.2
Operating System:
  Platform: win32
Binaries:
  Node: 24.12.0
Relevant Packages:
  fumadocs-core: 16.15.15
  fumadocs-ui: 16.15.15
  fumadocs-mdx: 15.4.0
  fumadocs-openapi: 11.4.1
  react: 19.2.8
  react-dom: 19.2.8

Which area(s) are affected? (Select all that apply)

Integrations (e.g OpenAPI, Typescript DocsGen), UI

Additional context

Observed on the versions above. The same code is in fumadocs-openapi 12.0.4 and on dev as of 1bc5374; source paths are relative to packages/ on that commit.

  1. useResponseExamples (openapi/src/operation.tsx:451) pushes sample: getRaw(example.value), which is undefined when there's no value.
  2. ResponseTabs (openapi/src/ui/operation/response-tabs.tsx:34) renders <ClientCodeBlock lang="json" code={JSON.stringify(example.sample, null, 2)} />. JSON.stringify(undefined) returns undefined, not a string.
  3. The default CodeBlock (shared-api/src/components/defaults.tsx) is DynamicCodeBlock. While Shiki loads, it renders Placeholder (base-ui/src/components/dynamic-codeblock.core.tsx:81, same in radix-ui), which calls code.split('\n') and throws.

A guard at any of these points fixes it, for example skipping examples whose value is undefined in step 1. DynamicCodeBlock could also tolerate a non-string code. For now we work around it with a custom components.CodeBlock that returns null when code is undefined.