Skip to content

fix(request-schema): render example/examples tabs for request bodies and callbacks#1370

Merged
sserrata merged 2 commits intomainfrom
fix/request-body-examples-and-callbacks
Mar 31, 2026
Merged

fix(request-schema): render example/examples tabs for request bodies and callbacks#1370
sserrata merged 2 commits intomainfrom
fix/request-body-examples-and-callbacks

Conversation

@sserrata
Copy link
Copy Markdown
Member

Summary

RequestSchema was rendering only the schema tree with no example tabs, unlike ResponseSchema which wraps everything in SchemaTabs and adds ExampleFromSchema, ResponseExample, and ResponseExamples tabs.

This caused two gaps:

  • Callback request bodies: schemas with a top-level example or examples (including via $ref) showed nothing in the Callbacks section
  • Regular request bodies: same issue — schema/MediaTypeObject-level examples had no "Example" tab in the docs view

Fix: mirror ResponseSchema's SchemaTabs + ExampleFromSchema / ResponseExample / ResponseExamples pattern inside RequestSchema for both the single-mime and multi-mime code paths. Since callbacks render via createRequestBodyDetailsRequestSchema, this fixes both surfaces in one change.

Test plan

  • Callback request body whose schema has a top-level example → "Example" tab appears in the Callbacks section
  • Callback request body with a MediaTypeObject-level example → "Example" tab appears
  • Regular request body with a schema-level example → "Example" tab appears (regression guard)
  • Request body with MediaTypeObject-level examples (multiple) → tabbed examples appear
  • Request bodies with no example/examples defined → no extra tab, schema renders as before

Demo specs added under demo/examples/tests/callbackExamples.yaml.

Closes #1251

🤖 Generated with Claude Code

…and callbacks

RequestSchema was rendering only the schema tree via SchemaNode, with no
example tabs — unlike ResponseSchema which wraps everything in SchemaTabs
and adds ExampleFromSchema, ResponseExample, and ResponseExamples tabs.

This meant:
- Callback request bodies whose schemas had top-level `example` or
  `examples` showed no sample values in the Callbacks section
- Regular request bodies with schema/MediaTypeObject-level examples also
  lacked the Example tab in the docs view

Fix: mirror ResponseSchema's SchemaTabs + ExampleFromSchema/ResponseExample/
ResponseExamples pattern inside RequestSchema for both the single-mime and
multi-mime code paths.

Demo specs added under demo/examples/tests/callbackExamples.yaml.

Closes #1251

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 30, 2026

Size Change: +7.73 kB (+0.35%)

Total Size: 2.23 MB

Filename Size Change
demo/.docusaurus/globalData.json 68.6 kB +1.07 kB (+1.59%)
demo/.docusaurus/registry.js 99.3 kB +1.55 kB (+1.58%)
demo/.docusaurus/routes.js 93.8 kB +1.4 kB (+1.52%)
demo/.docusaurus/routesChunkNames.json 39 kB +604 B (+1.58%)
demo/build/assets/js/main.********.js 665 kB +2.86 kB (+0.43%)
demo/build/assets/js/runtime~main.********.js 23.1 kB +246 B (+1.08%)
ℹ️ View Unchanged
Filename Size
demo/.docusaurus/codeTranslations.json 2 B
demo/.docusaurus/docusaurus.config.mjs 14.7 kB
demo/.docusaurus/i18n.json 372 B
demo/.docusaurus/site-metadata.json 1.51 kB
demo/build/assets/css/styles.********.css 164 kB
demo/build/index.html 97.6 kB
demo/build/petstore/add-pet/index.html 29.3 kB
demo/build/petstore/create-user/index.html 24 kB
demo/build/petstore/create-users-with-array-input/index.html 24.1 kB
demo/build/petstore/create-users-with-list-input/index.html 24.1 kB
demo/build/petstore/delete-order/index.html 23.8 kB
demo/build/petstore/delete-pet/index.html 24.1 kB
demo/build/petstore/delete-user/index.html 24.3 kB
demo/build/petstore/find-pets-by-status/index.html 24.8 kB
demo/build/petstore/find-pets-by-tags/index.html 25.4 kB
demo/build/petstore/get-inventory/index.html 23.1 kB
demo/build/petstore/get-order-by-id/index.html 24.1 kB
demo/build/petstore/get-pet-by-id/index.html 24.9 kB
demo/build/petstore/get-user-by-name/index.html 24.4 kB
demo/build/petstore/login-user/index.html 24.9 kB
demo/build/petstore/logout-user/index.html 23.7 kB
demo/build/petstore/new-pet/index.html 24.3 kB
demo/build/petstore/pet/index.html 22.5 kB
demo/build/petstore/place-order/index.html 23.3 kB
demo/build/petstore/schemas/apiresponse/index.html 24.6 kB
demo/build/petstore/schemas/cat/index.html 38.7 kB
demo/build/petstore/schemas/category/index.html 25.7 kB
demo/build/petstore/schemas/dog/index.html 39 kB
demo/build/petstore/schemas/honeybee/index.html 39.1 kB
demo/build/petstore/schemas/id/index.html 22.7 kB
demo/build/petstore/schemas/order/index.html 26.8 kB
demo/build/petstore/schemas/pet/index.html 38.5 kB
demo/build/petstore/schemas/tag/index.html 24.1 kB
demo/build/petstore/schemas/user/index.html 40.6 kB
demo/build/petstore/store/index.html 21.5 kB
demo/build/petstore/subscribe-to-the-store-events/index.html 30.2 kB
demo/build/petstore/swagger-petstore-yaml/index.html 30.2 kB
demo/build/petstore/update-pet-with-form/index.html 24.3 kB
demo/build/petstore/update-pet/index.html 24.7 kB
demo/build/petstore/update-user/index.html 24.3 kB
demo/build/petstore/upload-file/index.html 24.1 kB
demo/build/petstore/user/index.html 22.2 kB

