[PR #5831] [MERGED] fix(common): correctly populate OpenAPI response examples #5374

Closed
opened 2026-03-17 02:49:36 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/hoppscotch/hoppscotch/pull/5831
Author: @nivedin
Created: 2/4/2026
Status: Merged
Merged: 2/4/2026
Merged by: @jamesgeorge007

Base: patchHead: fix/open-api-example-schema


📝 Commits (6)

  • 0cf165e fix: import examples instead of openapi schema
  • 0e554bc chore: accept null as example
  • 1d6455d chore: use generateRequestBodyExampleFromOpenAPIV2BodySchema
  • 9e5330f chore: fix type issues
  • bcd42a5 chore: handle unresolved refs
  • 5ecae06 chore: improve doc allow empty examples

📊 Changes

2 files changed (+149 additions, -36 deletions)

View changed files

📝 packages/hoppscotch-common/src/helpers/import-export/import/openapi/example-generators/v2.ts (+4 -2)
📝 packages/hoppscotch-common/src/helpers/import-export/import/openapi/index.ts (+145 -34)

📄 Description

Closes FE-765 #4554

This PR fixes the issue where importing OpenAPI collections used to import the schema as the body for examples rather than the actual examples.

Before

image

After

image

What's changed

Notes to reviewers


Summary by cubic

Fixes OpenAPI import to use response examples instead of schemas. Imported collections now show real example payloads. Resolves FE-765 and #4554.

  • Bug Fixes
    • OpenAPI 3.0/3.1: prefer media.example, then media.examples; respect empty and null examples; skip unresolved $refs; otherwise generate from schema.
    • OpenAPI 2.0: use response.examples by content type; fallback to schema-based generation.
    • Safer JSON handling to avoid errors and keep bodies readable.

Written for commit 5ecae06a1b. Summary will update on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/hoppscotch/hoppscotch/pull/5831 **Author:** [@nivedin](https://github.com/nivedin) **Created:** 2/4/2026 **Status:** ✅ Merged **Merged:** 2/4/2026 **Merged by:** [@jamesgeorge007](https://github.com/jamesgeorge007) **Base:** `patch` ← **Head:** `fix/open-api-example-schema` --- ### 📝 Commits (6) - [`0cf165e`](https://github.com/hoppscotch/hoppscotch/commit/0cf165e98b4d865a1771c5882b45ce45469bb2fe) fix: import examples instead of openapi schema - [`0e554bc`](https://github.com/hoppscotch/hoppscotch/commit/0e554bcfd2487f8e2830620e6432740b3391a969) chore: accept null as example - [`1d6455d`](https://github.com/hoppscotch/hoppscotch/commit/1d6455d534bda6434f879924e007ca0b27cea47f) chore: use generateRequestBodyExampleFromOpenAPIV2BodySchema - [`9e5330f`](https://github.com/hoppscotch/hoppscotch/commit/9e5330f0977d966cadbe61718fce35293eb2befb) chore: fix type issues - [`bcd42a5`](https://github.com/hoppscotch/hoppscotch/commit/bcd42a584789a8c9bfc3d455a45003929e957bfd) chore: handle unresolved refs - [`5ecae06`](https://github.com/hoppscotch/hoppscotch/commit/5ecae06a1b2a970f5a5964969b348c34be364463) chore: improve doc allow empty examples ### 📊 Changes **2 files changed** (+149 additions, -36 deletions) <details> <summary>View changed files</summary> 📝 `packages/hoppscotch-common/src/helpers/import-export/import/openapi/example-generators/v2.ts` (+4 -2) 📝 `packages/hoppscotch-common/src/helpers/import-export/import/openapi/index.ts` (+145 -34) </details> ### 📄 Description <!-- Thanks for creating this pull request 🤗 Please make sure that the pull request is limited to one type (docs, feature, etc.) and keep it as small as possible. You can open multiple prs instead of opening a huge one. --> <!-- If this pull request closes an issue, please mention the issue number below --> Closes FE-765 #4554 This PR fixes the issue where importing OpenAPI collections used to import the schema as the body for examples rather than the actual examples. ### Before <img width="801" height="672" alt="image" src="https://github.com/user-attachments/assets/f21b6653-3195-41ec-aee6-c3fb4505ec34" /> ### After <img width="801" height="672" alt="image" src="https://github.com/user-attachments/assets/bc2b8871-b869-4d17-afe3-745b3f6db8cb" /> <!-- Add an introduction into what this PR tries to solve in a couple of sentences --> ### What's changed <!-- Describe point by point the different things you have changed in this PR --> <!-- You can also choose to add a list of changes and if they have been completed or not by using the markdown to-do list syntax - [ ] Not Completed - [x] Completed --> ### Notes to reviewers <!-- Any information you feel the reviewer should know about when reviewing your PR --> <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixes OpenAPI import to use response examples instead of schemas. Imported collections now show real example payloads. Resolves FE-765 and #4554. - **Bug Fixes** - OpenAPI 3.0/3.1: prefer media.example, then media.examples; respect empty and null examples; skip unresolved $refs; otherwise generate from schema. - OpenAPI 2.0: use response.examples by content type; fallback to schema-based generation. - Safer JSON handling to avoid errors and keep bodies readable. <sup>Written for commit 5ecae06a1b2a970f5a5964969b348c34be364463. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-17 02:49:36 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hoppscotch#5374
No description provided.