Skip to content

Conversation

sathiyadcavalier
Copy link

🛠️ Fix: Properly Render Multiple Examples in PDF from OpenAPI Spec

Summary

This PR resolves an issue where multiple examples defined in the OpenAPI spec were not being correctly rendered in the generated PDF. Previously, the code was iterating over the keys of the examples object but mistakenly treated the key itself as the example content.

Issue

The original code:

if (contentTypeObj.examples) {
  let iterCount = 0;
  for (const oneExample in contentTypeObj.examples) {
    exampleSectionDef.push([
      { text: `${localizedExampleLabel} ${++iterCount}:`, margin: [20, 10, 0, 0], style: ['small', 'b'] },
      { text: JSON.stringify(oneExample, null, 2), margin: [40, 10, 0, 0], style: 'monoSub' },
    ]);
  }
}

This resulted in the PDF showing only the keys (e.g., "example1", "example2") instead of the actual example content.

#### access both the key and the example object:

if (contentTypeObj.examples) {
  let iterCount = 0;
  for (const [key, exampleObj] of Object.entries(contentTypeObj.examples)) {
    exampleSectionDef.push([
      {
        text: `${localizedExampleLabel} ${++iterCount} (${key}):`,
        margin: [20, 10, 0, 0],
        style: ['small', 'b'],
      },
      {
        text: JSON.stringify(exampleObj, null, 2},
    ]);
  }
}
**Impact**
All examples defined under contentTypeObj.examples are now correctly included in the PDF.
Improves completeness and accuracy of documentation output.

**Testing**

Verified with multiple examples in the OpenAPI spec.
PDF output now includes all example contents with proper formatting and labels.

Let me know if you'd like to add a reference to an issue number or include a changelog entry!

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.

1 participant