Skip to content

Commit 358c91d

Browse files
sserrataclaude
andcommitted
fix(theme): prefill Send API Request from example fields (#544, #1079)
ApiItem previously only prefilled parameter values from `schema.default`. For required parameters, the OpenAPI spec discourages `default` (it is a server-side fallback, not a client-supplied value), so authors typically rely on `example`, `schema.example`, or `examples`. None of these were being consulted, leaving required inputs blank. Extend the prefill order to fall through: schema.default -> example -> schema.example -> first of examples Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 72f1187 commit 358c91d

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

  • packages/docusaurus-theme-openapi-docs/src/theme/ApiItem

packages/docusaurus-theme-openapi-docs/src/theme/ApiItem/index.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,22 @@ export default function ApiItem(props: Props): JSX.Element {
123123
(param: { in: "path" | "query" | "header" | "cookie" }) => {
124124
const paramType = param.in;
125125
const paramsArray: ParameterObject[] = params[paramType];
126-
const defaultValue = (param as any).schema?.default;
126+
const p = param as any;
127+
// Prefill order: schema.default, then example sources. `default` is
128+
// semantically a server-side fallback, so for required params authors
129+
// typically rely on `example` / `examples`. See #544 and #1079.
130+
const firstNamedExample =
131+
p.examples && typeof p.examples === "object"
132+
? (Object.values(p.examples)[0] as any)?.value
133+
: undefined;
134+
const prefill =
135+
p.schema?.default ??
136+
p.example ??
137+
p.schema?.example ??
138+
firstNamedExample;
127139
const initialized =
128-
defaultValue !== undefined
129-
? ({ ...param, value: defaultValue } as unknown as ParameterObject)
140+
prefill !== undefined
141+
? ({ ...param, value: prefill } as unknown as ParameterObject)
130142
: (param as ParameterObject);
131143
paramsArray?.push(initialized);
132144
}

0 commit comments

Comments
 (0)