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

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

Open
Tanvir786123 opened this issue Mar 16, 2025 · 1 comment

Comments

@Tanvir786123
Copy link

Tanvir786123 commented Mar 16, 2025

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.

@Tanvir786123
Copy link
Author

Please let me know if this issue should be moved to the https://github.com/fastapi/fastapi repository.

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

No branches or pull requests

1 participant