django-rest-framework-mongoengine
django-rest-framework-mongoengine copied to clipboard
Let's use ref_name for nested embedded fields as well
Hi,
I'm using drf-mongoengine with drf-yasg, and terrible things happen with the Swagger spec generation because the ref_name is "Embedded" across all the nested embedded fields.
I was able to fix this issue by adding a ref_name line for the build_nested_embedded_field
method of DocumentSerializer
.
def build_nested_embedded_field(self, field_name, relation_info, embedded_depth):
subclass = self.serializer_embedded_nested or EmbeddedDocumentSerializer
class EmbeddedSerializer(subclass):
class Meta:
model = relation_info.related_model
depth_embedding = embedded_depth - 1
ref_name = f"{self.get_model().__name__}_{field_name}".replace(
".", "_"
).replace("_child", "")
The following link is the fork repo I'm using for my project. If you like this idea, please add this feature! https://github.com/lessbutter/django-rest-framework-mongoengine/commit/52da614abb49b2781f319c3724223457b37025fe
Hello, @krsteve.
I've never tested DRF-Mongoengine with Swagger spec support, and definitely cannot guarantee that they work together. To be honest, I've switched to other projects full-time and have not really been maintaining DRF-Mongoengine now.
Do you suggest that addition of ref_name
field to the Serializer.Meta would improve its display in Swagger documentation, auto-generated by DRF-YASG? Is this solution similar to this post: https://stackoverflow.com/questions/59885543/problem-reusing-serializers-with-django-and-drf-yasg?
Thanks for your suggestion. Could you, maybe, create a unit-test for this functionality and submit a pull-request? I'll review it and merge, if everything works.
Sadly I don't think I have the time to create a unit-test as I'm currently working way past hours... :(
Anyways, great package! Helped me a lot. Thanks :)
Hello, @krsteve.
I've never tested DRF-Mongoengine with Swagger spec support, and definitely cannot guarantee that they work together. To be honest, I've switched to other projects full-time and have not really been maintaining DRF-Mongoengine now.
Do you suggest that addition of
ref_name
field to the Serializer.Meta would improve its display in Swagger documentation, auto-generated by DRF-YASG? Is this solution similar to this post: https://stackoverflow.com/questions/59885543/problem-reusing-serializers-with-django-and-drf-yasg?Thanks for your suggestion. Could you, maybe, create a unit-test for this functionality and submit a pull-request? I'll review it and merge, if everything works.
@BurkovBA @krsteve Take a look at #281, we ran into this problem in the beginning of 2021 and solved, deployed and run this successfully in production using drf-yasg. Unfortunately I can't invest time into adding unit tests in the foreseeable future, as we migrated our application to fastapi and I am busy with the last semester before my Bachlor thesis.
这是来自QQ邮箱的假期自动回复邮件。 您好,我最近正在休假中,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。
@skeletorXVI Sorry for my non-existence. Reviewed the PR, merged. Thank you for submitting it!