Skip to content

fix(theme): pre-populate parameter defaults in API explorer form#1448

Merged
sserrata merged 1 commit into
mainfrom
fix/param-defaults-1226
May 4, 2026
Merged

fix(theme): pre-populate parameter defaults in API explorer form#1448
sserrata merged 1 commit into
mainfrom
fix/param-defaults-1226

Conversation

@sserrata
Copy link
Copy Markdown
Member

@sserrata sserrata commented May 4, 2026

Summary

  • Read schema.default when initializing the params slice (ApiItem/index.tsx) so each parameter carries its default value into redux for code-snippet generation.
  • Sync that initial value into react-hook-form on mount in ParamTextFormItem, ParamSelectFormItem, and ParamBooleanFormItem so the right-hand request form renders the default instead of an empty input. Select/boolean items also pass the controller's value through to FormSelect for the visible selection.
  • Add a regression OpenAPI spec at demo/examples/tests/paramDefaults.yaml covering header, query, path, and cookie parameters with string, integer, enum, and boolean defaults. Picked up automatically by the existing tests plugin instance.

Fixes #1226 — the report focused on header parameters but the bug affected all four in locations.

Test plan

  • yarn workspace docusaurus-theme-openapi-docs tsc --noEmit (already passing locally)
  • In the demo: yarn docusaurus gen-api-docs tests && yarn start → open the new Parameter Defaults Demo API pages and confirm the right-hand form is pre-populated for each parameter location and type.
  • Confirm the generated cURL/code snippets include the default values without any user interaction.
  • Confirm clearing a default (typing then deleting, or selecting ---) still dispatches undefined correctly so the snippet drops the parameter.

Out of scope (good follow-ups)

  • Array defaults via ParamArrayFormItem — needs a useEffect similar to the existing schema.example seeding (line 101).
  • Multi-select defaults (ParamMultiSelectFormItem).
  • Pre-existing collision: ParamSelectFormItem and ParamBooleanFormItem register under the static names paramSelect / paramBoolean, so multiple instances on one page step on each other. Should eventually be keyed by param.name.

🤖 Generated with Claude Code

Read `schema.default` when initializing the params slice and sync that value
into react-hook-form on mount for text, select, and boolean form items so the
right-hand request form renders defaults instead of empty inputs. Affected all
parameter locations (header, query, path, cookie); headers were the most
visible regression.

Also adds an OpenAPI test schema covering each location and schema type used
by the demo `tests` plugin instance.

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

github-actions Bot commented May 4, 2026

Size Change: +6.29 kB (+0.28%)

Total Size: 2.27 MB

📦 View Changed
Filename Size Change
demo/.docusaurus/globalData.json 70.5 kB +869 B (+1.25%)
demo/.docusaurus/registry.js 102 kB +1.23 kB (+1.22%)
demo/.docusaurus/routes.js 96.4 kB +1.2 kB (+1.26%)
demo/.docusaurus/routesChunkNames.json 40 kB +502 B (+1.27%)
demo/build/assets/js/main.********.js 667 kB +2.24 kB (+0.34%)
demo/build/assets/js/runtime~main.********.js 23.6 kB +242 B (+1.04%)
ℹ️ View Unchanged
Filename Size
demo/.docusaurus/codeTranslations.json 2 B
demo/.docusaurus/docusaurus.config.mjs 16.3 kB
demo/.docusaurus/i18n.json 372 B
demo/.docusaurus/site-metadata.json 1.58 kB
demo/build/assets/css/styles.********.css 171 kB
demo/build/index.html 95.4 kB
demo/build/petstore/add-pet/index.html 30 kB
demo/build/petstore/create-user/index.html 24.7 kB
demo/build/petstore/create-users-with-array-input/index.html 24.8 kB
demo/build/petstore/create-users-with-list-input/index.html 24.8 kB
demo/build/petstore/delete-order/index.html 24.5 kB
demo/build/petstore/delete-pet/index.html 24.8 kB
demo/build/petstore/delete-user/index.html 25 kB
demo/build/petstore/find-pets-by-status/index.html 25.5 kB
demo/build/petstore/find-pets-by-tags/index.html 26.1 kB
demo/build/petstore/get-inventory/index.html 23.8 kB
demo/build/petstore/get-order-by-id/index.html 24.8 kB
demo/build/petstore/get-pet-by-id/index.html 25.6 kB
demo/build/petstore/get-user-by-name/index.html 25.1 kB
demo/build/petstore/login-user/index.html 25.6 kB
demo/build/petstore/logout-user/index.html 24.4 kB
demo/build/petstore/new-pet/index.html 25 kB
demo/build/petstore/pet/index.html 23.2 kB
demo/build/petstore/place-order/index.html 24 kB
demo/build/petstore/schemas/apiresponse/index.html 25.2 kB
demo/build/petstore/schemas/cat/index.html 39 kB
demo/build/petstore/schemas/category/index.html 26.3 kB
demo/build/petstore/schemas/dog/index.html 39.3 kB
demo/build/petstore/schemas/honeybee/index.html 39.3 kB
demo/build/petstore/schemas/id/index.html 23.4 kB
demo/build/petstore/schemas/order/index.html 27.3 kB
demo/build/petstore/schemas/pet/index.html 38.8 kB
demo/build/petstore/schemas/tag/index.html 24.7 kB
demo/build/petstore/schemas/user/index.html 40.7 kB
demo/build/petstore/store/index.html 22.2 kB
demo/build/petstore/subscribe-to-the-store-events/index.html 30.9 kB
demo/build/petstore/swagger-petstore-yaml/index.html 30.9 kB
demo/build/petstore/update-pet-with-form/index.html 25 kB
demo/build/petstore/update-pet/index.html 25.4 kB
demo/build/petstore/update-user/index.html 25 kB
demo/build/petstore/upload-file/index.html 24.8 kB
demo/build/petstore/user/index.html 22.9 kB

compressed-size-action

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 4, 2026

Visit the preview URL for this PR (updated for commit 336f8c2):

https://docusaurus-openapi-36b86--pr1448-s4giwsls.web.app

(expires Mon, 11 May 2026 19:12:07 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: bf293780ee827f578864d92193b8c2866acd459f

@sserrata sserrata merged commit 4a61bae into main May 4, 2026
12 checks passed
@sserrata sserrata deleted the fix/param-defaults-1226 branch May 4, 2026 19:21
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.

The default value of the parameter in the request header is not displayed

1 participant