Inflect component attributes when using the OpenAPI SchemaGenerator
sliverc opened this issue · 6 comments
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.
Hey @sliverc, I would like to work on this. Can you guide me a bit so that I can get started ?
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?
@sliverc If all that's needed is formatting field.field_name on those lines I'd love to start contributing with that.
@sha016 Yes as far as I see is formatting field name enough + adjusting the tests. Feel free to give it a try.
@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.