fix(spec): handle requestBody with no content without crashing#10837
Open
yogeshwaran-c wants to merge 2 commits intoswagger-api:masterfrom
Open
fix(spec): handle requestBody with no content without crashing#10837yogeshwaran-c wants to merge 2 commits intoswagger-api:masterfrom
yogeshwaran-c wants to merge 2 commits intoswagger-api:masterfrom
Conversation
When a requestBody object has no content property (only description and required), the requiredParameters selector would crash with TypeError: Cannot read properties of undefined (reading 'entrySeq') because requestBody.getIn(["content"]) returns undefined. This adds a null check before iterating over content entries, returning the partial result early when content is absent. Fixes swagger-api#10767
Contributor
|
@yogeshwaran-c Although the content field is required (https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#request-body-object), the fix is valid since the app should not crash despite errors in the document; please just include a unit test for this case to prevent future regressions. |
Cover the case where requestBody has no content property to prevent regression of the no-content crash fix.
Author
|
@lukaszzazulak Thanks for the review and for confirming the fix is valid. I've added a unit test for getOAS3RequiredRequestBodyContentType in test/unit/core/plugins/spec/selectors.js that covers the no-content case (along with a couple of related cases for context) — pushed in 9aa5940. |
lukaszzazulak
approved these changes
Apr 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When a requestBody object has no
contentproperty (onlydescriptionandrequired), therequiredParametersselector insrc/core/plugins/spec/selectors.jscrashes with:This happens because
requestBody.getIn(["content"])returnsundefinedwhen there is nocontentkey, and.entrySeq()is then called onundefined.The fix adds a null check before iterating over content entries, returning the partial result early when content is absent.
Motivation and Context
Fixes #10767
While the OpenAPI spec expects requestBody to have a
contentfield, real-world specs sometimes omit it (e.g., when using code generators or incomplete specs). Swagger UI should handle this gracefully instead of crashing.How Has This Been Tested?
requiredfield that was already extracted from the requestBodyScreenshots (if appropriate):
N/A
Checklist
My PR contains...
src/is unmodified: changes to documentation, CI, metadata, etc.)package.json)My changes...
Documentation
Automated tests