Skip to content

Illustrating the inline schema naming issue in Swagger UI when using a list #10372

Open
@Tanvir786123

Description

@Tanvir786123

Q&A (please complete the following information)

  • OS: WSL
  • Browser: chrome
  • Version: Version 134.0.6998.89
  • Method of installation: pip
  • Swagger-UI version: [e.g. 3.10.0]
  • Swagger version: 5.20.1
  • OpenAPI version: 3.1.0

Content & configuration

https://github.com/Tanvir786123/fastapi-swagger-ui-issue/tree/main contains a complete rundown of what this issue is, i.e., the inability to correctly display the name of the return object if it is a List.

Example Swagger/OpenAPI definition:

{
  "openapi": "3.1.0",
  "info": {
    "title": "FastAPI",
    "version": "0.1.0"
  },
  "paths": {
    "/item": {
      "get": {
        "summary": "Get a single book",
        "description": "Returns a single book with full details.",
        "operationId": "get_book_item_get",
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Book"
                }
              }
            }
          }
        }
      }
    },
    "/items": {
      "get": {
        "summary": "Get list of books",
        "description": "Returns a list of books with full details.",
        "operationId": "get_books_items_get",
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "items": {
                    "$ref": "#/components/schemas/Book"
                  },
                  "type": "array",
                  "title": "Response Get Books Items Get"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Book": {
        "properties": {
          "id": {
            "type": "integer",
            "title": "Id"
          },
          "title": {
            "type": "string",
            "title": "Title"
          },
          "author": {
            "type": "string",
            "title": "Author"
          },
          "summary": {
            "type": "string",
            "title": "Summary"
          }
        },
        "type": "object",
        "required": [
          "id",
          "title",
          "author",
          "summary"
        ],
        "title": "Book"
      }
    }
  }
}

Swagger-UI configuration options:

SwaggerUI({
  // your config options here
})
?yourQueryStringConfig

Describe the bug you're encountering

https://github.com/Tanvir786123/fastapi-swagger-ui-issue/tree/main contains a complete rundown of what this issue is, i.e., the inability to correctly display the name of the return object if it is a List.

To reproduce...

Steps to reproduce the behavior:
Please follow the steps on the linked repository.

Expected behavior

The inline schema name for the second endpoint should have been: Books.

Screenshots

Inside https://github.com/Tanvir786123/fastapi-swagger-ui-issue/tree/main.

Additional context or thoughts

This problem may potentially extend to more objects than just List. However, the objective of this issue is to solve the problem using a List type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions