You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Self-referencing schemas seem to be broken when following the Django Ninja documentation, producing incorrect and unusable OpenAPI schema and endpoints.
And shows an incorrect schema (where parent is shown as a string):
When the endpoint is executed, the following error is returned:
Traceback (most recent call last):
File "/usr/local/lib/python3.12/site-packages/ninja/operation.py", line 108, in run
return self._result_to_response(request, result, temporal_response)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/ninja/operation.py", line 208, in _result_to_response
validated_object = response_model.model_validate(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/pydantic/main.py", line 551, in model_validate
return cls.__pydantic_validator__.validate_python(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.ValidationError: 1 validation error for NinjaResponseSchema
response.self_reference
Field required [type=missing, input_value=<DjangoGetter: <SelfRefer...erenceModel object (1)>>, input_type=DjangoGetter]
For further information visit https://errors.pydantic.dev/2.7/v/missing
Self-referencing schemas seem to be broken when following the Django Ninja documentation, producing incorrect and unusable OpenAPI schema and endpoints.
For example, using the following models:
Loaded with the following data:
[{"model": "questions.selfreferencemainmodel", "pk": 1, "fields": {"self_reference": 1}}, {"model": "questions.selfreferencemodel", "pk": 1, "fields": {"parent": null, "text": "Test 1"}}, {"model": "questions.selfreferencemodel", "pk": 2, "fields": {"parent": 1, "text": "Test 2"}}]
And the following API:
Results in errors in the OpenAPI docs:
![Screenshot 2024-06-18 at 7 39 26 PM](https://private-user-images.githubusercontent.com/72322081/340884474-d3a169a6-7bb4-4164-b5aa-8d1c9577ad02.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTk3NTM4NzMsIm5iZiI6MTcxOTc1MzU3MywicGF0aCI6Ii83MjMyMjA4MS8zNDA4ODQ0NzQtZDNhMTY5YTYtN2JiNC00MTY0LWI1YWEtOGQxYzk1NzdhZDAyLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MzAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjMwVDEzMTkzM1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTQ0NjYxZjM4NmQ2OTY2NDQ4YjhkMGVmMWQxZDU2NjQ4NDA3YTY5Mzk1MmFjZjFmMTAzNTFkZDU4OWZmNTc4YTkmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.jdMgXWa67VTWd914Bl_ej1qqq4zZMf2YapMAO9XKD1U)
And shows an incorrect schema (where
![Screenshot 2024-06-18 at 7 39 33 PM](https://private-user-images.githubusercontent.com/72322081/340884562-44a230ce-5532-4a64-bb01-99d55f1bea3d.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTk3NTM4NzMsIm5iZiI6MTcxOTc1MzU3MywicGF0aCI6Ii83MjMyMjA4MS8zNDA4ODQ1NjItNDRhMjMwY2UtNTUzMi00YTY0LWJiMDEtOTlkNTVmMWJlYTNkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MzAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjMwVDEzMTkzM1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTk5YWRiOTFkY2I5NTM4NzAxYTg1MjU2NWJmOWVlNzMxNjBiYWUwY2ZhYmU0ODdjMjgyOTNiOGJjOGY2ZjY0MzAmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.DKq8varASNBRfPWGFmRfiyPDrTGwLJp6-1PrHhzBfI8)
parent
is shown as astring
):When the endpoint is executed, the following error is returned:
Lastly, here is the generated OpenAPI.json:
Thank you for your assistance in advance!
Versions (please complete the following information):
The text was updated successfully, but these errors were encountered: