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

Add a method for getting serializer field name (OpenAPI) #7493

Merged

Conversation

denisorehovsky
Copy link
Contributor

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 vbabiy/djangorestframework-camel-case#79 (comment)

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.

Copy link
Collaborator

@carltongibson carltongibson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grrr. Yes. Seems reasonable. Can you add docs and tests please.

@denisorehovsky
Copy link
Contributor Author

@carltongibson Added docs and test.

@t-ionut
Copy link

t-ionut commented Dec 21, 2020

I'd also love to see this merged 😄 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.

@stale
Copy link

stale bot commented Apr 17, 2022

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 stale bot added the stale label Apr 17, 2022
@stale stale bot removed the stale label Jun 6, 2022
@carltongibson carltongibson removed their request for review June 27, 2022 07:53
@stale
Copy link

stale bot commented Oct 15, 2022

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 stale bot added the stale label Oct 15, 2022
@WhyNotHugo
Copy link

.

@stale stale bot removed the stale label Oct 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants