Skip to content

Commit 2eea7dc

Browse files
sserrataclaude
andauthored
fix(request-schema): render example/examples tabs for request bodies and callbacks (#1370)
* fix(request-schema): render example/examples tabs for request bodies 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> * fix(request-schema): suppress ExampleFromSchema when explicit example/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> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 5beabbe commit 2eea7dc

2 files changed

Lines changed: 288 additions & 83 deletions

File tree

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
openapi: 3.1.0
2+
info:
3+
title: Callback Examples Demo API
4+
description: |
5+
Demonstrates that `example` and `examples` defined on schemas referenced
6+
by callback request bodies are rendered in the documentation.
7+
8+
**Cases covered:**
9+
- Callback request body whose schema has a top-level `example`
10+
- Callback request body with a MediaTypeObject-level `example`
11+
- Regular request body with `example` on the schema (regression guard)
12+
version: 1.0.0
13+
servers:
14+
- url: https://httpbin.org
15+
description: HTTPBin
16+
tags:
17+
- name: callbackExamples
18+
description: Callback example rendering tests
19+
paths:
20+
/anything/webhook-source:
21+
post:
22+
tags:
23+
- callbackExamples
24+
summary: Register webhook (schema-level example on callback body)
25+
description: |
26+
Creates a resource and fires a callback to the provided URL.
27+
The callback's request body schema has a top-level `example` —
28+
verify it appears as an "Example" tab in the Callbacks section.
29+
requestBody:
30+
required: true
31+
content:
32+
application/json:
33+
schema:
34+
type: object
35+
properties:
36+
callbackUrl:
37+
type: string
38+
format: uri
39+
description: URL to receive the callback POST.
40+
required:
41+
- callbackUrl
42+
callbacks:
43+
onEvent:
44+
"{$request.body#/callbackUrl}":
45+
post:
46+
summary: Event callback
47+
requestBody:
48+
required: true
49+
content:
50+
application/json:
51+
schema:
52+
$ref: "#/components/schemas/EventPayload"
53+
responses:
54+
"200":
55+
description: Callback acknowledged
56+
responses:
57+
"201":
58+
description: Registration created
59+
60+
/anything/webhook-media-example:
61+
post:
62+
tags:
63+
- callbackExamples
64+
summary: Register webhook (MediaTypeObject-level example on callback body)
65+
description: |
66+
Same as above but the `example` is on the MediaTypeObject, not the schema.
67+
Verify the "Example" tab appears in the Callbacks section.
68+
requestBody:
69+
required: true
70+
content:
71+
application/json:
72+
schema:
73+
type: object
74+
properties:
75+
callbackUrl:
76+
type: string
77+
format: uri
78+
required:
79+
- callbackUrl
80+
callbacks:
81+
onEvent:
82+
"{$request.body#/callbackUrl}":
83+
post:
84+
summary: Event callback (media-level example)
85+
requestBody:
86+
required: true
87+
content:
88+
application/json:
89+
schema:
90+
$ref: "#/components/schemas/EventPayload"
91+
example:
92+
id: "evt_media_001"
93+
type: "order.completed"
94+
payload:
95+
orderId: "ORD-999"
96+
total: 49.99
97+
responses:
98+
"200":
99+
description: Callback acknowledged
100+
responses:
101+
"201":
102+
description: Registration created
103+
104+
/anything/request-body-with-example:
105+
post:
106+
tags:
107+
- callbackExamples
108+
summary: Regular endpoint with schema-level example (regression guard)
109+
description: |
110+
Verifies that the schema-level `example` also renders for regular
111+
(non-callback) request bodies — i.e. this fix doesn't regress
112+
the existing request body display.
113+
requestBody:
114+
required: true
115+
content:
116+
application/json:
117+
schema:
118+
$ref: "#/components/schemas/EventPayload"
119+
responses:
120+
"200":
121+
description: OK
122+
123+
components:
124+
schemas:
125+
EventPayload:
126+
type: object
127+
description: Payload delivered to the registered callback URL.
128+
example:
129+
id: "evt_001"
130+
type: "order.created"
131+
payload:
132+
orderId: "ORD-123"
133+
total: 29.99
134+
properties:
135+
id:
136+
type: string
137+
description: Unique event identifier.
138+
type:
139+
type: string
140+
description: Event type slug.
141+
payload:
142+
type: object
143+
description: Event-specific data.
144+
required:
145+
- id
146+
- type
147+
- payload

0 commit comments

Comments
 (0)