Repository navigation
Conversation
sserrata
left a comment
There was a problem hiding this comment.
Thanks. This PR now has a merge conflict with main because of #1678 (jest.config.js, Body/index.tsx). Please rebase. The media-type handling is also incomplete. Please add one shared helper (for example, getMediaType(contentType): remove parameters, change to lower case) and use it in Body, buildPostmanRequest and the plugin. #1677 needs the same helper.
Other items (outside the diff):
packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/Body/index.tsx: The form checks (here and in the render branch) still compare the rawcontentTypewith===.multipart/form-data; boundary=xorapplication/x-www-form-urlencoded; charset=utf-8still gets an empty plaintext editor. Use the parsedmediaType.packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/buildPostmanRequest.ts: The form mode is selected by an exact match on the rawcontentType. A urlencoded type that has parameters keeps the old mode.packages/docusaurus-plugin-openapi-docs/src/openapi/openapi.ts: The plugin'sjsonRequestBodyExamplestill uses raw-key checks.application/json;charset=UTF-8andapplication/problem+json; charset=utf-8get no example, so the plugin and theme do not agree.
| contentType?.includes("application/json") || | ||
| contentType?.endsWith("+json") | ||
| ) { | ||
| if (mediaType === "application/json" || mediaType?.endsWith("+json")) { |
There was a problem hiding this comment.
Regression: an exact match drops JSON handling for application/json-seq, application/jsonl and similar types that the old includes("application/json") matched. These now get an empty plaintext editor.
sserrata
left a comment
There was a problem hiding this comment.
Thanks for the update. The shared helper, the form branches and the json-seq fix look good. Some new problems must be fixed before merge:
Other items (outside the diff):
packages/docusaurus-plugin-openapi-docs/src/openapi/utils/utils/openapi.ts:isFormUrlEncodedstill uses an exact match, so the plugin and theme do not agree forapplication/x-www-form-urlencoded; charset=utf-8.
| import SchemaTabs from "@theme/SchemaTabs"; | ||
| import TabItem from "@theme/TabItem"; | ||
| import { sampleFromSchema } from "docusaurus-plugin-openapi-docs/lib/openapi/createSchemaExample"; | ||
| import { getMediaType } from "docusaurus-plugin-openapi-docs/lib/utils/mediaType"; |
There was a problem hiding this comment.
Peer dependency break: the theme imports docusaurus-plugin-openapi-docs/lib/utils/mediaType, which is new in this PR, but the theme peer range is still ^5.0.0. A user who upgrades only the theme gets "Module not found". Move getMediaType into the theme (for example, ApiExplorer/utils). Then the plugin change and the special Jest mappings are also not necessary. #1677 needs the same helper. The plugin version (or the existing code at openapi/utils/utils/openapi.ts:509) can stay separate.
| key.toLowerCase() === "application/json" || | ||
| key.toLowerCase() === "application/json; charset=utf-8" | ||
| ) { | ||
| if (getMediaType(key).startsWith("application/json")) { |
There was a problem hiding this comment.
startsWith("application/json") now selects the first application/json* key. With {application/jsonl, application/json}, the example comes from the jsonl schema. Use an exact application/json match first, then +json. The webhook branch (line 358) has the same problem.
|
|
||
| if (body.type === "form") { | ||
| const mediaType = getMediaType(contentType); | ||
| if (mediaType === "multipart/form-data") { |
There was a problem hiding this comment.
A boundary= from the selected content type goes into the Content-Type header of the snippets, but the client makes its own boundary. The copied curl command then sends a body that the server cannot parse. Remove boundary from the header for formdata.
| return; | ||
| } | ||
|
|
||
| if (body.type === "form") { |
There was a problem hiding this comment.
After a mode change, the old raw, urlencoded or formdata data stays on the cloned body, and toJSON() includes it. Clear the inactive fields.
|
Visit the preview URL for this PR (updated for commit a3a0963): https://docusaurus-openapi-36b86--pr1676-ua544npm.web.app (expires Fri, 06 Nov 2026 15:56:06 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 Sign: bf293780ee827f578864d92193b8c2866acd459f |
📸 Visual Diff ReportSnapshot comparison against https://docusaurus-openapi.tryingpan.dev/
✅ No visual regressions detected. Updated at 2026-10-30T16:01:14.079Z · run 40927256913 |
Refs #603.
Normalize media types with a theme-local helper and keep plugin-side normalization local. Parameterized forms and JSON/XML examples work consistently; API and webhook sampling prefer exact application/json, then +json, before the existing JSON-family fallback. The theme does not require a new plugin-internal export.
Include the main-branch changes through #1677, retaining its body-mode selection and named-file validation. Only final formdata mode omits the multipart boundary. Pre-encoded raw strings and nonform file uploads retain their supplied boundary and bytes. The two old unnamed multipart-file controls now use supported nonform file uploads; the raw-string multipart controls and upstream multipart validation tests remain intact.
Validation on Node 26.5.0/macOS: full
yarn testpasses 372 tests across 20 suites, with 35 snapshots. All three packages build without cache; strict changed-file ESLint, Prettier and diff checks pass. The builder is byte-identical to the #1677 merge, af7bee5.Required full
yarn lintstill exits 2 at the existing Cypresscypress/globalsconfiguration error. No browser or hosted CI matrix result is claimed.