mirror of
https://github.com/hoppscotch/hoppscotch.git
synced 2026-04-25 08:45:58 +03:00
[PR #5990] fix(import): handle allOf in OpenAPI example body generation #5455
Labels
No labels
CodeDay
a11y
browser limited
bug
bug fix
cli
core
critical
design
desktop
discussion
docker
documentation
duplicate
enterprise
feature
feature
fosshack
future
good first issue
hacktoberfest
help wanted
i18n
invalid
major
minor
need information
need testing
not applicable to hoppscotch
not reproducible
pull-request
question
refactor
resolved
sandbox
self-host
spam
stale
testmu
wip
wont fix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/hoppscotch#5455
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/hoppscotch/hoppscotch/pull/5990
Author: @mahmoodhamdi
Created: 3/13/2026
Status: 🔄 Open
Base:
main← Head:fix/openapi-allof-example-generation📝 Commits (3)
1d2d339fix(import): handle allOf in OpenAPI example body generationfefb734fix: preserve merged object when allOf sub-schema has no typee77e812fix: guard oneOf/anyOf against empty arrays📊 Changes
2 files changed (+74 additions, -5 deletions)
View changed files
📝
packages/hoppscotch-common/src/helpers/import-export/import/openapi/example-generators/v3.ts(+34 -4)📝
packages/hoppscotch-common/src/helpers/import-export/import/openapi/example-generators/v31.ts(+40 -1)📄 Description
Description
Closes #5988
When importing OpenAPI specs that use
allOffor schema composition (a very common pattern for inheritance and mixins), the example body generator produced an empty string becauseallOfwas not handled.For example, this schema:
Previously generated:
""(empty)Now generates:
{"name": "string", "age": 0, "breed": "string"}Changes
v3.ts (OpenAPI 3.0):
allOfhandling that merges all sub-schema properties into a single objectv31.ts (OpenAPI 3.1):
allOfhandlingoneOf/anyOfhandling (had a TODO noting the gap)The merge strategy: iterate sub-schemas left to right, generate examples for each, and spread-merge object results. Later schemas override earlier ones for conflicting keys, consistent with how
allOfworks in JSON Schema.Testing
Summary by cubic
Fixes empty example bodies when importing OpenAPI specs that use
allOfby merging composed schemas and preserving merged objects when a sub-schema has no type. Also adds default handling foroneOf/anyOfin 3.0/3.1 to pick the first option and guards against empty arrays.allOfsub-schemas left-to-right; later keys override earlier; skip non-object results so constraint-only sub-schemas don’t wipe merged objects.oneOf/anyOfby generating from the first schema; guard against empty arrays to prevent runtime errors.Written for commit
e77e8123e7. Summary will update on new commits.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.