Comments (11)
Hello!
You probably have multiple serializers named NestedSerializer in different packages. Each serializer gets mapped to an OpenAPI named model according to its name. You could go to each serializer in question and explicitly give it a more distinctive name, or force it to be generated as an inline model (both will work if you only care about the documentation aspect).
from drf-yasg.
Hey thanks for the quick reply!
None of the serializers I am using have a nested serializer called "NestedSerializer". One of my serializers which aren't working looks like this:
class ClientSerializer(serializers.ModelSerializer):
"""
Serializer for clients
"""
items = ItemSerializer(many=True, read_only=True)
class Meta:
model = Client
fields = ('id', 'user', 'items', 'company')
Is there something I am doing wrong? I tried to look at that documentation but I was unsure as what to do with the "ref_name" attribute?
Thanks again!
from drf-yasg.
Huh. If that is the case then this might be a bug.
For the ref_name
attribute, you would add it to the serializer Meta
class.
from drf-yasg.
Hey! I realise I had depth=3
in one of the serializers which seemed to cause an issue.
I set the depth=1
and that has fixed the problem and going to debug further on my side.
Thanks so much for the help!
from drf-yasg.
That shouldn't be a problem, or if it is, it should be fixed. So please do report if you find that it is a bug caused by this library.
from drf-yasg.
I just confirmed that if depth is greater than 1 in more than one serializer, it throws the mentioned error.
from drf-yasg.
Ok, I'll try to figure it out. Any code example (e.g. django-admin startproject
with minimal changes) that shows the problem would be of great help, if it's not too hard!
from drf-yasg.
I tried to reproduce the error this morning but couldn't which means its probably the way models are related, if I will have time, I will try it again some time later.
from drf-yasg.
@axnsan12 This a example project to view the issue https://github.com/dilipMaharjan/drf_yasg_depth_issue
Steps:
- Clone the project
- Run docker-compose up
- In your browser, type localhost/docs/
4.Change the depth to 1 in CSerializer and it works
I hope this helps.
from drf-yasg.
Hello!
Thanks a lot for the example app, it's great! The problem seems to be caused by having ModelSerializer
s with implicitly generated NestedSerializer
s for their model's ForeignKey
relations...
It can be worked around by defining nested fields explicitly on your ModelSerializer
to indicate which serializer they should use.
The permanent fix will likely be to force all such automatic serializers to be output inline (e.g. no entry in the bottom Models
section, no sub-model name when viewing the operation). If you want to keep the named/by-reference behaviour you will have to implement the solution mentioned above anyway.
from drf-yasg.
Thanks.
from drf-yasg.
Related Issues (20)
- get_schema_fields breaks when using django-filters after last update HOT 2
- Redirect URL is not being processed in Django 4.2 when using oauth2 implicit flow HOT 1
- coreschema does not get installed with 1.21.6 HOT 4
- Can I use swagger_auto_schema in generic views?
- Vulnerability Issue
- `SerializerMethodField` return type is always 'STRING' when a file uses `from __future__ import annotations` due to PEP 563 HOT 2
- Animation not working on brave browser
- swagger_serializer_method does not work with partialmethod
- Headers Not Getting Sent Along with Request!
- Wrong Base URL: localhost HOT 2
- Add Python 3.12 Support HOT 1
- from pkg_resources import DistributionNotFound, get_distribution `ModuleNotFoundError: No module named 'pkg_resources`
- Export enums with drf-yasg to Swagger: Works in responses serializers but not in query_serializer
- Showing the read_only fields in the serializer in the post /swagger template in (ForignKeyFields)
- Django5 not supported? HOT 1
- tags hierarchy (sub-tags grouping)
- How can i remove default urls generated by base_url of router from swagger ui ??
- django_filters is not compatible
- Login with JWT
- filters.ModelChoiceFilter not looks like filters.ChoiceFilter HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from drf-yasg.