Invalid OAS file generation for Page
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?
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.
@rolikoff Any updates?
Hi @rolikoff,
I'm closing this issue, please reopen it in case if it still exists