django-rest-framework icon indicating copy to clipboard operation
django-rest-framework copied to clipboard

Add a method for getting serializer field name (OpenAPI)

Open denisorehovsky opened this issue 5 years ago • 3 comments

I've camelized my API using djangorestframework-camel-case (https://github.com/vbabiy/djangorestframework-camel-case). However, OpenAPI is still showing me that all of my fields are in snake case.

One way of fixing this is to override map_serializer method and do something similar to what has been described here https://github.com/vbabiy/djangorestframework-camel-case/issues/79#issue-563203091

However, it would be much simpler if we had a separate method for getting serializer field name that I can override:

class CustomAutoSchema(AutoSchema):
    ...

    def get_field_name(self, field):
        return camelize(field.field_name)

This PR adds this method.

denisorehovsky avatar Aug 23 '20 06:08 denisorehovsky

@carltongibson Added docs and test.

denisorehovsky avatar Aug 23 '20 08:08 denisorehovsky

I'd also love to see this merged :smile: I'm working on an API that'll be used by an Angular app and it can generate services based on OpenAPI & Swagger. I'd like to have both the API and its Swagger documentation show the same fields, in camelCase.

t-ionut avatar Dec 21 '20 14:12 t-ionut

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Apr 17 '22 00:04 stale[bot]

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Oct 15 '22 19:10 stale[bot]

.

WhyNotHugo avatar Oct 15 '22 20:10 WhyNotHugo