Skip to content

fix(response): handle empty examples map in OAS3 responses#10803

Open
maruthang wants to merge 1 commit intoswagger-api:masterfrom
maruthang:fix/issue-7823-empty-examples
Open

fix(response): handle empty examples map in OAS3 responses#10803
maruthang wants to merge 1 commit intoswagger-api:masterfrom
maruthang:fix/issue-7823-empty-examples

Conversation

@maruthang
Copy link
Copy Markdown

Description

Guard against empty examples: {} maps in OAS3 response content types that caused "could not render" errors. When a response's media type has an empty examples map, examplesForMediaType.keySeq().first() throws because the map has no keys. This fix checks that the examples map is a non-empty Immutable Map before accessing its keys.

Motivation and Context

Fixes #7823

When an OAS3 spec includes an empty examples: {} in a response content type, Swagger UI crashes with a "could not render" error. This is because the code attempts to call .keySeq().first() on an empty (or null) Immutable Map without checking if it's valid first.

How Has This Been Tested?

  • Added a unit test that renders a <Response> component with an OAS3 response containing examples: {} and asserts no error is thrown
  • Verified the existing unit tests still pass

Screenshots (if appropriate):

N/A

Checklist

My PR contains...

  • No code changes (src/ is unmodified: changes to documentation, CI, metadata, etc.)
  • Dependency changes (any modification to dependencies in package.json)
  • Bug fixes (non-breaking change which fixes an issue)
  • Improvements (misc. changes to existing features)
  • Features (non-breaking change which adds functionality)

My changes...

  • are breaking changes to a public API (config options, System API, major UI change, etc).
  • are breaking changes to a private API (Redux, component props, utility functions, etc.).
  • are breaking changes to a developer API (npm script behavior changes, new dev system dependencies, etc).
  • are not breaking changes.

Documentation

  • My changes do not require a change to the project documentation.
  • My changes require a change to the project documentation.
  • If yes to above: I have updated the documentation accordingly.

Automated tests

  • My changes can not or do not need to be tested.
  • My changes can and should be tested by unit and/or integration tests.
  • If yes to above: I have added tests to cover my changes.
  • If yes to above: I have taken care to cover edge cases in my tests.
  • All new and existing tests passed.

Guard against empty `examples: {}` maps in OAS3 response content
types that caused "could not render" errors by checking the map
is non-empty before accessing keys.

Fixes swagger-api#7823
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.

Swagger Responses section showing could not render with emojis

1 participant