swagger-ui icon indicating copy to clipboard operation
swagger-ui copied to clipboard

Misleading example value in case of cyclic references

Open whoareyoukid opened this issue 5 months ago • 4 comments

Q&A (please complete the following information)

  • OS: macOS
  • Browser: chrome
  • Version: 135.0.7049.114
  • Method of installation: npm
  • Swagger-UI version: 5.20.5
  • Swagger/OpenAPI version: Swagger 2.0

Content & configuration

Example Swagger/OpenAPI definition:

{
  "swagger": "2.0",
  "paths": {
    "/A": {
      "get": {
        "responses": {
          "200": {
            "schema": {
              "$ref": "#/definitions/A"
            }
          }
        }
      }
    }
  },
  "definitions": {
    "A": {
      "type": "object",
      "properties": {
        "nextA": {
          "$ref": "#/definitions/A"
        }
      }
    }
  }
}

Swagger-UI configuration options:

SwaggerUI({
        spec: apiSpec,
        dom_id: '#api-ui-container',
        defaultModelRendering: 'model',
        showExtensions: true,
        deepLinking: true,
        plugins: [DisableTryItOutPlugin],
      });

Describe the bug you're encountering

To reproduce...

Steps to reproduce the behavior: Go to Example value of the only endpoint. You will see that it is:

{
  "nextA": "string"
}

Although the nextA is really an object that follows the same definition, like in

{
  "nextA": {
    "nextA": {}
  }
}

Of course in any given value the nextAs must stop at some recursion level, therefore the Swagger UI would have to decide how many levels to include in the example value. But showing a "string" instead is misleading.

Image

Expected behavior

Even an empty object would make more sense. Please display something better than just a string.

whoareyoukid avatar Jul 08 '25 12:07 whoareyoukid

Hey there @whoareyoukid 👋 Thanks for finding this bug! Are you interested in preparing PR with proposed solution? 🥺

robert-hebel-sb avatar Jul 16 '25 09:07 robert-hebel-sb

@robert-hebel-sb Can I work on this issue?

DipakHalkude avatar Oct 10 '25 16:10 DipakHalkude

@DipakHalkude Sure thing!

Thanks for finding time to help us out 🙏 Looking forward to PR 👀

robert-hebel-sb avatar Oct 30 '25 10:10 robert-hebel-sb

I am on it :)

DipakHalkude avatar Nov 10 '25 08:11 DipakHalkude