Skip to content

many=True not influencing output on openapi docs page #721

@nneul

Description

@nneul

I'm not sure if this is an issue with my usage, or something with apiflask, but I'm having trouble getting the generated api docs to reflect return of a list instead of a single element. The examples on the apiflask pages don't seem to cover this case.

class UserOut(Schema):
    id = Integer()
    name = String()
    email = String()
    age = Integer()
    status = String()

@api_blueprint.route("/latest/TestList")
@api_blueprint.output(UserOut(many=True))
@api_blueprint.doc(summary="List all users", description="Get a list of all registered users")
def api_testlist():
    users = [
        {"id": 1, "username": "nneul", "name": "user name", "status": "active"}
    ]
    return users

I would expect this to return something that indicated an array return, but it is resulting in this in the openapi spec:

      "UserOut": {
        "additionalProperties": false,
        "properties": {
          "age": {
            "type": "integer"
          },
          "email": {
            "type": "string"
          },
          "id": {
            "type": "integer"
          },
          "name": {
            "type": "string"
          },
          "status": {
            "type": "string"
          }
        },
        "type": "object"
      }




    "/api-bin/latest/TestList": {
      "get": {
        "description": "Get a list of all registered users",
        "parameters": [],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UserOut"
                }
              }
            },
            "description": "Successful response"
          }
        },
        "summary": "List all users",
        "tags": [
          "Unauthenticated API Endpoints"
        ]
      }
    },

Environment:

  • Python version: 3.11
  • Flask version: 3.1.2
  • APIFlask version: 3.0.2

Am I missing something obvious here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions