Skip to content

Conversation

DarkMatter-999
Copy link
Contributor

Description

This PR fixes a rendering bug in the Responses when using custom OpenAPI extensions (x-*) inside the responses object.

Motivation and Context

fixes #10561
Swagger UI previously attempted to render all entries in the responses object, including custom extensions like x-tenant as actual HTTP responses.

How Has This Been Tested?

Manually tested with an OpenAPI 3.1.0 spec containing x-tenant under responses
Verified that the Responses section renders correctly and without errors
Confirmed that valid responses (200, 500, etc.) still display as expected
Ran relevant tests, no regressions observed.

Environment:
OS: Linux
Browser: Chromium 139
Swagger UI: master Branch

Schema used for testing:

{
  "openapi" : "3.1.0",
  "paths" : {
    "/hello" : {
      "get" : {
        "responses" : {
          "200" : {
            "description" : "The hello message",
            "content" : {
              "text/plain" : {
                "schema" : {
                  "type" : "string"
                }
              }
            },
            "x-tenant" : "acme"
          },
          "500" : {
            "description" : "Internal server error",
            "x-tenant" : "acme"
          },
          "x-tenant" : "acme"
        },
        "x-tenant" : "acme",
        "summary" : "Hello",
        "tags" : [ "Example Resource" ]
      }
    }
  },
  "info" : {
    "title" : "prout-quarkus API",
    "version" : "1.0-SNAPSHOT"
  }
}

Screenshots (if appropriate):

Before:

image

After:

image

Checklist

My PR contains...

  • Bug fixes (non-breaking change which fixes an issue)

My changes...

  • are not breaking changes.

Documentation

  • My changes do not require a change to the project documentation.

Automated tests

  • All new and existing tests passed.

@DarkMatter-999 DarkMatter-999 marked this pull request as ready for review October 7, 2025 08:11
<tbody>
{
responses.entrySeq().map( ([code, response]) => {
responses.filter((_, key) => !key.startsWith("x-")).entrySeq().map( ([code, response]) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we rewrite and reuse logic from core/utils to filter extensions?

const extensionRegExp = /^x-/
export const isExtension = (key) => extensionRegExp.test(key)

export const getExtensions = (defObj) => {
  if(Map.isMap(defObj)) {
    return defObj.filter((v, k) => isExtension(k))
  }
  return Object.keys(defObj).filter((key) => isExtension(key))
}
Suggested change
responses.filter((_, key) => !key.startsWith("x-")).entrySeq().map( ([code, response]) => {
responses.filter((_, key) => !isExtension(key)).entrySeq().map( ([code, response]) => {

@robert-hebel-sb
Copy link
Contributor

hey @DarkMatter-999
thanks for creating this PR 🙏

could we address an issue where we don't have any responses besides extension? Currently we display an empty table but no table should be displayed in such case

actual:
Screenshot 2025-10-07 at 11 15 46
expected:
Screenshot 2025-10-07 at 11 17 55

openapi: 3.1.0
paths:
  /hello:
    get:
      responses:
        x-tenant: acme

info:
  title: prout-quarkus API
  version: 1.0-SNAPSHOT

@DarkMatter-999
Copy link
Contributor Author

Hi @robert-hebel-sb, thanks for the review.
I have made all the required changes, please re-review ✌️.

@robert-hebel-sb robert-hebel-sb merged commit 23e3e00 into swagger-api:master Oct 8, 2025
8 checks passed
swagger-bot pushed a commit that referenced this pull request Oct 10, 2025
## [5.29.4](v5.29.3...v5.29.4) (2025-10-10)

### Bug Fixes

* **core:** refactor UNSAFE_ lifecycle methods in ContentType and OperationContainer ([#10373](#10373)) ([2814709](2814709)), closes [#10212](#10212)
* ignore rendering responses with extensions in the schema ([#10592](#10592)) ([23e3e00](23e3e00))
* include script in body ([#10593](#10593)) ([456274c](456274c))
* update vulnerable libxml2 to 2.13.9-r0 ([#10600](#10600)) ([8138154](8138154))
* use h1 for title heading to improve accessibility ([#10598](#10598)) ([c0bd7b6](c0bd7b6)), closes [#10480](#10480)
@swagger-bot
Copy link
Contributor

🎉 This PR is included in version 5.29.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Responses are not render if OpenAPI Reponses object contains extensions

3 participants