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

Invalid OAS file generation for Page #1110

Open
rolikoff opened this issue Apr 2, 2024 · 1 comment
Open

Invalid OAS file generation for Page #1110

rolikoff opened this issue Apr 2, 2024 · 1 comment
Assignees
Labels
question Further information is requested

Comments

@rolikoff
Copy link

rolikoff commented Apr 2, 2024

I'm currently integrating a library with my FastAPI project and utilizing the following library versions:

[tool.poetry.dependencies]
python = "~3.12.0"
fastapi = "~0.110.0"
fastapi-pagination = "~0.12.21"

I've established a test route within my project as follows:

@router.get("/")
async def domains() -> Page[Domain]:
    domains = [Domain(id=1, name="test"), Domain(id=2, name="test2")]
    return paginate(domains)

However, I've encountered an issue with the OpenAPI Specification (OAS) YAML file generated, as it includes incorrect schema types:

openapi: 3.0.2
...

    Page_Domain_:
     properties:
       items:
         items:
           $ref: '#/components/schemas/Domain'
         type: array
         title: Items
       total:
         anyOf:
         - type: integer
           minimum: 0.0
         - type: 'null'
         title: Total
       page:
         anyOf:
         - type: integer
           minimum: 1.0
         - type: 'null'
         title: Page
       size:
         anyOf:
         - type: integer
           minimum: 1.0
         - type: 'null'
         title: Size
       pages:
         anyOf:
         - type: integer
           minimum: 0.0
         - type: 'null'
         title: Pages

I understand that OAS version 3.0.2 does not support null types, which may not be a direct issue with fastapi-pagination. Minimum values are not ints, which is odd as well. Could you provide any insights into the underlying problem or suggest a possible solution?

@uriyyo uriyyo self-assigned this Apr 3, 2024
@uriyyo uriyyo added the question Further information is requested label Apr 3, 2024
@uriyyo
Copy link
Owner

uriyyo commented Apr 3, 2024

Hi @rolikoff,

Could you please show how you generate OpenAPI schema?

Here is what component definition looks like in my case:

from fastapi import FastAPI

from fastapi_pagination import Page, add_pagination, paginate

app = FastAPI()
add_pagination(app)


@app.get("/")
async def get_items() -> Page[int]:
    return paginate([])
{
    "Page_int_": {
        "properties": {
            "items": {
                "items": {
                    "type": "integer"
                },
                "type": "array",
                "title": "Items"
            },
            "total": {
                "type": "integer",
                "minimum": 0.0,
                "title": "Total"
            },
            "page": {
                "type": "integer",
                "minimum": 1.0,
                "title": "Page"
            },
            "size": {
                "type": "integer",
                "minimum": 1.0,
                "title": "Size"
            },
            "pages": {
                "type": "integer",
                "minimum": 0.0,
                "title": "Pages"
            }
        },
        "type": "object",
        "required": [
            "items"
        ],
        "title": "Page[int]"
    }
}

But it use 3.1.0 OpenAPI version.

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

No branches or pull requests

2 participants