Skip to content

Fix OpenAPI generator crash on empty content objects#362

Merged
boyney123 merged 3 commits intomainfrom
fix/openapi-empty-content-crash
Mar 17, 2026
Merged

Fix OpenAPI generator crash on empty content objects#362
boyney123 merged 3 commits intomainfrom
fix/openapi-empty-content-crash

Conversation

@boyney123
Copy link
Contributor

Closes #2346

What This PR Does

Fixes a crash in the OpenAPI generator when responses or request bodies have content: {} (an empty content object). This is valid OpenAPI but caused a TypeError because Object.keys({}) returns an empty array, and accessing [0] yields undefined. The generator now gracefully skips empty content objects while still processing valid ones.

Changes Overview

Key Changes

  • Guard against empty content objects in getSchemasByOperationId (request body and response schema extraction)
  • Guard against empty content objects in getExamplesByOperationId (request body and response example extraction)
  • Add test OpenAPI fixture with content: {} on responses and request bodies
  • Add integration test verifying the generator handles empty content without crashing

How It Works

The fix adds if (contentType) checks after Object.keys(content)[0] at all 4 locations where content types are extracted. When content is an empty object, the code now skips that response/request body instead of crashing. Valid responses with actual content types continue to be processed normally.

Breaking Changes

None

Additional Notes

The reporter's second concern (one failing generator stopping all subsequent generators) is handled at the EventCatalog core orchestration level, not in this generator package. The fix here prevents the crash from occurring in the first place.

🤖 Generated with Claude Code

…odies

Guard against content: {} in OpenAPI spec responses and request bodies
which caused TypeError crashes when Object.keys() returned an empty array.

Closes #2346

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@changeset-bot
Copy link

changeset-bot bot commented Mar 17, 2026

🦋 Changeset detected

Latest commit: fead971

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@eventcatalog/generator-openapi Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@boyney123 boyney123 merged commit 2dd6ef1 into main Mar 17, 2026
7 of 8 checks passed
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