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

[BUG] Pydantic schema is using a higher version json schema than open api #418

Closed
shughes-uk opened this issue Apr 8, 2022 · 3 comments
Closed

Comments

@shughes-uk
Copy link

shughes-uk commented Apr 8, 2022

Describe the bug
It seems pydantic is generating schema in line with the latest json schema draft, but openapi expects an older version.
This issue has some info, and fastapi appears to have solved it but it might be worth solving this in ninja too.

pydantic/pydantic#1164

The outcome of this at the moment is codegen tools for openapi do not work correctly with ninja produced openapi docs.

swagger codegen simply silently fails, https://github.com/openapi-generators/openapi-python-client explodes

The type causing the issue is used as part of the default pagination decorator so I imagine this applies to most ninja users.

@vitalik
Copy link
Owner

vitalik commented Apr 9, 2022

Hi @shughes-uk

do you have some simple snippet that can be used to reproduce this bug ?

@shughes-uk
Copy link
Author

shughes-uk commented Apr 12, 2022

Example api with paginate

from django.contrib import admin
from django.urls import path
from ninja import NinjaAPI, Schema
from ninja.pagination import paginate

api = NinjaAPI()


@api.get("/add")
@paginate
def add(request, a: int, b: int, **kwargs):
    return [{"result": a + b}]


urlpatterns = [
    path("admin/", admin.site.urls),
    path("api/", api.urls),
]

Running

python manage.py runserver &
pip openapi-python-client
openapi-python-client generate --url http://127.0.0.1:8000/api/openapi.json

Running this outputs

Error(s) encountered while generating, client was not created

Failed to parse OpenAPI document

3 validation errors for OpenAPI
paths -> /api/add -> get -> parameters -> 3 -> schema -> $ref
  field required (type=value_error.missing)
paths -> /api/add -> get -> parameters -> 3 -> schema -> exclusiveMinimum
  value could not be parsed to a boolean (type=type_error.bool)
paths -> /api/add -> get -> parameters -> 3 -> $ref
  field required (type=value_error.missing)

It's a little obtuse but those errors are from their pydantic representation of the openapi schema.

This issue over on fast-api may be more helpful than the issue I linked in the ticket tiangolo/fastapi#3541

vitalik added a commit that referenced this issue Jun 3, 2022
@vitalik
Copy link
Owner

vitalik commented Jul 1, 2022

@shughes-uk this is fixed in 0.18+

@vitalik vitalik closed this as completed Jul 1, 2022
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

2 participants