Repository navigation
feat: render CSV request and response examples - #2869
Merged
Merged
Conversation
For text/csv (and application/csv, +csv, x-csv, comma-separated-values) media types, PayloadDisplay now renders a flat record, or an array of flat records, as CSV: a header row plus RFC 4180-quoted rows. Payloads that are not tabular keep the previous rendering. String CSV examples are shown as plain text instead of C-like highlighting. Re-contributes the CSV half of Redocly#2347 for v3. The format is derived from the media type, so the codeSamplesLanguages option is no longer needed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01117LuacuBxMJUn1wJkfdyL
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01117LuacuBxMJUn1wJkfdyL
Completes the previous commit, which only added the CSV unit tests: PayloadDisplay now uses jsonToCsv for CSV media types, with tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01117LuacuBxMJUn1wJkfdyL
3 tasks done
Generated CSV tables are no longer cut at MAX_DISPLAYED_STRING_LENGTH, matching the XML and form-urlencoded views. The changeset no longer claims string CSV examples changed: clike already rendered as plain text. Documents LF row separators and the absence of formula-injection escaping, and tests an own __proto__ key. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01117LuacuBxMJUn1wJkfdyL
5 tasks done
Contributor
|
Merged! Thank you for your contribution @rishitank. The changes will be available in the next release |
rishitank
added a commit
to rishitank/rishitank
that referenced
this pull request
Oct 15, 2026
Redocly/redoc#2347 (2023) was closed when Redoc v3 shipped. Its CSV half was re-raised against v3 as Redocly/redoc#2869 and merged on 15 Oct 2026; the XML half became fixes to openapi-sampler, Redocly/openapi-sampler#223, still in review. Same wording as the portfolio's open-source card. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01117LuacuBxMJUn1wJkfdyL
rishitank
added a commit
to rishitank/rishitank
that referenced
this pull request
Oct 15, 2026
…es await review (#2) The Redoc line still described the 2023 PR (Redocly/redoc#2347) as open. It now says the examples were first proposed in 2023 and later requested by other developers, CSV is merged into v3 for the next release (Redocly/redoc#2869, merged 15 Oct 2026, after redoc@3.0.1), and the XML fixes to openapi-sampler await review (Redocly/openapi-sampler#223). Reviewed by CodeRabbit (approved 564170d) and an independent Claude fact-check of every claim. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01117LuacuBxMJUn1wJkfdyL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What/Why/How?
This picks up #2347 (Response example generation for XML and CSV), which @AlexVarchuk closed after the v3.0.0 release with a request to rebase onto
main. The original branch lived in my former employer's fork, which I can no longer push to, so this is a new PR. The rewrite meant a straight rebase wasn't possible, so this is a port to v3's code.What's left of #2347 for v3
xml.name,attribute,prefix,namespaceandwrapped. I didn't port the old XML generator: it would duplicate that work and give worse output (no attributes, no escaping). I found a few bugs in the sampler's XML mode while comparing, and proposed fixes upstream in fix: xml root element, root arrays and allOf composition openapi-sampler#223.text/csvresponse shows its generated sample as pretty-printed JSON. This PR adds that.codeSamplesLanguagesoption. @adamaltman asked on Response example generation for XML and CSV #2347 whether the format could be worked out from the content type instead of an option. v3 now does that, and so does this PR.Behaviour
PayloadDisplay, an object payload for a CSV media type is shown as CSV when it is a flat record or an array of flat records. CSV media types aretext/csv,application/csv,*+csv, and the legacyx-csv/comma-separated-values, with any parameters. The CSV has a header row (the union of keys across records, in JavaScript property order: first seen, except that integer-like keys such as10come first), then one row per record, quoted per RFC 4180.oneOfvariants, through the existing variant picker.langFromMimereturnstextfor CSV, so the code block and copy telemetry reporttextrather thanclike(rendering is unchanged).Object.prototypemember (e.g.constructor) stays empty, and an own__proto__key is an ordinary column."", so the row doesn't become a blank line.Example (
text/csv, schemaarrayof{date, keyword, clicks}wherekeywordhas the exampleshoes, red):Before this change, the same response showed
[ { "date": "2019-08-24", "keyword": "shoes, red", "clicks": 0 } ].Reference
Tests
src/utils/__tests__/csv.test.ts(21 tests):null/undefinedvalues__proto__key) and single-column empty cells$reffixtures from Response example generation for XML and CSV #2347, run through openapi-samplermedia-type.test.ts:isCsvMediaType(case, parameters,+csv, legacy aliases, negatives) andlangFromMimefor CSV.PayloadDisplay.test.tsx: CSV fortext/csv(with charset),application/csvand+csv; a long table shown untruncated; the JSON fallback for nested data; string CSV as plain text.npm run lint,npm run ts:checkandnpm run unitpass: 3,286 tests.npm run e2e: 310 passed, 2 failed. The two failures (download.spec.ts › GraphQL: should download schemaandscroll-anchoring.spec.ts › Scroll-spy URL sync) also fail on an unmodifiedmainin my environment, where outbound requests tocdn.redoc.lyare blocked. Neither touches examples.text/csvresponse renders as above.Check yourself
🤖 Generated with Claude Code
https://claude.ai/code/session_01117LuacuBxMJUn1wJkfdyL