diff --git a/AUTHORS b/AUTHORS index 84e52286..35d959c6 100644 --- a/AUTHORS +++ b/AUTHORS @@ -39,6 +39,7 @@ Safa AlFulaij <safa1996alfulaij@gmail.com> santiavenda <santiavenda2@gmail.com> Sergey Kolomenkin <https://kolomenkin.com> Stas S. <stas@nerd.ro> +Steven A. <sha0160@protonmail.com> Swaraj Baral <baralswaraj40@gmail.com> Tim Selman <timcbaoth@gmail.com> Tom Glowka <glowka.tom@gmail.com> diff --git a/CHANGELOG.md b/CHANGELOG.md index db78a996..b631eda7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ any parts of the framework not mentioned in the documentation should generally b * Avoid error when `parser_context` is `None` while parsing. * Raise comprehensible error when reserved field names `meta` and `results` are used. * Use `relationships` in the error object `pointer` when the field is actually a relationship. +* Added missing inflection to the generated OpenAPI schema. ### Changed diff --git a/example/tests/__snapshots__/test_openapi.ambr b/example/tests/__snapshots__/test_openapi.ambr index 28044c74..48aa21fa 100644 --- a/example/tests/__snapshots__/test_openapi.ambr +++ b/example/tests/__snapshots__/test_openapi.ambr @@ -133,7 +133,7 @@ "entries": { "$ref": "#/components/schemas/reltomany" }, - "first_entry": { + "firstEntry": { "$ref": "#/components/schemas/reltoone" }, "type": { @@ -541,7 +541,7 @@ "entries": { "$ref": "#/components/schemas/reltomany" }, - "first_entry": { + "firstEntry": { "$ref": "#/components/schemas/reltoone" }, "type": { diff --git a/rest_framework_json_api/schemas/openapi.py b/rest_framework_json_api/schemas/openapi.py index 2dff2e10..c3d553b7 100644 --- a/rest_framework_json_api/schemas/openapi.py +++ b/rest_framework_json_api/schemas/openapi.py @@ -7,6 +7,7 @@ from rest_framework.schemas.utils import is_list_view from rest_framework_json_api import serializers, views +from rest_framework_json_api.utils import format_field_name class SchemaGenerator(drf_openapi.SchemaGenerator): @@ -655,12 +656,12 @@ def map_serializer(self, serializer): if isinstance(field, serializers.HiddenField): continue if isinstance(field, serializers.RelatedField): - relationships[field.field_name] = { + relationships[format_field_name(field.field_name)] = { "$ref": "#/components/schemas/reltoone" } continue if isinstance(field, serializers.ManyRelatedField): - relationships[field.field_name] = { + relationships[format_field_name(field.field_name)] = { "$ref": "#/components/schemas/reltomany" } continue @@ -682,7 +683,7 @@ def map_serializer(self, serializer): schema["description"] = str(field.help_text) self.map_field_validators(field, schema) - attributes[field.field_name] = schema + attributes[format_field_name(field.field_name)] = schema result = { "type": "object",