Skip to content

OpenAPI 3.1.x schema with tuple restrictions on additional items throws an error and does not render. #10921

Description

@iarenaza

Q&A (please complete the following information)

  • OS: Debian GNU/Linux 13.5 (Trixie)
  • Browser: Firefox 151.0.1 / Chromium 149.0.7827.102 (Official Build) built on Debian GNU/Linux 13 (trixie) (64-bit)
  • Method of installation: npm
  • Swagger-UI version: current HEAD in master (but the issue is also present in version 5.32.0)
  • Swagger/OpenAPI version: OpenAPI 3.1.0

Content & configuration

Minimal repro for OpenAPI definition:

{
  "openapi": "3.1.0",
  "info": {
    "title": "Minimal error reproduction",
    "version": "0.0.1"
  },
  "paths": {
    "/api/some-path": {
      "get": {
        "parameters": [
          {
            "in": "query",
            "name": "sort-by",
            "required": true,
            "schema": {
              "default": [
                [
                  "triggered-at",
                  "desc-nulls-last"
                ]
              ],
              "type": "array",
              "items": {
                "type": "array",
                "prefixItems": [
                  {
                    "type": "string",
                    "enum": [
                      "triggered-at"
                    ]
                  },
                  {
                    "type": "string",
                    "enum": [
                      "asc-nulls-first",
                      "asc-nulls-last",
                      "desc-nulls-first",
                      "desc-nulls-last"
                    ]
                  }
                ],
                "items": false
              }
            }
          }
        ],
        "summary": "Minimal repro API def",
        "tags": [
          "minimal-repro"
        ]
      }
    }
  }
}

Swagger-UI configuration options:

The default configuration used by the instructions given at https://github.com/swagger-api/swagger-ui/blob/HEAD/docs/development/setting-up.md (except for the url: setting, that points to a local file with the OpenAPI JSON file shown above).

Describe the bug you're encountering

The Swagger UI doesn't render the parameters details of the /api/some-path path, when clicked on it. It shows an error instead (see screen shots below), and displays several Javascript error and call stack traces in the Javascript console.

To reproduce

Steps to reproduce the behavior:

  1. Launch the development environment as documented at https://github.com/swagger-api/swagger-ui/blob/HEAD/docs/development/setting-up.md (after saving the OpenAPI JSON schema shown above in the dev-helpers/examples directory, with a suitable name and updating the url: setting in dev-helpers/dev-helper-initializer.js file as suggested in the same previous link)
  2. Go to http://localhost:3200
  3. Click on the /api/some-path endpoint definition expand it.
  4. See the error.

Expected behavior

The /api/some-path endpoint definition is expanded without issues, and the sort-by parameter is correctly rendered.

Screenshots

First error shown when clicking to expand the endpoint definition:

Image

Second error shown when clicking on the "Next >" button:

Image

Error shown when clicking on the "x Close" button:

Image

Additional context or thoughts

The code is blowing up at this line:

if (List.isList(schemaItems?.get("type")) && (schemaItemsType === "array" || schemaItemsType === "object")) {

It looks like the support for JSON Schema Draft 2012-12 (the one used by OpenAPI 3.1.x) is not complete, when it comes to the tuple validation syntax, specially about the additional items in a tuple.

If we remove the final "items": false key from the tuple definition object, the Swagger UI is rendered successfully. Although the restrictions about not being able to add more entries to the tuple is not enforced (for obvious reasons).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions