swagger-api / swagger-ui

Swagger UI is a collection of HTML, JavaScript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.
https://swagger.io
Apache License 2.0
25.96k stars 8.85k forks source link

Unexpected defaultModelExpandDepth behavior #8008

Open alexrejto opened 2 years ago

alexrejto commented 2 years ago

Q&A (please complete the following information)

Content & configuration

Example Swagger/OpenAPI definition: This request body is referenced by a POST request in the request body.

    AppCreate:
      additionalProperties: false
      properties:
        name:
          type: string
          example: My First App
          minLength: 3
          maxLength: 255
        description:
          type: string
          example: This is my first App!
          maxLength: 8192
      required:
        - name

Swagger-UI configuration options:

        <SwaggerUI
          url='url'
          docExpansion={'none'}
          deepLinking={true}
          // @ts-expect-error: TS2769 Expected @types issue
          defaultModelRendering="model"
          defaultModelsExpandDepth={-1}
          defaultModelExpandDepth={3} // Issues arise when this is larger than 3
        />

Describe the bug you're encountering

When defaultModelExpandDepth is 3 or larger, the requestBody is rendered as below on load. Notably, the string-typed name and description fields are hidden behind the carat.

image

Expected rendering, shown below, is only accessible if defaultModelExpandDepth is 2 or less.

image

Additional context or thoughts

Please let me know if you need any additional information! I am happy to help.

M-Reimer commented 2 years ago

Same issue here:

"defaultModelExpandDepth" is just broken currently. Seems to be some kind of regression as this used to work in older versions.

kchaitanya1195 commented 1 year ago

The config option is working correctly in 4.6.2. Issue comes up in 4.7.0.

gcardoso22 commented 1 year ago

I also wanted to upgrade to latest version but this is a deal-breaker. As an additional note, this happens for all models that have a value greater than the one specified in defaultModelExpandDepth.

twjasa commented 1 year ago

Hello,

I'll take a look at it today :)

twjasa commented 1 year ago

Hello you all,

I created a PR to fix this issue -> https://github.com/swagger-api/swagger-ui/pull/8186