From d0251630bd6ef3edaf03e47e5c1e6b36d32ee82a Mon Sep 17 00:00:00 2001 From: sha016 <92833633+sha016@users.noreply.github.com> Date: Thu, 11 Nov 2021 08:15:05 -0600 Subject: [PATCH] Format fields in OpenAPI Schema (#1003) --- AUTHORS | 1 + CHANGELOG.md | 1 + example/tests/__snapshots__/test_openapi.ambr | 4 ++-- rest_framework_json_api/schemas/openapi.py | 7 ++++--- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/AUTHORS b/AUTHORS index 84e52286..35d959c6 100644 --- a/AUTHORS +++ b/AUTHORS @@ -39,6 +39,7 @@ Safa AlFulaij santiavenda Sergey Kolomenkin Stas S. +Steven A. Swaraj Baral Tim Selman Tom Glowka 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",