Skip to content

Missing "items" elements in schema of class extending ArrayList #1800

@didjoman

Description

@didjoman

Describe the bug

If a controller returns the interface of a class that also extends an "ArrayList", then the generated Schema of the class (being of type array) misses the "items" property. Furthermore, the class of the item doesn't have a generated schema.

How to reproduce

(Using Java 11, SpringBoot 2.7.2, springdoc-openapi-webmvc-core 1.6.10 based on Swagger-core 2.2.2)
git clone https://github.com/didjoman/springdoc-extension-of-arraylist-issue
Run the application (spring boot).
Run curl --location --request GET 'http://localhost:8080/doc' --header 'Content-Type: application/json'

Expected behavior

The Schema of the "Books" should contain the property "item", with a $ref towards "Book". And there should be a Schema for the "Book" class.
We should obtain a schema like:

{
    "openapi": "3.0.1",
    "info": {
        "title": "OpenAPI definition",
        "version": "v0"
    },
    "servers": [
        {
            "url": "http://localh",
            "description": "Generated server url"
        }
    ],
    "paths": {
        "/test": {
            "get": {
                "tags": [
                    "basic-controller"
                ],
                "summary": "get",
                "description": "Provides a list of books.",
                "operationId": "get",
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "*/*": {
                                "schema": {
                                    "oneOf": [
                                        {
                                            "$ref": "#/components/schemas/Books"
                                        }
                                    ]
                                }
                            }
                        }
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "Books": {
                "type": "array",
                "description": "Represents a list of Books.",
                "allOf": [
                    {
                        "$ref": "#/components/schemas/Knowledge"
                    },
                    {
                        "type": "object",
                        "properties": {
                            "empty": {
                                "type": "boolean"
                            }
                        }
                    }
                ],
				"items": {
                    "$ref": "#/components/schemas/Book"
                }
            },
            "Knowledge": {
                "type": "object",
                "description": "Represents the knowledge."
            },
			"Book": {
                "type": "object",
                "properties": {
                    "title": {
                        "type": "string"
                    }
                },
                "description": "Represents a Book."
            }
        }
    }
}

Actual behavior

Today, only the "Books" schema is described, without the "items" property. And the schema for the "Book" class is missing.

{
    "openapi": "3.0.1",
    "info": {
        "title": "OpenAPI definition",
        "version": "v0"
    },
    "servers": [
        {
            "url": "http://localh",
            "description": "Generated server url"
        }
    ],
    "paths": {
        "/test": {
            "get": {
                "tags": [
                    "basic-controller"
                ],
                "summary": "get",
                "description": "Provides a list of books.",
                "operationId": "get",
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "*/*": {
                                "schema": {
                                    "oneOf": [
                                        {
                                            "$ref": "#/components/schemas/Books"
                                        }
                                    ]
                                }
                            }
                        }
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "Books": {
                "type": "array",
                "description": "Represents a list of Books.",
                "allOf": [
                    {
                        "$ref": "#/components/schemas/Knowledge"
                    },
                    {
                        "type": "object",
                        "properties": {
                            "empty": {
                                "type": "boolean"
                            }
                        }
                    }
                ]
            },
            "Knowledge": {
                "type": "object",
                "description": "Represents the knowledge."
            }
        }
    }
}

Additional context

It looks like if the controller returns a type "Books" instead of "Knowledge", the doc contains the "items" property and the missing "Book" schema.

Metadata

Metadata

Assignees

No one assigned

    Labels

    invalidThis doesn't seem right

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions