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

Use explicit declared serializer field label as oas title #286

Closed
wants to merge 1 commit into from

Conversation

wonderbeyond
Copy link

NOTE: every serializer field has a non-empty label, when not declared it's derived from the field name. I think only explicitly declared labels are necessary to go into the OAS schema. So I read the label from field._kwargs, not field.label.

@tfranzel
Copy link
Owner

tfranzel commented Feb 2, 2021

this looks like it is very similar to #191. please read through it first so we are on the same page.

@wonderbeyond
Copy link
Author

this looks like it is very similar to #191. please read through it first so we are on the same page.

Yes, I share similar idea with #191. However I were not caring about filter parameters, and I think filters should be treated much differently with models and serializers. (about this idea, also refer #234 (comment))

@tfranzel below is your comment at page #191:

ideally spectacular could find out if verbose_name is explicitly set and only then put it in the schema. i looked at the django/drf code but i have not found a silver bullet there yet. having a flag would also be a solution, however i would like to exhaust the possiblity of an automatic solution first. once introduced, parameters will never go away

You want a way to find out if verbose_name is explicitly set and only then put it in the schema, I think just did it in a simple way.

@tfranzel
Copy link
Owner

@wonderbeyond, this is just as i suspected. as you see, a lot of tests are failing because the title gets added everywhere. This is exactly the same duplication problem, where name and title are just copies. this add alot noise to the schema with no additional info.

@wonderbeyond
Copy link
Author

@wonderbeyond, this is just as i suspected. as you see, a lot of tests are failing because the title gets added everywhere. This is exactly the same duplication problem, where name and title are just copies. this add alot noise to the schema with no additional info.

I think these noises can be fixed in drf-spectacular's own code scope, though I've not read through enough code and can not help more. My intention is to find only explicit declared serializer field labels. I'm so sorry that I'm busy currently and have no spare time to give more comments...

@krzysieqq krzysieqq mentioned this pull request Mar 12, 2021
tfranzel added a commit that referenced this pull request Mar 18, 2021
@tfranzel
Copy link
Owner

@wonderbeyond sry for the long wait. field._kwargs did indeed help but failed on the PK fields with 'ID'. i took a different route and now it looks like it is working without the noise. feedback welcome. i'll close this PR as it is outdated now.

@tfranzel tfranzel closed this Mar 18, 2021
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

Successfully merging this pull request may close these issues.

None yet

2 participants