Skip to content

Inflect component attributes when using the OpenAPI SchemaGenerator #967

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

Closed
sliverc opened this issue Jul 30, 2021 Discussed in #966 · 6 comments · Fixed by #1003
Closed

Inflect component attributes when using the OpenAPI SchemaGenerator #967

sliverc opened this issue Jul 30, 2021 Discussed in #966 · 6 comments · Fixed by #1003
Labels
bug good first issue Good for newcomers

Comments

@sliverc
Copy link
Member

sliverc commented Jul 30, 2021

Discussed in #966

Originally posted by mattis-rosenkranz July 29, 2021
The generated OpenaAPI-Scheme component attributes are not inflected using the settings described in the docs.
This is not a problem as the parser just leaves the attribute names as they are, but it would be nice to conform the OpenAPI-scheme to the chosen field format.

Most likely this will be fixed in map_serialzer function.

@sliverc sliverc added the bug label Jul 30, 2021
@sliverc sliverc added the good first issue Good for newcomers label Sep 29, 2021
@SwarajBaral
Copy link
Contributor

Hey @sliverc, I would like to work on this. Can you guide me a bit so that I can get started ?

@sliverc
Copy link
Member Author

sliverc commented Oct 6, 2021

When JSON_API_FORMAT_FIELD_NAMES is configured openapi schema still shows attribute and relatioship field names underscored instead of formatted.

When looking quickly at the code it seems that the field name here, here and here needs to be formatted with utils.format_field_name to make this work.

@SwarajBaral
Does this help you to get started?

@sha016
Copy link
Contributor

sha016 commented Oct 27, 2021

@sliverc If all that's needed is formatting field.field_name on those lines I'd love to start contributing with that.

@sliverc
Copy link
Member Author

sliverc commented Oct 27, 2021

@sha016 Yes as far as I see is formatting field name enough + adjusting the tests. Feel free to give it a try.

@sha016
Copy link
Contributor

sha016 commented Oct 27, 2021

@sliverc I've made those changes and ran tests. The tests fail because the changes that are applied don't match to the last snapshot if I'm reading this right:


E       assert '{\n  "descri...hors"\n  ]\n}' == '{\n  "descri...hors"\n  ]\n}'
E         Skipping 2040 identical leading characters in diff, use -v to show
E         -     "first_entry": {
E         ?           ^^
E         +     "firstEntry": {
E         ?           ^
E                                 "$ref": "#/components/schemas/reltoone"
E                               },...
E         
E         ...Full output truncated (110 lines hidden), use '-vv' to show

.tox/py37-django22-drf312/lib/python3.7/site-packages/snapshottest/module.py:233: AssertionError
========================================================================================== SnapshotTest summary ==========================================================================================
12 snapshots passed.
2 snapshots failed in 1 test suites. Inspect your code or run with `pytest --snapshot-update` to update them.

When I run pytest --snapshot-update the tests all pass. Am I good to make a PR? Should I include the changed "example/tests/snapshots/snap_test_openapi.py" file in the PR after running pytest --snapshot-update? I'm in unfamiliar territory here.

@sliverc
Copy link
Member Author

sliverc commented Oct 27, 2021

@sliverc Yes snapshot needs to be updated and commited as well. But do not worry just open a PR with what you have. If something is missing I can then always comment there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug good first issue Good for newcomers
Projects
None yet
3 participants