Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

errors rendering non-existing schemas when defaultModelRendering is set to model #9666

Closed
glowcloud opened this issue Mar 6, 2024 · 3 comments

Comments

@glowcloud
Copy link
Contributor

Content & configuration

Example Swagger/OpenAPI definition:

openapi: 3.1.0
info:
  title: Empty response test case
  version: '1'
paths:
  '/':
    get:
      responses:
        '200':
          description: no content
        '201':
          description: no schema but an example
          content:
            application/json:
              example:
                foo: bar
        '202':
          description: no schema but examples
          content:
            application/json:
              examples:
                first:
                  value:
                    foo: bar
                second:
                  value:
                    baz: foobar
        '203':
          description: no schema no example
          content:
            application/json: {}

Swagger-UI configuration options:

SwaggerUI({
    url: "./examples/oas31-empty-response.yaml",
    dom_id: "#swagger-ui",
    presets: [
      SwaggerUIBundle.presets.apis,
      SwaggerUIStandalonePreset
    ],
    defaultModelRendering: "model",
    plugins: [
      SwaggerUIBundle.plugins.DownloadUrl
    ],
    layout: "StandaloneLayout"
})

Describe the bug you're encountering

Swagger UI tries to render schemas when no schema has been provided, if defaultModelRendering is set to model. This causes errors:

error01

and renders the Could not render ModelWrapper message:

error02

If we switch to the example tab, we will correctly not be able to switch back to schema:

error03

To reproduce...

Steps to reproduce the behavior:

  1. Load the provided specification with defaultModelRendering set to model
  2. Expand the GET / operation
  3. See the Could not render ModelWrapper message and errors in console

Expected behavior

Swagger UI should not render the schema tab if no schema has been provided.

@char0n
Copy link
Member

char0n commented Mar 6, 2024

So this is related to the fact that we're trying to render (forcing with configuration) a component that it's not event accessible from standard UI workflow.

Sensible thing to do would be ignoring defaultModelRendering=model when there is no schema.

glowcloud added a commit that referenced this issue Mar 6, 2024
Refs #9666
Co-authored-by: Pierre Paysant-Le Roux <ppaysant@gmail.com>
@glowcloud
Copy link
Contributor Author

Addressed by #9667

@char0n
Copy link
Member

char0n commented Mar 6, 2024

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

No branches or pull requests

2 participants