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

Let's use ref_name for nested embedded fields as well #284

Open
krsteve opened this issue Oct 3, 2021 · 5 comments
Open

Let's use ref_name for nested embedded fields as well #284

krsteve opened this issue Oct 3, 2021 · 5 comments

Comments

@krsteve
Copy link

krsteve commented Oct 3, 2021

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!
lessbutter@52da614

@krsteve krsteve changed the title Let's use Let's use ref_name for nested embedded fields as well Oct 3, 2021
@BurkovBA
Copy link
Collaborator

BurkovBA commented Oct 3, 2021

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.

@krsteve
Copy link
Author

krsteve commented Oct 7, 2021

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 :)

@skeletorXVI
Copy link
Contributor

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.

@IATF
Copy link

IATF commented Dec 27, 2021 via email

@BurkovBA
Copy link
Collaborator

@skeletorXVI Sorry for my non-existence. Reviewed the PR, merged. Thank you for submitting it!

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

4 participants