Skip to content

Response example generation for XML and CSV - #2347

Closed
rishitank wants to merge 16 commits into
Redocly:mainfrom
Adthena:epic-FBI-287-response-example-generation-for-xml-and-csv
Closed

rishitank wants to merge 16 commits into
Redocly:mainfrom
Adthena:epic-FBI-287-response-example-generation-for-xml-and-csv

Conversation

@rishitank

Copy link
Copy Markdown
Contributor

What/Why/How?

As part of implementing api-docs at Adthena, we had the need to auto-generate response examples for XML and CSV based on the OpenAPI schema provided.

  • This PR implements XML and CSV response example generation for Redoc if a response example is not provided.
  • The code for XML generation was adapted from RapiDoc's implementation and ported over to TypeScript.
  • The feature can be enabled via a redoc option.

Reference

Testing

Screenshots (optional)

Check yourself

  • Code is linted
  • Tested
  • All new/updated code is covered with tests

@lornajane

Copy link
Copy Markdown
Contributor

Thank you! It's quite a big pull request, so we're going to need some time to prioritise and review this, but thank you so much for this :)

(if anyone else tries it from the branch, let us know how you get on?)

@LeWolOnline

Copy link
Copy Markdown

@lornajane
Hello! Could you please provide an update on this PR? I'm experiencing the same issue it solves.
Thank you!

@ndmitrys

ndmitrys commented Jun 7, 2024

Copy link
Copy Markdown

Oh, I'm experiencing the same issue. @lornajane, any updates?

@kamukondiwa

Copy link
Copy Markdown

Hi @lornajane, is there any update on this? I can see that there are conflicts on this PR now, I wonder if you are implementing it yourselves?

Comment thread README.md
* **path-only**: displays a path in the sidebar navigation item.
* **id-only**: displays the operation id with a fallback to the path in the sidebar navigation item.
* `showWebhookVerb` - when set to `true`, shows the HTTP request method for webhooks in operations and in the sidebar.
* `codeSamplesLanguages` - enables code sample generation for the provided list of languages.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why this is needed? Can we not determine this from the content type? (application/json, vs application/xml, vs text/csv)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used to allow the user to control for which media types they want code examples to show up rather than showing all code examples for all media types supported (in case the user doesn't want code examples for certain media types to show up by default).

@AlexVarchuk

Copy link
Copy Markdown
Collaborator

@rishitank Thank you for the contribution! 🙏
We've just shipped Redoc v3.0.0, which reworked a large part of the codebase, so older PRs no longer apply cleanly. We're closing them to keep the queue manageable. If you think this is still relevant for v3, please rebase onto main and reopen, and we'll happily review it.

rishitank added a commit to rishitank/redoc that referenced this pull request Oct 14, 2026
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
@rishitank

Copy link
Copy Markdown
Contributor Author

Thanks @AlexVarchuk! I can't reopen this one, because its branch lived in a fork I no longer have access to. So I've opened a new PR rebased onto v3 main: #2869.

v3 already generates XML examples, so #2869 covers only the CSV half. It works the format out from the content type rather than adding the codeSamplesLanguages option, as @adamaltman suggested. While comparing the XML output, I also found a few bugs in openapi-sampler's XML mode and fixed them in Redocly/openapi-sampler#223.

makare11a pushed a commit that referenced this pull request Oct 15, 2026
* feat: render CSV request and response examples

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 #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

* feat: wire CSV rendering into PayloadDisplay and add tests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01117LuacuBxMJUn1wJkfdyL

* feat: render CSV payloads in PayloadDisplay

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

* fix: show CSV examples untruncated; correct the changeset

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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
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.

8 participants