compressed-size-action

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 30, 2026

Visit the preview URL for this PR (updated for commit 25fc6cf):

https://docusaurus-openapi-36b86--pr1370-we7e4nsv.web.app

(expires Thu, 30 Apr 2026 00:01:02 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: bf293780ee827f578864d92193b8c2866acd459f

@sserrata
Copy link
Copy Markdown
Member Author

Code Review

Overall: Solid fix that closes a real gap. The approach — mirroring ResponseSchema's SchemaTabs pattern inside RequestSchema — is the right call. The diff is clean and the demo spec covers the three main cases well. A few items worth considering before merge:


Observations

1. Potential duplicate example tabs

When a schema has a top-level example and the MediaTypeObject also has an example, both ExampleFromSchema ("Example (auto)") and ResponseExample ("Example") will render, potentially showing identical content under two different tab labels. sampleResponseFromSchema picks up the schema's example field, so this isn't hypothetical — it'll happen with the EventPayload schema + any endpoint that also sets a media-level example.

ResponseSchema has the same behavior today, so this isn't a regression, but it's worth calling out since the fix adds this surface to request bodies too. A follow-up could suppress ExampleFromSchema when an explicit example/examples is already provided.

2. Reusing ResponseExample / ResponseExamples for request context

The components work correctly, but their names and the translation key (OPENAPI_RESPONSE_EXAMPLES.EXAMPLE) are semantically tied to responses. This isn't broken, but it'll cause confusion for anyone maintaining this later. Low priority, but worth a refactor or alias.

3. firstBody guard before ExampleFromSchema is redundant

{firstBody &&
  ExampleFromSchema({
    schema: firstBody,
    mimeType: mimeType,
  })}

ExampleFromSchema already guards internally (returns null if sampleResponseFromSchema produces nothing useful). The outer firstBody && check is harmless but unnecessary — the component never reaches this line when firstBody is falsy due to the earlier if (firstBody === undefined || ...) return guard.

4. No automated test coverage

The demo YAML is good for visual/manual verification, but there are no Jest/unit tests for the new rendering paths. If there's a pattern in the repo for component snapshot tests or similar, this would be a good candidate. Not a blocker if the project convention is manual QA only.

5. Single-mime fallback path firstBody assignment

const firstBody = mediaTypeObject?.schema ?? body.content![randomFirstKey];

The fallback ?? body.content![randomFirstKey] assigns the entire MediaTypeObject to firstBody if .schema is absent. Then ExampleFromSchema({ schema: firstBody, ... }) is called with a MediaTypeObject instead of a schema object. This pre-existed the PR, but the new code now routes it through ExampleFromSchema, which may produce unexpected output for schema-less content types. Worth a follow-up.


Summary

Area Status
Fix correctness ✅ Correct — mirrors ResponseSchema pattern exactly
Callbacks surface ✅ Covered via createRequestBodyDetails → RequestSchema
Regression guard (regular request bodies) ✅ Demo spec included
Duplicate tab edge case ⚠️ Inherited from ResponseSchema, not a regression
Naming (ResponseExample for request context) ⚠️ Minor, cosmetic
Automated tests ⚠️ Manual only
Pre-existing fallback path quirk ℹ️ Out of scope but worth tracking

Good fix — the core change is sound and the test plan covers the main cases. The duplicate tab scenario is the only item I'd consider addressing before shipping if UX consistency matters here.

…/examples present

When a MediaTypeObject has an explicit `example` or `examples`, both
ExampleFromSchema and ResponseExample/ResponseExamples would render —
showing duplicate tabs with identical content since sampleResponseFromSchema
picks up schema.example. Suppress ExampleFromSchema when an explicit
media-level example is already provided.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@sserrata sserrata merged commit 2eea7dc into main Mar 31, 2026
11 checks passed
@sserrata sserrata deleted the fix/request-body-examples-and-callbacks branch March 31, 2026 00:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Render callback examples

1 participant